Classical Interactive with Push Button

Interactive reports increase the visibility of user when the user interacts with the basic list to get detail secondary lists. The basic list contains the brief information whereas the detail list contains the detail information. As per the requirement the user interacts with the detailed list whenever it is needed. That is the reason why it increases the visibility. Instead of an extensive and detailed list the user can actively control data retrieval and display during the session through this interactive report. The user can interact with the report with having the cursor position and entering the command.

There are several events for Interactive report:
1.       At line selection (when user double clicks to a particular field value)
2.       At user command (when user selects a particular field value and then clicks a push button)
3.       Top of page during line selection (it displays different content at different secondary lists)

To interact by using a push button the R/3 system has an option which is menu painter. We can do this by using the PF-STATUS. With the help of that we can create our customized menu where we can set push button. After that we have to write functionality under the event at user command. The push button must have a function code and by using that we can write our custom function. The system field SY-UCOMM is used to set the different functions in different push buttons.

Here we have an example where we select Vendor account details based on the selection criteria by select options. The report will have a basic list which will display the vendor details from LFA1 table. Then by selecting a vendor account number if we click the push button Purchase Order then we shall go to the first secondary list. This list is coming from the EKKO table. After that if we select any purchase order and then click the PO item button then second secondary list will be coming. This list is coming from EKPO table.

In this point of view we have used HIDE statement. HIDE actually hides the field value into the system to reuse that at any time. With the help of this statement the system loads the field name, field content and line number in which the line exists. The line number is stored in SY-LINNO field. Field symbols cannot be specified in HIDE. This statement works independently. If we select the cursor to any blank field then also the HIDE will store that value.

REPORT  zabap_gui.

*-------Declaring database tables for using the line type--------------*
TABLES: lfa1, ekko, ekpo.

*------Declaring structures for work area & Internal table-------------*
TYPES: BEGIN OF ty_lfa1,
         lifnr TYPE lfa1-lifnr,
         land1 TYPE lfa1-land1,
         name1 TYPE lfa1-name1,
         regio TYPE lfa1-regio,
       END OF ty_lfa1,

       BEGIN OF ty_ekko,
         ebeln TYPE ekko-ebeln,
         bukrs TYPE ekko-bukrs,
         aedat TYPE ekko-aedat,
         ernam TYPE ekko-ernam,
         lifnr TYPE ekko-lifnr,
       END OF ty_ekko,

       BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         lgort TYPE ekpo-lgort,
       END OF ty_ekpo.

*-----Declaring Work Areas---------------------------------------------*
      wa_lfa1 TYPE ty_lfa1,
      wa_ekko TYPE ty_ekko,
      wa_ekpo TYPE ty_ekpo,

*-----Declaring Internal Tables----------------------------------------*
      it_lfa1 TYPE TABLE OF ty_lfa1,
      it_ekko TYPE TABLE OF ty_ekko,
      it_ekpo TYPE TABLE OF ty_ekpo.

*---Event Initialization-----------------------------------------------*
  SELECT-OPTIONS: s_lifnr FOR lfa1-lifnr.

*---Event Start of Selection-------------------------------------------*
  PERFORM get_data_lfa1.
  SET PF-STATUS 'PUSH_BUTTON'. "Setting PF status for Push Buttons

*---Event At User Command----------------------------------------------*
AT USER-COMMAND. "When user clicks any button

  CASE sy-ucomm. "It contains the function code of any button
    WHEN 'EKKO'. "Push button Purchase Order
      PERFORM get_data_ekko.

    WHEN 'EKPO'. "Push button Purchase Order Item
      PERFORM get_data_ekpo.

    WHEN 'EXIT'. "Push button Exit
    WHEN 'CANCEL'. "Push button Cancel

*---Event Top of Page for Basic List-----------------------------------*
  PERFORM top_basic_lfa1.

*---Event Top of Page During Line Selection for Drilled List-----------*
  CASE sy-lsind. "It counts the drilled number
    WHEN '1'.
      PERFORM top_ekko.
    WHEN '2'.
      PERFORM top_ekpo.
*&      Form  get_data_lfa1
*       Select data from Vendor table
FORM get_data_lfa1 .

  REFRESH it_lfa1.

  IF s_lifnr[] IS NOT INITIAL.
    SELECT lifnr land1 name1 regio
      FROM lfa1 INTO TABLE it_lfa1
      WHERE lifnr IN s_lifnr.

    IF sy-subrc = 0.
      LOOP AT it_lfa1 INTO wa_lfa1.
        WRITE: / wa_lfa1-lifnr,
              20 wa_lfa1-land1,
              25 wa_lfa1-name1,
              65 wa_lfa1-regio.

        HIDE wa_lfa1-lifnr. "Vendor is keeping Hide to store the data
                            "into system temporarily
        AT LAST.
          SKIP 2.
          WRITE: /25 'End of Vendor Account List'.

      MESSAGE 'Vendor doesn''t exist' TYPE 'I'.
    MESSAGE 'Please enter a valid Vendor Account Number' TYPE 'I'.

ENDFORM.                    " get_data_lfa1
*&      Form  get_data_ekko
*       Select data from Purchase Order Header table
FORM get_data_ekko .

  REFRESH it_ekko.

  IF wa_lfa1-lifnr IS NOT INITIAL.
    SELECT ebeln bukrs aedat ernam lifnr
      FROM ekko INTO TABLE it_ekko
      WHERE lifnr = wa_lfa1-lifnr.

    IF sy-subrc = 0.
      LOOP AT it_ekko INTO wa_ekko.
        WRITE: / wa_ekko-ebeln,
              15 wa_ekko-bukrs,
              22 wa_ekko-aedat,
              34 wa_ekko-ernam,
              50 wa_ekko-lifnr.

        HIDE wa_ekko-ebeln. "PO is keeping Hide to store the data
                            "into system temporarily
        AT LAST.
          SKIP 2.
          WRITE: /20 'End of Purchase Order List'.
      MESSAGE 'Purchase Order doesn''t exist' TYPE 'I'.

ENDFORM.                    " get_data_ekko
*&      Form  get_data_ekpo
*       Select data from Purchase Order Item Table
FORM get_data_ekpo .

  REFRESH it_ekpo.

  IF wa_ekko-ebeln IS NOT INITIAL.
    SELECT ebeln ebelp matnr werks lgort
      FROM ekpo INTO TABLE it_ekpo
      WHERE ebeln = wa_ekko-ebeln.

    IF sy-subrc = 0.
      LOOP AT it_ekpo INTO wa_ekpo.
        WRITE: / wa_ekpo-ebeln,
              15 wa_ekpo-ebelp,
              22 wa_ekpo-matnr,
              42 wa_ekpo-werks,
              50 wa_ekpo-lgort.

        AT LAST.
          SKIP 2.
          WRITE: /25 'End of Material List'.
    MESSAGE 'Select a Purchase Order' TYPE 'I'.

ENDFORM.                    " get_data_ekpo
*&      Form  top_basic_lfa1
*       Top of page of basic list - Vendor list
FORM top_basic_lfa1 .

  WRITE: / 'Vendor Account List' COLOR 3.
  WRITE: / 'Vendor Account',
        20 'Land',
        25 'Name',
        65 'Region'.

ENDFORM.                    " top_basic_lfa1
*&      Form  top_ekko
*       Top of page for first secondary list - PO header list
FORM top_ekko .

  WRITE: / 'Purchase Order List' COLOR 5.
  WRITE: / 'Po Number',
        15 'Company',
        22 'Date',
        34 'Name',
        50 'Vendor Account Number'.

ENDFORM.                    " top_ekko
*&      Form  top_ekpo
*       Top of page for second secondary list - PO item list
FORM top_ekpo .

  WRITE: / 'Purchase Order List' COLOR 1.
  WRITE: / 'PO Number',
        15 'PO Item',
        22 'Material',
        42 'Plant',
        50 'Storage'.

ENDFORM.                    " top_ekpo

Here is the output of Selection Screen:

The basic list of Vendor details:

The first secondary list of Purchase Order:

The second secondary list of Purchase Order Item:

Since this is a demo system there is data discrepancy at the database level. Hence Material and storage location is blank.