SAP ABAP - Sample Report Program On Dynamic ALV Grid/List Display.

This report program displays any ztable or standard table data in ALV grid display. the table has to be entered by the user.


This program has the ability to display the contents of any standard table or ztable in grid display.

SAMPLE PROGRAM:

REPORT ZALV_DYNAMIC.
TYPE-POOLS: SLIS.

DATA: ld_st_table TYPE REF TO DATA,
itab TYPE REF TO DATA,
st_desc TYPE REF TO CL_ABAP_STRUCTDESCR,
is_layout TYPE SLIS_LAYOUT_ALV,
l_fieldcat TYPE LVC_S_FCAT,
t_fieldcat TYPE LVC_T_FCAT,
ls_fieldcat TYPE SLIS_FIELDCAT_ALV,
lt_fieldcat TYPE SLIS_T_FIELDCAT_ALV.

* DECLARE ALV GRID TITLE
DATA : title1(30),
title2(10),
title3(50).

* DECLARE FIELD SYMBOLS
FIELD-SYMBOLS : TYPE STANDARD TABLE,
TYPE ANY,
TYPE ABAP_COMPDESCR.

* SELECTION SCREEN TO ENTER THE TABLE NAME
PARAMETERS : p_itab LIKE DD02L-TABNAME.

INITIALIZATION.

START-OF-SELECTION.

* TEXTS FOR GRID TITLE
title1 = 'Dynamic ALV Grid Table'.
title2 = p_itab.

CONCATENATE title1 title2 INTO title3 SEPARATED BY SPACE.

* CREATE STRUCTURE FOR DYNAMIC TABLE
CREATE DATA ld_st_table TYPE (p_itab).
ASSIGN ld_st_table->* TO .

* DYNAMIC TABLE FIELD STRUCTURE
st_desc ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( ).

LOOP AT st_desc->COMPONENTS ASSIGNING .

* BUILD THE FIELDCATALOG
L_FIELDCAT-FIELDNAME = -NAME.
L_FIELDCAT-REF_TABLE = p_itab.
APPEND L_FIELDCAT TO T_FIELDCAT.

* BUILD THE FIELDCATALOG
LS_FIELDCAT-FIELDNAME = -NAME.
LS_FIELDCAT-REF_TABNAME = p_itab.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

ENDLOOP.

* ALV LAYOUT
IS_LAYOUT-ZEBRA = 'X'.
IS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
IS_LAYOUT-WINDOW_TITLEBAR = title3.

* CREATE THE DYNAMIC TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = T_FIELDCAT
IMPORTING
EP_TABLE = itab.

ASSIGN itab->* TO .

* READ DATA FROM THE SELECTED TABLE

SELECT * FROM (p_itab)
INTO CORRESPONDING FIELDS OF TABLE .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = IS_LAYOUT
IT_FIELDCAT = LT_FIELDCAT
i_bypassing_buffer = 'X'
i_callback_program = sy-repid
i_save = 'A'
TABLES
t_outtab = . "internal table

IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


SELECTION SCREEN:



















More Programs On ALV:

- ALV Tree Display.


- Colors In ALV Grid Display.


- Making ALV Grid Fields Editable.


- Display Average Value In ALV Report.

- ...Back To Sample Programs, Tips & Tricks On ALV Grid/List Display.

Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.