Preface – This post is part of the ABAP Beginner series.
Interactive Report in SAP ABAP is a report where user can interact with the output page of report. They can click on an item of a list to get its details. For example, On first page you have been provided basic details of employees and on click of a line item i.e. Employee ID, you are navigated to another page where you can see the employee Annual Salary. If you still want to know further, you again clicked on Employee ID here and now you are navigated to third page where you see employee’s salary structure. These all things are possible using Interactive Report in SAP ABAP.
Table of Contents
Introduction
An Interactive Report uses a basic list [list number 0] to show basic information and uses secondary list [1 to 20] to show detailed information. Thus, there are total 21 lists. We use SY-LSIND [System Variable] to get the index number of the list.
Events in ABAP
Before, we learn about events of Interactive report, it is advisable to learn all the ABAP events, because it is common across all the programs. ABAP is an event driven Programming language. ABAP Report Events are used to handle different kinds of events during runtime. It starts with the event name, followed by the programming codes belonging to that event.
It is advisable to use Comment line to declare the end of an event, since Events do not have a closing Keyword and it ends as soon any other Event starts.
There are different kinds of events in ABAP, SAP has categorized these events together.
Categories of Events in ABAP:
There are four categories of Events in ABAP. Among them List Events are the one that helps us to make Interactive Reports:
Event Category | Explanation | Events in the Category |
Except Pool programs it occurs in every programs. | LOAD-OF-PROGRAM | |
These events occur only in Executable Reports. | INITIALIZATION START-OF-SELECTION END-OF-SELECTION (obsolete) | |
These events occur during Selection Screen Processing | AT SELECTION-SCREEN OUTPUT AT SELECTION-SCREEN | |
These events occur during Classical List Processing [List can be a table or consecutive Write statements, etc.] | TOP-OF-PAGE END-OF-PAGE AT-LINE-SELECTION AT USER-COMMAND AT PFnn SET USER-COMMAND
|
Events in Classical Report [Used in Interactive Reports too]:
Classical Reports have following events, these events are common for Interactive Reports:
- LOAD-OF-PROGRAM : First event fired, loads program in memory
- INITIALIZATION: Initialize variable
- START-OF-SELECTION : Actual Business Logic (After START-OF-SELECTION)
- END-OF-SELECTION : To end above
- AT SELECTION-SCREEN : To validate Multiple Input fields (After Initialization and before START-OF-SELECTION) (After
- AT SELECTION-SCREEN OUTPUT: To manipulate Dynamic screen
- AT SELECTION-SCREEN ON
- AT SELECTION-SCREEN ON END OF
- AT SELECTION-SCREEN ON BLOCK
- AT SELECTION-SCREEN ON RADIOBUTTON GROUP
- AT SELECTION-SCREEN ON VALUE REQUEST
- TOP-OF-PAGE : To print heading
- END-OF-PAGE: To print footer

Events in Interactive Reports in SAP ABAP – Image Illustration
Events of Interactive Report in SAP ABAP:
- TOP-OF-PAGE
- END-OF-PAGE
- AT-LINE-SELECTION
- AT USER-COMMAND
- AT PFnn
- SET USER-COMMAND
Note: To know more about these events, click here.
Example of Interactive Report in SAP ABAP:
TABLES zBarry_emp. TABLES zBarry_sal. PARAMETERS: ip type char20. DATA : it_emp1 TYPE TABLE OF zBarry_emp, it_emp2 TYPE TABLE OF zBarry_sal, wa_emp TYPE zBarry_emp, wa_emp2 TYPE zBarry_sal, it_emp3 TYPE TABLE OF zBarry_add, wa_emp3 TYPE zBarry_add, fnam TYPE char20, fval TYPE char8, fnam1 TYPE char20, fval1 TYPE char8.. set PF-STATUS 'PFSTATUS'. SELECT-OPTIONS : p_empid FOR zBarry_emp-empid. AT USER-COMMAND. CASE SY-UCOMM. WHEN 'MAIN'. sy-lsind = 1. PERFORM display_data. ENDCASE. AT SELECTION-SCREEN. PERFORM validate_input. START-OF-SELECTION. PERFORM get_data. PERFORM display_data. TOP-OF-PAGE. FORMAT COLOR COL_HEADING INVERSE. WRITE 'BASIC EMPLOYEE DETAILS'. TOP-OF-PAGE DURING LINE-SELECTION. IF sy-lsind = 1. FORMAT COLOR COL_HEADING INVERSE. WRITE 'EMPLOYEE SALARY DETAILS'. ELSEIF sy-lsind = 2. FORMAT COLOR COL_HEADING INVERSE. WRITE 'EMPLOYEE ADDRESS DETAILS'. ENDIF. AT LINE-SELECTION. PERFORM primary_list. PERFORM secondary_list. *&---------------------------------------------------------------------* *& Form VALIDATE_INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM validate_input . "validating input IF p_empid IS INITIAL. MESSAGE 'Please Enter Employee Number' TYPE 'E'. "if the employee id field is left blank ELSE. SELECT empid FROM zBarry_emp INTO TABLE it_emp1 WHERE empid IN p_empid. IF sy-subrc <> 0. MESSAGE 'Please Enter Correct Employee Number' TYPE 'E'. "if wrong employee id is entered ENDIF. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM get_data . "fetching basic employee details from table SELECT * FROM zBarry_emp INTO TABLE it_emp1 WHERE empid IN p_empid. ENDFORM. *&---------------------------------------------------------------------* *& Form DISPLAY_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM display_data . "displaying data FORMAT COLOR COL_NEGATIVE INVERSE. WRITE:/,3 'Employee ID', 20 'First NAME', 35 'Last NAME'. SKIP. LOOP AT it_emp1 INTO wa_emp. FORMAT COLOR COL_POSITIVE INVERSE. WRITE : /3 wa_emp-empid,20 wa_emp-emp_fname,35 wa_emp-emp_lname. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form PRIMARY_LIST *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM primary_list . "fetching employee salary details on list 1 IF sy-lsind = 1. GET CURSOR FIELD fnam VALUE fval. IF fnam = 'WA_EMP-EMPID'. "if employee id is selected SELECT * FROM zBarry_sal INTO TABLE it_emp2 WHERE empid = fval . FORMAT COLOR COL_NEGATIVE INVERSE. WRITE:/,3 'Employee ID', 20 'Transaction ID', 35 'Month', 55 'Date Of Salary'. SKIP. LOOP AT it_emp2 INTO wa_emp2. FORMAT COLOR COL_POSITIVE INVERSE. WRITE : /3 wa_emp2-empid,20 wa_emp2-tid,35 wa_emp2-mon,55 wa_emp2-dos. ENDLOOP. ENDIF. IF fnam = 'WA_EMP-EMP_FNAME'. "if employee name is selected WRITE: / 'name'. ENDIF. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form SECONDARY_LIST *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM secondary_list . "fetching employee address details on list 2 IF sy-lsind = 2. GET CURSOR FIELD fnam1 VALUE fval1. IF fnam = 'WA_EMP-EMPID'. "if employee id is selected SELECT * FROM zBarry_add INTO TABLE it_emp3 WHERE empid = fval1 . FORMAT COLOR COL_NEGATIVE INVERSE. WRITE:/,3 'Employee ID', 20 'Flat No.', 35 'Street Name', 55 'City Name'. SKIP. LOOP AT it_emp3 INTO wa_emp3. FORMAT COLOR COL_POSITIVE INVERSE. WRITE : /3 wa_emp3-empid,20 wa_emp3-flat_no,35 wa_emp3-street_name,55 wa_emp3-city_name. ENDLOOP. ENDIF. ENDIF. ENDFORM.
Note: To learn more about how this program is functioning, click here.
Programming Guidelines:
- Never use Selection Screen Events in Function Module
- Use LOAD-OF-SCREEN to load default values for the type of Reports executed via SUBMIT or using a transaction code
- Use INITIALIZATION to load default values for the executable type of Reports
- It is advised not to specify an event more than once [Except AT-SELECTION-SCREEN & GET event, all other can be specified multiple times.]
- If you are not specifying any event name, still specify START-OF-SELECTION to improve readability
- After every execution of events NEW-LINE event is executed automatically.
1. what is the use of —PARAMETERS: ip type char20.
2. Main & at line selection (Secondary list) not working propertly.
could you share the use of first input box & where we need to provide the MAIN function.