SAP List Viewer (ALV) is another way to create reports in ABAP. This chapter explains how to develop reports using both procedural and object-oriented ALV libraries.

15    ALV Reports

Reports are a common development in ABAP. A typical report extracts data from the database and processes it per a user’s requirements. The processed data is then presented to the user as a report output. Such report output typically shows data in rows and columns and also provides some basic functionality, such as sorting the output, filtering the data, summarizing the values, and so on.

As discussed in Chapter 13, developing a classical report requires a developer to spend too much time making the report output presentable and provides only basic functions, such as sorting or filtering data.

To this end, SAP provides the SAP List Viewer (ALV) library, which automatically manages report output and provides additional functionalities without developers having to sweat. All the developer needs to do is supply the output data to the library. The ALV library is available for both procedural and object-oriented programming techniques. The object-oriented ALV library is available in two variants: the CL_GUI_ALV_GRID ABAP class and the ALV object model, the latter of which is an object-oriented encapsulation of the existing ALV tool.

In this chapter, we’ll discuss how to work with the ALV library using function modules, the CL_GUI_ALV_GRID ABAP class, and the ALV object model. In Section 15.1, we begin by discussing the standard ALV reports in the reuse library. We’ll look at the four primary report displays: list, grid, block, and hierarchical.

From there, in Section 15.2, we provide an overview of the interactive features that can be used in ALV reports. Section 15.3 teaches how to use the Control Framework to create a custom ALV grid control. Finally, in Section 15.4, we offer details on using the different displays of the ALV object model, including the table, hierarchical, and tree object displays.

15.1    Standard ALV Reports Using the Reuse Library

SAP provides various function modules in the reuse library that can be used to display report output. These function modules take care of formatting the output and automatically provide various additional functionalities, such as sorting, filtering, and so on. All the function module names in the reuse library start with REUSE_ALV*. The function modules in the reuse library require you to pass certain components to prepare the output; the basic components that you need to pass to the ALV function module include the following:

With the reuse library, you can create simple reports, block reports, and hierarchical reports.

The following are the different types of report output that can be displayed using the function modules from the reuse library:

In the following subsections, we’ll discuss each of these report outputs in detail.

15.1.1    List and Grid Display: Simple Reports

A simple report shows data from a single internal table as a report output; data from various database tables can be consolidated into a single internal table and passed to the ALV function module as report output. The reuse library provides two function modules—REUSE_ALV_LIST_DISPLAY and REUSE_ALV_GRID_DISPLAY—that can be used to show a simple report either as a list or as a grid, respectively.

The parameter interfaces of these two function modules are similar. The function module help documentation in Function Builder (Transaction SE37) for each function module contains detailed information about each parameter.

Listing 15.1 shows sample code using a list display; it generates the output shown in Figure 15.1.

REPORT ZDEMO_SIMPLE_REPORT.
DATA it_sflight TYPE STANDARD TABLE OF sflight.
PARAMETERS p_carrid TYPE s_carr_id.
SELECT * FROM sflight INTO TABLE it_sflight WHERE carrid EQ p_carrid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
TABLES
t_outtab = it_sflight
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

Listing 15.1    Simple ALV Report Using List Display

List Output Generated by Code in Listing 15.1

Figure 15.1    List Output Generated by Code in Listing 15.1

In Listing 15.1, we’re selecting the data from table SFLIGHT for a given airline code and displaying it as report output using the list display ALV. We pass the structure name from ABAP Data Dictionary to the I_STRUCTURE_NAME formal parameter of the REUSE_ALV_LIST_DISPLAY function module, which uses this structure name to create the output layout.

The data that should be displayed in the output is selected into the internal table IT_SFLIGHT and passed to the T_OUTTAB formal parameter. The ALV function module takes care of printing all the data in internal table IT_SFLIGHT without us having to spend any additional effort on formatting the output.

The function module also loads a default SAP GUI status, which provides many buttons in the application toolbar for additional functionality, such as sorting the output, printing the output, exporting the report output, and so on, as shown in Figure 15.1.

Table 15.1 lists some of the significant parameters of the ALV function module, not all of which are used in the example. Please refer to the function module documentation in Function Builder for each ALV function module for a more exhaustive explanation.

Parameter Description
I_CALLBACK_PROGRAM Name of the calling program. The function module uses this information to call routines in the calling program for interactive reports.
I_CALLBACK_PF_STATUS_SET A subroutine name of the program is passed to this parameter, in which the custom SAP GUI status can be set.
I_CALLBACK_USER_COMMAND A subroutine name of the program is passed to this parameter, which is called when the user performs any actions on the displayed list, such as selecting a SAP GUI button or double-clicking a row.
I_CALLBACK_TOP_OF_PAGE This parameter is specific to a grid display. A subroutine name of the program is passed to this parameter, to which simple header information can be passed for TOP-OF-PAGE.
I_GRID_TITLE This parameter is specific to a grid display. A title for the grid can be passed to this parameter.
I_STRUCTURE_NAME An ABAP Data Dictionary table or structure type name can be passed to this parameter, which contains the output fields.
IT_FIELDCAT An internal table of type SLIS_T_FIELDCAT_ALV is passed to this parameter, which contains the field catalog information for the output fields.
IT_EXCLUDING An internal table consisting of the function codes that should be excluded from the output can be passed to this parameter. All the function codes maintained in the internal table will be hidden when the list is generated.
IT_SPECIAL_GROUPS An internal table with information about grouping fields for column selection is passed to this parameter.
IT_SORT The sort criteria for the initial display can be passed to this parameter.
IT_FILTER The filter criteria for the initial display can be passed to this parameter.
IS_VARIANT The variant that should be used for the initial display can be passed to this parameter.
IT_EVENTS A table consisting of the relevant events and the form routines called for each event can be passed to this parameter. The ALV function module calls the form routine of the program for the respective event.
IS_PRINT Print-related information can be passed to this parameter.

Table 15.1    ALV Function Module Parameters

The grid display ALV is similar to the list display ALV for all practical purposes, but the grid display is part of the Control Framework. The Control Framework uses JavaBeans or ActiveX controls in the presentation layer and provides certain additional features, such as grid title, TOP-OF-PAGE, removing vertical and horizontal lines, making the ALV editable, and so on.

JavaBeans and ActiveX are competing technologies that facilitate communication among components within a framework container (such as SAP GUI or a web browser). The grid display can also be used within the Control Framework, allowing multiple grid displays to be shown on a single screen, which isn’t possible with a list display.

Listing 15.2 shows the grid display ALV being called, which is similar to calling the list display ALV. Here, we’re also passing the optional grid title, which is displayed in the report output, as shown in Figure 15.2.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
I_GRID_TITLE = text-001
TABLES
t_outtab = it_sflight
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

Listing 15.2    Calling Grid Display ALV

Grid DisplayALVgrid display

Figure 15.2    Grid Display

The ALV function module has many parameters (see Table 15.1) that can be passed to control the report output. At a bare minimum, the ALV function module requires you to supply the output layout information, such as the column positions, column names, and so on, and the actual data that should be displayed in the output.

If you wish to display all the fields of an ABAP Data Dictionary table or structure, then the table/structure name can be passed to the I_STRUCTURE_NAME formal parameter of the ALV function module.

In Listing 15.1 and Listing 15.2, we passed SFLIGHT as the structure name to the I_STRUCTURE_NAME formal parameter, because we wanted to print all the fields of table SFLIGHT in the output. However, you may often be printing only certain fields of a table or fields from different tables in the output. In such scenarios, you can create a field catalog and pass it to the function module using the IT_FIELDCAT formal parameter.

You can also create a structure in ABAP Data Dictionary consisting of the output fields and pass it to the I_STRUCTURE_NAME formal parameter. Using a structure name as opposed to defining a field catalog in the program helps you to maintain the output fields centrally if multiple reports are using a similar layout.

Using the field catalog has the advantage that additional attributes can be supplied for each field. The field catalog should be an internal table in which information about each output field is maintained. This internal table should be of type SLIS_T_FIELDCAT_ALV, which belongs to the type group SLIS. The function module documentation provides information about each of the components of the SLIS_T_FIELDCAT_ALV structure and the valid values that can be passed.

Figure 15.3 shows some of the components of the field catalog structure. At a minimum, you should fill the COL_POS, TABNAME, FIELDNAME, and SELTEXT (long, medium, or short) components.

Field Catalog ComponentsField catalogcomponents

Figure 15.3    Field Catalog Components

Listing 15.3 shows the code for a simple report using a field catalog.

REPORT ZDEMO_SIMPLE_REPORT.
TYPES: BEGIN OF ty_sflight,
CARRID TYPE S_CARR_ID,
CONNID TYPE S_CONN_ID,
FLDATE TYPE S_DATE,
PRICE TYPE S_PRICE,
CURRENCY TYPE S_CURRCODE,
END OF ty_sflight.

DATA : it_sflight TYPE STANDARD TABLE OF ty_sflight,
it_fieldcat TYPE SLIS_T_FIELDCAT_ALV.


PARAMETERS p_carrid TYPE s_carr_id.

START-OF-SELECTION.
PERFORM get_data USING p_carrid CHANGING it_sflight.
END-OF-SELECTION.
PERFORM field_catalog CHANGING it_fieldcat.
PERFORM show_output.

*&--------------------------------------------------------------*
*& Form GET_DATA
*&--------------------------------------------------------------*
FORM get_data USING p_p_carrid CHANGING pt_sflight LIKE it_sflight.
SELECT carrid connid fldate price currency FROM sflight INTO TABLE
pt_sflight WHERE carrid EQ p_p_carrid.
ENDFORM.
*&--------------------------------------------------------------*
*& Form FIELD_CATALOG
*&--------------------------------------------------------------*
FORM field_catalog CHANGING pt_fieldcat LIKE it_fieldcat.
DATA lw_fieldcat LIKE LINE OF pt_fieldcat.
lw_fieldcat-col_pos = 1.
lw_fieldcat-fieldname = 'CARRID'.
lw_fieldcat-tabname = 'IT_SFLIGHT'.
lw_fieldcat-seltext_m = 'Airline Code'.
APPEND lw_fieldcat TO pt_fieldcat.
CLEAR lw_fieldcat.

lw_fieldcat-col_pos = 2.
lw_fieldcat-fieldname = 'CONNID'.
lw_fieldcat-tabname = 'IT_SFLIGHT'.
lw_fieldcat-seltext_l = 'Flight Connection Number'.
lw_fieldcat-outputlen = 25.
APPEND lw_fieldcat TO pt_fieldcat.
CLEAR lw_fieldcat.

lw_fieldcat-col_pos = 3.
lw_fieldcat-fieldname = 'FLDATE'.
lw_fieldcat-tabname = 'IT_SFLIGHT'.
lw_fieldcat-seltext_m = 'Flight Date'.
APPEND lw_fieldcat TO pt_fieldcat.
CLEAR lw_fieldcat.

lw_fieldcat-col_pos = 4.
lw_fieldcat-fieldname = 'PRICE'.
lw_fieldcat-tabname = 'IT_SFLIGHT'.
lw_fieldcat-seltext_m = 'Airfare'.
APPEND lw_fieldcat TO pt_fieldcat.
CLEAR lw_fieldcat.

lw_fieldcat-col_pos = 5.
lw_fieldcat-fieldname = 'CURRENCY'.
lw_fieldcat-tabname = 'IT_SFLIGHT'.
lw_fieldcat-seltext_m = 'Airline Currency'.
APPEND lw_fieldcat TO pt_fieldcat.
CLEAR lw_fieldcat.
ENDFORM.
*&--------------------------------------------------------------*
*& Form SHOW_OUTPUT
*&--------------------------------------------------------------*
FORM show_output.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_GRID_TITLE = 'ALV Grid Display'
IT_FIELDCAT = it_fieldcat
TABLES
t_outtab = it_sflight
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.

Listing 15.3    Using Field Catalog

In Listing 15.3, we are printing certain fields from table SFLIGHT (see Figure 15.4), as defined in the TY_SFLIGHT structure. We defined a field catalog internal table IT_FIELDCAT of type SLIS_T_FIELDCAT_ALV.SLIS_T_FIELDCAT_ALV as a table type, which belongs to the type group SLIS and has a line type of SLIS_FIELDCAT_ALV. The SLIS_FIELDCAT_ALV structure has various field catalog components.

In our program, we’re passing various information about the output fields by filling the components of structure SLIS_FIELDCAT_ALV. For example, we’re passing the name of the internal table that holds the output data to the TABNAME component, the field name to the FIELDNAME component, the column position to the COL_POS component, and the column name to the relevant SELTEXT component.

In Listing 15.3, the field catalog is filled inside the FIELD_CATALOG subroutine. The function module documentation should help you explore other components of the field catalog that can be used for formatting the output.

We can also use the REUSE_ALV_FIELDCATALOG_MERGE function module to fill the field catalog internal table.

Printing Selected Table SFLIGHT Fields

Figure 15.4    Printing Selected Table SFLIGHT Fields

The layout can be handled by passing a structure of type SLIS_LAYOUT_ALV to the IS_LAYOUT formal parameter. Using the IS_LAYOUT parameter, we can control the output layout, such as making the fields editable, using a stripped pattern for cells, removing horizontal or vertical lines, and so on. The function module documentation explains the significance of each component of the SLIS_LAYOUT_ALV structure.

Listing 15.4 shows how the IS_LAYOUT parameter can be used to make the cells editable, as shown in Figure 15.5.

Note

The cells can be made editable only in a grid display; this feature is not supported in a list display.

FORM show_output.
DATA layout TYPE SLIS_LAYOUT_ALV.
layout-edit = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_GRID_TITLE = 'ALV Grid Display'
IS_LAYOUT = layout
IT_FIELDCAT = it_fieldcat
TABLES
t_outtab = it_sflight
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.

Listing 15.4    Passing an ALV Layout

Making Cells Editable

Figure 15.5    Making Cells Editable

15.1.2    Block Display

Using a block display, we can print data from multiple internal tables in the output, with each internal table’s data printed in a block. For a block display, we use three function modules:

Listing 15.5 shows the sample code to work with a block display.

REPORT ZDEMO_BLOCK_REPORT.
DATA : it_sflight TYPE STANDARD TABLE OF sflight,
it_spfli TYPE STANDARD TABLE OF spfli,
it_fcat_sflight TYPE SLIS_T_FIELDCAT_ALV,
it_fcat_spfli TYPE slis_t_fieldcat_alv,
it_events TYPE SLIS_T_EVENT.

PARAMETERS p_carrid TYPE s_carr_id.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM field_catalog.
PERFORM show_output.

*&--------------------------------------------------------------*
*& Form GET_DATA
*&--------------------------------------------------------------*
FORM get_data .
SELECT * FROM sflight INTO TABLE it_sflight WHERE carrid EQ p_carrid.
SELECT * FROM spfli INTO TABLE it_spfli WHERE carrid EQ p_carrid.
ENDFORM.
*&--------------------------------------------------------------*
*& Form FIELD_CATALOG
*&--------------------------------------------------------------*
FORM field_catalog .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
CHANGING
ct_fieldcat = it_fcat_spfli
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
ct_fieldcat = it_fcat_sflight
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&--------------------------------------------------------------*
*& Form SHOW_OUTPUT
*&--------------------------------------------------------------*
FORM show_output .
DATA layout TYPE SLIS_LAYOUT_ALV.
layout-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = 'ZDEMO_BLOCK_REPORT'
.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = layout
it_fieldcat = it_fcat_spfli
i_tabname = 'IT_SPFLI'
it_events = it_events
TABLES
t_outtab = it_spfli
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = layout
it_fieldcat = it_fcat_sflight
i_tabname = 'IT_SFLIGHT'
it_events = it_events
TABLES
t_outtab = it_sflight
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.



CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.

Listing 15.5    Block Display

In Listing 15.5, we’re selecting data from tables SFLIGHT and SPFLI and displaying that data as blocks in the output, as shown in Figure 15.6.

Block Display Showing Data from Tables SPFLI and SFLIGHT

Figure 15.6    Block Display Showing Data from Tables SPFLI and SFLIGHT

15.1.3    Hierarchical Sequential Display

A hierarchical sequential display is used when displaying related data, such as the header and item data of a document. We use the REUSE_ALV_HIERSEQ_LIST_DISPLAY function module to generate the hierarchical sequential display. This function module requires you to pass the header and item tables along with the key information of the tables.

The key information is used to identify the related records in the header and item tables. A field catalog is prepared with all the fields of the header and item tables and is passed to the function module.

Listing 15.6 shows the sequential report for a billing document, with certain data about the header and item details of the billing document printed in the output (see Figure 15.7).

REPORT ZDEMO_HIERARCHICAL_REPORT.
TYPES : BEGIN OF ty_vbrk,
vbeln TYPE vbeln_vf, "Document Number
kunrg TYPE kunrg, "Payer
fkdat TYPE fkdat, "Billing date
netwr TYPE netwr, "Net Value
END OF ty_vbrk.
TYPES : BEGIN OF ty_vbrp,
vbeln TYPE vbeln_vf, " Document Number
posnr TYPE posnr_vf, "Billing item
arktx TYPE arktx, "Description of Item
fkimg TYPE fkimg, "Billed quantity
vrkme TYPE vrkme, "Sales Unit
netwr TYPE netwr_fp, "Net Value
matnr TYPE matnr, "Material Number
END OF ty_vbrp.
DATA : it_vbrk TYPE STANDARD TABLE OF ty_vbrk,
it_vbrp TYPE STANDARD TABLE OF ty_vbrp,
it_fieldcat TYPE SLIS_T_FIELDCAT_ALV,
wa_fieldcat TYPE SLIS_FIELDCAT_ALV,
v_vbeln TYPE vbeln_vf.
SELECT-OPTIONS s_vbeln FOR v_vbeln.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM field_catalog.
PERFORM show_output.
*&--------------------------------------------------------------*
*& Form GET_DATA
*&--------------------------------------------------------------*
FORM get_data .
SELECT vbeln kunrg fkdat netwr FROM vbrk INTO TABLE it_vbrk WHERE vbeln IN s_vbeln.
SELECT vbeln posnr arktx fkimg vrkme netwr matnr FROM vbrp INTO TABLE
it_vbrp WHERE vbeln IN s_vbeln.
ENDFORM.
*&--------------------------------------------------------------*
*& Form FIELD_CATALOG
*&--------------------------------------------------------------*
FORM field_catalog .
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'VBELN'.
wa_fieldcat-tabname = 'IT_VBRK'.
wa_fieldcat-seltext_m = 'Document No.'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'KUNRG'.
wa_fieldcat-tabname = 'IT_VBRK'.
wa_fieldcat-seltext_m = 'Customer'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'FKDAT'.
wa_fieldcat-tabname = 'IT_VBRK'.
wa_fieldcat-seltext_m = 'Billing Date'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'NETWR'.
wa_fieldcat-tabname = 'IT_VBRK'.
wa_fieldcat-seltext_m = 'Net Value'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'POSNR'.
wa_fieldcat-tabname = 'IT_VBRP'.
wa_fieldcat-seltext_m = 'Item No'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 6.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-tabname = 'IT_VBRP'.
wa_fieldcat-seltext_m = 'Document No.'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 7.
wa_fieldcat-fieldname = 'ARKTX'.
wa_fieldcat-tabname = 'IT_VBRP'.
wa_fieldcat-seltext_m = 'Description'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 8.
wa_fieldcat-fieldname = 'FKIMG'.
wa_fieldcat-tabname = 'IT_VBRP'.
wa_fieldcat-seltext_m = 'Quantity'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 9.
wa_fieldcat-fieldname = 'VRKME'.
wa_fieldcat-tabname = 'IT_VBRP'.
wa_fieldcat-seltext_m = 'UoM'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 10.
wa_fieldcat-fieldname = 'NETWR'.
wa_fieldcat-tabname = 'IT_VBRP'.
wa_fieldcat-seltext_m = 'Net Value'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDFORM.
*&--------------------------------------------------------------*
*& Form SHOW_OUTPUT
*&--------------------------------------------------------------*
FORM show_output .
DATA layout TYPE SLIS_LAYOUT_ALV.
DATA key_info TYPE SLIS_KEYINFO_ALV.
key_info-header01 = 'VBELN'.
key_info-item01 = 'VBELN'.
layout-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
IS_LAYOUT = layout
IT_FIELDCAT = it_fieldcat
i_tabname_header = 'IT_VBRK'
i_tabname_item = 'IT_VBRP'
is_keyinfo = key_info
TABLES
t_outtab_header = it_vbrk
t_outtab_item = it_vbrp
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.

Listing 15.6    Hierarchical Sequential List Display

In Listing 15.6, data from the billing document header table VBRK is fetched into the internal table IT_VBRK, and the item data from the database table VBRP is fetched into the internal table IT_VBRP.

A field catalog is built manually with all the fields of the header and item tables. The REUSE_ALV_HIERSEQ_LIST_DISPLAY function module is called in the program to which the field catalog is passed, along with the internal tables that contain the header and item table. A KEY_INFO structure of type SLIS_KEYINFO_ALV is used to pass the common key fields of the header and item tables.

Hierarchical Sequential ReportHierarchical sequential report

Figure 15.7    Hierarchical Sequential Report

In this section, we discussed the different standard ALV report types available from the reuse library. In the next section, we’ll transition into a discussion of interactive reports.