Example documentationFirst Steps Locate this document in the navigation structure

 

This section describes the easiest way to display a list with selected data in the ALV Grid Control. To do this, you must:

  1. Create an instance of the ALV Grid Control and integrate it into a screen.

  2. Select the data to be displayed and pass it together with a description of the fields to the instance.

    Note Note

    See also sample report BCALV_GRID_DEMO in development class SLIS.

    End of the note.
Creating an ALV Grid Control

You instantiate an ALV Grid Control in the same way as other controls:

  1. 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 Syntax

    1. 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.
    End of the code.

    Note 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).

    End of the note.
  2. 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 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.

    End of the note.
  3. 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 Syntax

    1. 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.
    End of the code.

Note 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.

End of the note.

Caution 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.

End of the caution.

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:

  1. Fill the internal table with data:

    Syntax Syntax

    1. SELECT * FROM sflight INTO TABLE gt_sflight.
    End of the code.
  2. 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 Syntax

    1. CALL METHOD grid->set_table_for_first_display
      	EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
      	CHANGING IT_OUTTAB = gt_sflight.
    End of the code.

Note 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.

End of the note.