Interactive Report Program in ABAP

Interactive Report in SAP ABAP is a report where you can interact with the output page of report. You can click on an item of a list to get its details. In this article, we will discuss an example of Interactive Reports. To know more about Events in Interactive Report click here. Do check Interactive Reporting – FAQs for more clarification.

Introduction

ABAP report has more often a requirement to display expandable lists.

For example, On first page you have been provided basic details of employees.

Interactive Report - Page 1 Illustration
Report – Page 1 Illustration

On click of  a line item i.e. Employee ID (Here, we have clicked, 1117582), you are navigated to another page where you can see the employee Annual Salary.

Interactive Report - Page 2 Image Illustration
Report – Page 2 Image Illustration

If you still want to know further, you again clicked on Employee ID(Here, we have clicked, 1117582) here and now you are navigated to third page where you see employee’s salary structure.

Interactive Report Page 3 - Image Illustration
Report Page 3 – Image Illustration

These all things are possible in SAP ABAP using Interactive Reports.

ABAP Interactive Report Program

Program Requirement: Create an ABAP report to take Employee ID as Input and display basic details i.e. Employee ID, First Name and Last Name on First page (list 0). On click of Employee ID, display employee salary details on list 1. Again on click of Employee ID, display address details on list 2.

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.

Code Explanation

In the program mentioned above, we have discussed Interactive operation in ABAP Report. This program has comments wherever required. Still, we will be explaining the key points of this program. This program utilizes ABAP Interactive Events, do read it here, before proceeding.

  • Initially, we have defined Parameters to take Employee ID as input, variables to perform query and have set PF-STATUS as ‘PFSTATUS’. This PF Status is used to display standard Menu buttons on the top i.e. Execute, Close, Back, etc
  • Forms/Performs : Here we have written following forms as per the requirement:
    • validate_input: Here we check if the employee id field is left blank or if wrong employee id is entered. In both cases we raise error
    • get_data:  Here we are fetching basic employee details from table
    • display_data: Here we are displaying data (list 0)
    • primary_list: Here we are fetching employee salary details on list 1
    • secondary_list: Here we are fetching employee address details on list 2

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.