This section describes the easiest way to display a list with selected data in the ALV Grid Control. To do this, you must:
See also sample report BCALV_GRID_DEMO in development class
You instantiate an ALV Grid Control in the same way as other controls:
DATA: grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container
gt_sflight TYPE TABLE OF sflight.
In order to integrate a control into a screen, you can use four different
container controls (in this example, we use the custom container control).IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
CONTAINER_NAME = 'CCCONTAINER'.
CREATE OBJECT GRID1
EXPORTING
I_PARENT = g_custom_container.
ENDIF.
The
IF query of reference variable g_custom_container ensures that the instances are only generated when the PBO is processed for the first time.Normally, you must use method
cl_gui_cfw=>flush to pass the methods called to the frontend. However, since the Control Framework performs an automatic flush at the end of the PBO module, this step is not required here.
When you start the program, although the two instances (the container control and the ALV Grid Control) are generated, they are not visible.
Displaying a List in the ALV Grid Control
Once you have created the ALV Grid Control and integrated it into a screen using a container control, you must pass the data and its structure to the ALV Grid Control:
SELECT * FROM sflight INTO TABLE gt_sflight.
CALL METHOD grid->set_table_for_first_display
EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING IT_OUTTAB = gt_sflight.
In this case, the structure data is provided through the Data Dictionary. The ALV Grid Control gets the field information from table SFLIGHT and displays all fields of the table.