13.7    Interactive Reports

Interactive reports are those reports that react to user actions on the list screen, adding an element of interactivity to the report. The AT LINE-SELECTION and AT USER-COMMAND events allow you to create interactive reports. Typically, interactive reports are designed in such a way that summarized information is displayed on the basic list and the user can then click on the displayed line to branch out to more detailed information on subsequent lists.

Various techniques are used to identify the line that the user selected on the list and pass this data to subsequent processing blocks. Some of the important ABAP statements used in interactive reports are discussed in the following subsections.

13.7.1    HIDE

The HIDE statement is one of the fundamental statements used with interactive reports. It’s used when creating a basic list to define a hide area where the information that needs to be passed to subsequent lists is defined. Once a record is written to the basic list using the WRITE statement, the HIDE statement is used immediately to store the record in the hide area. When the user selects the record from the list, it’s automatically copied to the data object in the program for which the value was written in the output.

For example, say we need to develop a report to show all the billing documents created in a given date range. The requirement specifies that the user should be presented with a selection screen to input the date range.

On clicking Execute, the report should display all the billing documents created in the given date range. The basic list should display the header data of each document, and the user can double-click the document number to see the item details of the selected document.

Listing 13.9 shows the code for this requirement.

REPORT zdemo_billing_report NO STANDARD PAGE HEADING.

TYPES: BEGIN OF ty_vbrk,
vbeln TYPE vbeln_vf,
fkdat TYPE fkdat,
netwr TYPE netwr,
kunrg TYPE kunrg,
END OF ty_vbrk.

TYPES: BEGIN OF ty_vbrp,
vbeln TYPE vbeln,
posnr TYPE posnr_vf,
arktx TYPE arktx,
fkimg TYPE fkimg,
vrkme TYPE vrkme,
netwr TYPE netwr_fp,
matnr TYPE matnr,
mwsbp TYPE mwsbp,
END OF ty_vbrp.

DATA: it_vbrp TYPE TABLE OF ty_vbrp,
wa_vbrp TYPE ty_vbrp,
it_vbrk TYPE TABLE OF ty_vbrk,
wa_vbrk TYPE ty_vbrk.

SELECT-OPTIONS: s_fkdat FOR wa_vbrk-fkdat.

START-OF-SELECTION.
SELECT vbeln
fkdat
netwr
kunrg
FROM vbrk
INTO TABLE it_vbrk
WHERE fkdat IN s_fkdat.


END-OF-SELECTION.
LOOP AT it_vbrk INTO wa_vbrk.
AT FIRST.
FORMAT COLOR COL_HEADING.
WRITE : 5 'BILLING DOCUMENT',
30 'PAYER',
50 'NET VALUE',
80 'BILLING DATE'.
FORMAT COLOR OFF.
ENDAT.
FORMAT COLOR COL_NORMAL.
WRITE : /5 wa_vbrk-vbeln,
30 wa_vbrk-kunrg,
50 wa_vbrk-netwr LEFT-JUSTIFIED,
80 wa_vbrk-fkdat.
HIDE wa_vbrk-vbeln.
ENDLOOP.
FORMAT COLOR OFF.

AT LINE-SELECTION.

SELECT vbeln
posnr
arktx
fkimg
vrkme
netwr
matnr
mwsbp
FROM vbrp
INTO TABLE it_vbrp
WHERE vbeln EQ wa_vbrk-vbeln.
LOOP AT it_vbrp INTO wa_vbrp.
AT FIRST.
FORMAT COLOR COL_HEADING.
WRITE AT: /5 'ITEM',
20 'DESCRIPTION',
56 'BILLED QUANTITY',
75 'SU',
96 'NET VALUE',
115 'MATERIAL',
130 'TAX AMOUNT'.
FORMAT COLOR OFF.
ENDAT.
FORMAT COLOR COL_NORMAL.
WRITE AT: /5 wa_vbrp-posnr,
20 wa_vbrp-arktx,
55 wa_vbrp-fkimg,
75 wa_vbrp-vrkme,
85 wa_vbrp-netwr,
115 wa_vbrp-matnr,
130 wa_vbrp-mwsbp LEFT-JUSTIFIED.
FORMAT COLOR OFF.
ENDLOOP.
TOP-OF-PAGE.
WRITE 'Billing Document Header Data'.
TOP-OF-PAGE DURING LINE-SELECTION.
WRITE 'Billing Document Item Data'.

Listing 13.9    Billing Document Report

In Listing 13.9, initially the document header details are selected from table VBRK for the given data range and displayed in the basic list. To display the data in basic list, we loop the data in internal table it_vbrk and use the WRITE statement to print the record. We used the HIDE statement before ENDLOOP to store the document number in the hide area, which will be transferred to the AT LINE-SELECTION processing block when the user double-clicks the document number in the basic list.

The hide area is the area in the list buffer in which global variables can be stored for every row of a screen list via the HIDE statement. Without using the HIDE statement, there’s no way to identify the document number on which the user double-clicked in order to fetch subsequent item details for the document inside the AT LINE-SELECTION event. When the user double-clicks the document number, its value will be transferred to the original wa_vbrk-vbeln field in the program. We use this field to select the data from the item table VBRP.

We print the page heading for the basic list under the TOP-OF-PAGE event and the page heading for the detail list under the TOP-OF-PAGE DURING LINE-SELECTION event.

Figure 13.10 shows the expected output in the basic list and Figure 13.11 shows the expected output in the detail list for the given requirement. The detail list is called when the user double-clicks the document number displayed in the basic list.

Basic List for Code in  Basic lists

Figure 13.10    Basic List for Code in Figure 13.9

Detail List for Code in  Detail lists

Figure 13.11    Detail List for Code in Listing 13.9

13.7.2    READ LINE

Similar to the HIDE statement, the READ LINE or READ CURRENT LINE statement can be used to capture the value when the user double-clicks a record. Using the READ LINE statement, you can read any line by supplying the row number. You can use the GET CURSOR statement to dynamically identify the row on which the user double-clicked and use that row number with the READ LINE statement to get the field value, as shown in Listing 13.10. To read the line in succession, use the READ CURRENT LINE statement.

DATA row TYPE sy-index.
GET CURSOR LINE row.
READ LINE row FIELD VALUE wa_vbrk-vbeln.
READ CURRENT LINE FIELD VALUE wa_vbrk-vbeln.

Listing 13.10    Using READ LINE and READ CURRENT LINE

In Listing 13.10, we are defining a row variable of type sy-index to identify the cursor position. The GET CURSOR statement fills the variable row with the line number in the list of the current cursor position. The READ LINE statement reads the field value of the supplied row number, and the READ CURRENT LINE statement automatically reads the line where the cursor is currently positioned.

13.7.3    GET CURSOR

To retrieve information about the cursor position, we can use the GET CURSOR statement to determine the current row and current field, as shown in Listing 13.11.

*Using GET CURSOR to fetch row number
DATA row TYPE sy-index.
GET CURSOR LINE row.
*Using GET CURSOR to fetch column (field) name
DATA field TYPE string.
GET CURSOR FIELD field.

Listing 13.11    Using GET CURSOR

13.7.4    DESCRIBE LIST

The DESCRIBE LIST statement provides information about the attributes of the list levels. Using this statement, we can retrieve information such as the number of lines or number of pages of a list, get the page number of a particular line number, or get the properties of the particular page. Refer to the keyword documentation to see all the possible additions that can be used with this statement.

Listing 13.12 uses the DESCRIBE LIST statement to identify the last page and then read the number of lines on the last page. In this example, the last_page field will contain the total number of pages generated. Using this value, we read the number of lines on the last page. The lines field will contain the number of lines in the last page.

DATA: last_page  TYPE I,
lines TYPE I.
AT LINE-SELECTION.
DESCRIBE LIST NUMBER OF PAGES last_page,
DESCRIBE LIST PAGE last_page LINES lines.

Listing 13.12    Using DESCRIBE LIST Statement