Creating dynamic internal table to display ALV code example
Example: Creating dynamic internal table to display ALV
REPORT ZSAN_RFCTEST.
DATA : IT_FCAT TYPE LVC_T_FCAT.
PARAMETERS: P_TABLE TYPE DD02L-TABNAME.
DATA : WA_TABLE TYPE DD02L.
AT SELECTION-SCREEN.
IF P_TABLE IS NOT INITIAL.
SELECT SINGLE * FROM DD02L INTO WA_TABLE WHERE TABNAME = P_TABLE AND TABCLASS = 'TRANSP'.
ELSE.
MESSAGE 'Please enter a table' TYPE 'E'.
STOP.
ENDIF.
IF WA_TABLE IS INITIAL.
MESSAGE 'Table Dosent exit or is not transparent table' TYPE 'E'.
STOP.
ENDIF.
START-OF-SELECTION.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = P_TABLE
CHANGING
CT_FIELDCAT = IT_FCAT.
DATA : FS_TAB TYPE REF TO DATA.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
* I_STYLE_TABLE =
IT_FIELDCATALOG = IT_FCAT
* I_LENGTH_IN_BYTE =
IMPORTING
EP_TABLE = FS_TAB.
FIELD-SYMBOLS: <FS_TAB> TYPE STANDARD TABLE.
ASSIGN FS_TAB->* TO <FS_TAB>.
*data : it_tab type TABLE OF p_table.
SELECT * FROM (P_TABLE) INTO CORRESPONDING FIELDS OF TABLE <FS_TAB> UP TO 50 ROWS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = P_TABLE
TABLES
T_OUTTAB = <FS_TAB>.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.