Dynamic ALV to display SE11 table data

Dynamic ALV to display a table in ALV grid by creating dynamic internal table in SAP ABAP

+ -
In the below example, we are going to display SE11 table data (ant transparent table) in the form if ALV, follow the below steps.

Step1: Create field catalog for the table.

Step2: Create dynamic table.

Step3: Get table data.

Step4: Display ALV.

Dynamic ALV in SAP ABAP

Step1: build field catalog for the input table.

PARAMETERS: P_TABLE TYPE DD02L-TABNAME. "table input

START-OF-SELECTION.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' "create field catalog
    EXPORTING
      I_STRUCTURE_NAME = P_TABLE
    CHANGING
      CT_FIELDCAT      = IT_FCAT.

Step2: Create dynamic table.

Create dynamic table using 'CREATE_DYNAMIC_TABLE'  method of class 'CL_ALV_TABLE_CREATE'.
  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.

Get data from table using select statement

Get data from table using select statements.
FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE. "declare field symbol
ASSIGN FS_TAB->* TO <fs_tab>. "assign field symbol memory
SELECT * FROM (P_TABLE) INTO CORRESPONDING FIELDS OF TABLE <fs_tab> UP TO 50 ROWS. "get data

Step4:Display ALV

Display data in ALV using field catalog and table.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_STRUCTURE_NAME = P_TABLE
    TABLES
      T_OUTTAB         = <fs_tab>.

Final Code will be

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.

Please Sign in to ask a question

Was this lesson helpful to you? Yes No 17 People out of 27 think this lesson helpful


Lesson Navigation

←Previous Chapter
Next Chapter →