Entering content frame

This graphic is explained in the accompanying textFirst Steps Locate the document in its SAP Library 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

See also sample report BCALV_GRID_DEMO in development class SLIS .

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:
  2. 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 Structure link container controls (in this example, we use the custom container control).

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

    Structure link Exercise 1: Reserving an Area for a Control of the Controls Tutorial explains how to mark an area in the alphanumerical Screen Painter version.

  5. 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:

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.

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:
  2. SELECT * FROM sflight INTO TABLE gt_sflight.

  3. 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:

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.

 

 

 

 

 

 

 

Leaving content frame