List of values and field information for any database table
*&---------------------------------------------------------------------*
*& Report Z_FIELDINFO
*
*& Author :Swarna.S.
*&---------------------------------------------------------------------*
*&
*& AS Description
*& Simple ALV report -- User enters a table name and gets in ALV the
*& list of all the fields in table with their salient characteristics
*& and the key field is given a different color for quick recognition
*& and when the user presses the button list it downloads all the table
*& data in excel format as DAT file and when user presses EXIT, they
*& can leave the program
*&---------------------------------------------------------------------*
REPORT Z_FIELDINFO.
*Type pools declaration for ALV.
TYPE-POOLS : slis.
*Type pool declarations for ABAP language
type-pools : abap.
*String for filename
data p_string type string.
*Structure declaration for the result of Function module
TYPES : BEGIN OF ty_fies.
INCLUDE STRUCTURE DFIES.
TYPES : END OF ty_fies.
*Structure declaration for header - fieldnames
types : BEGIN OF ty_header,
fieldname(100) TYPE c,
END OF ty_header.
*Internal table and workarea declaration for header
data : it_header type standard table of ty_header initial size 0,
wa_header type ty_header.
*Internal table and work area declaration for FM .
data : it_fies type standard table of ty_fies initial size 0,
wa_fies type ty_fies.
*Dynamic internal table declarations
DATA STRUCT_REF TYPE REF TO CL_ABAP_STRUCTDESCR.
DATA wa_FieldCAT TYPE LVC_S_FCAT.
DATA IT_FIELDCAT TYPE LVC_T_FCAT.
DATA DATAREFERENCE TYPE REF TO DATA.
* Field-Symbols for dynamic internal table
FIELD-SYMBOLS: <dyn_tab> TYPE ANY TABLE,
<DYN_TABLE> TYPE STANDARD TABLE,
<DESR_COMP> TYPE ABAP_COMPDESCR,
<MY_FS> TYPE ANY.
*Structure declaration for dd02t
TYPES : BEGIN OF ty_desc.
INCLUDE STRUCTURE DD02T.
TYPES : END OF ty_desc.
*Internal table and work area declaration for dd02t .
data : it_desc type standard table of ty_desc initial size 0,
wa_desc type ty_desc.
*Structure declaration for the output in ALV format
TYPES : BEGIN OF ty_output.
INCLUDE STRUCTURE DFIES.
TYPES : color_line(4) TYPE c, " Line color
END OF ty_output.
*Internal table and work area declaration for output ALV.
data : it_output type standard table of ty_output initial size 0,
wa_output type ty_output.
*Data declarations for ALV
DATA: c_cont type ref to cl_gui_custom_container,
c_alvgd type ref to cl_gui_alv_grid,
it_fcat TYPE lvc_t_fcat,
it_layout TYPE lvc_s_layo.
* Grid title.
data : text2 type string.
* Selection screen
selection-screen begin of block blk with frame.
*HERE ENTER THE TABLE NAME
parameters : p_table like dd02l-tabname,
*HERE ENTER THE PATH WHERE YOU HAVE TO DOWNLOAD YOUR FILE
*please enter the file as XLS extension as we download
*the data in DAT format as 'C:\temp\file.xls'
p_file like rlgrap-filename.selection-screen end of block blk.
*initialization event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.
*fetch values from the DD02t
select
* from DD02t into table it_desc where tabname = p_table and ddlanguage = 'E'.
*Function module to get all the fields and their characteristics in a*table
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING TABNAME = p_table
* FIELDNAME = ' '
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* GROUP_NAMES = ' '
* UCLEN =
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
DFIES_TAB = it_fies
* FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3 .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Appending the values fetched through the Function module in the output
*Alv report
loop at it_fies into wa_fies.
wa_output-fieldname = wa_fies-fieldname.
wa_output-inttype = wa_fies-inttype.
wa_OUTPUT-MEMORYID = wa_FIES-MEMORYID.
wa_OUTPUT-CHECKTABLE = wa_fies-checktable.
wa_OUTPUT-LENG = wa_FIES-LENG.
wa_output-fieldtext = wa_fies-fieldtext.
wa_output-keyflag = wa_fies-keyflag.
wa_output-convexit = wa_fies-convexit.
wa_output-domname = wa_fies-domname.
wa_output-rollname = wa_fies-rollname.
if wa_fies-keyflag = 'X'.
wa_output-color_line = 'C600'.
endif.
APPEND wa_output to it_output.
CLEAR wa_output.
endloop.
* Table description for pop up
READ TABLE IT_DESC INTO WA_DESC INDEX 1.
text2 = wa_desc-ddtext.
*POP up to show the table and its defintion
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING TITEL = 'Table for display'
TEXTLINE1 = p_table
TEXTLINE2 = text2
START_COLUMN = 25
START_ROW = 6.
*Call the ALV screen with custom container




