Interactive Report Program in ABAP

by | Jun 4, 2018 | ABAP Programs

Preface – This post is part of the ABAP Programs series.

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.

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 INT4,
       fnam1   TYPE char20,
       fval1   TYPE INT4.
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.

Important Points to Consider

The fields fval and fval1 will hold the value of field that you will double click. In our usecase, we store Employee ID in it and use the same to fetch data from table, hence its field type is similar to the Emp ID, i.e. INT4 .

Also, You need to double click on set PF-STATUS ‘PFSTATUS’.

And enter the following as shown below:

At Line Selection Not Working in ABAP

If F2 value is not set as ‘PICK’ as shown above then it will cause issue and you will wonder why double click is not working for ABAP Interactive report.

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

Output

Screen 1:

Main Screen

 

Screen 2:

Second Screen

Screen 3:

Third Screen

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

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

Advertisement

Advertisement

Advertisement

Advertisement

Go Coding