First Steps 
This section describes the easiest way to display a list with selected data in the ALV Grid Control. To do this, you must:
Create an instance of the ALV Grid Control and integrate it into a screen.
Select the data to be displayed and pass it together with a description of the fields to the instance.
Note
See also sample report BCALV_GRID_DEMO in development class SLIS.
You instantiate an ALV Grid Control in the same way as other controls:
Declare reference variables for the ALV Grid Control and the container. In addition, declare an internal table that you fill with selected data later on:
Syntax
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.
Note
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).
Create a standard screen and mark an area for the custom container control in the graphical Screen Painter (icon identified by letter 'C'). Assign name CCCONTAINER to this area.
Note
Exercise 1: Reserving an Area for a Control of the Controls Tutorial explains how to mark an area in the alphanumerical Screen Painter version.
In the PBO module of the screen, you must now instantiate the container control and the ALV Grid Control. By doing this, you create a link between the container control and the screen, using the container created in the Screen Painter. Using parameter parent,
you define the container control as the parent of the ALV Grid Control:
Syntax
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.
Note
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.
Caution
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.
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:
Fill the internal table with data:
Syntax
SELECT * FROM sflight INTO TABLE gt_sflight.
Pass the output table and the structure data to the ALV Grid Control. Again, ensure to call this method only once after the ALV Grid Control is created:
Syntax
CALL METHOD grid->set_table_for_first_display EXPORTING I_STRUCTURE_NAME = 'SFLIGHT' CHANGING IT_OUTTAB = gt_sflight.
Note
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.