Classical Interactive Report

Classical Interactive Report

Interactive program generally interacts with user on the output screen. Let us suppose we have an output for a particular program/report. Now if we want details description by double clicking on a particular field or clicking on a button then it will be called interaction with output. By doing this we can go to the detailed report or secondary output. When we are on the secondary output then we can back to our first out by clicking on Back button. We can generate 19 secondary list of output. Hence a total of 20 output screen (1 Primary + 19 Secondary) can be generated by Interactive program.

We have a requirement where we have to prepare a primary output containing Purchase Order, Company Code, Category, Type and Vendor with PO Info. The secondary list will be generated with PO Item, Material, Plant, Storage Location, Material Group, Quantity and Unit of measure. The secondary list will be generated if we double click on PO field in primary output.

We have mentioned the tables EKKO, EKPO and T161T. Now we have declared the structure types of internal tables of it_ekko, it_text, it_out1 and it_ekpo. Here it_out1 contains the combination of two internal tables it_ekko and it_text and it_ekpo is for the secondary output. For internal operation we have declared work area of every internal tables.

Next we have mentioned the event INITIALIZATION. Under this we are calling program name, user name and system date of the program. We have declared here selection screen begin with block b1 and under this we are mentioning obligatory select option.

Now under START-OF-SELECTION we are declaring all the operations for primary listing. We have made 4 subroutines. In get_ekko we select fields from EKKO into internal table it_ekko. Then in get_t161t we select fields from t161t into internal table it_text for all entries in it_ekko. After that we are preparing the primary output in the basic_output subroutine. Now we have made another subroutine for displaying the primary output and that is disp_basic.

Hence the primary list is prepared now and now we have to create the secondary list. To make the secondary list we are calling event AT LINE-SELECTION which raises functionality when user double clicks in any field. Now we are mentioning GET CURSOR for that field and for that value of the field. When these two are matches with Purchase Order (EBELN) field then we are calling two subroutines for secondary list. 

Subroutine get_ekpo Selects fields from EKPO into table it_ekpo for all entries in it_ekko. Then it prepares the secondary output display in the subroutine of ekpo_output.

We also have raised events TOP-OF-PAGE which shows the header list of primary output and TOP-OF-PAGE DURING LINE-SELECTION which shows the top list of secondary output. Here TOP-OF-PAGE DURING LINE-SELECTION is used only for interactive reports. That means when user double clicks on the field the TOP-OF-PAGE DURING LINE-SELECTION event triggers to make the secondary output header.

REPORT  zabap_gui.

* Declaring line structure of database tables
TABLES: ekko, ekpo, t161t.

* Declaring local structures for internal table & work area
TYPES:
       BEGIN OF ty_ekko,
        ebeln TYPE ekko-ebeln, "Purchase Order
        bukrs TYPE ekko-bukrs, "Company Code
        bstyp TYPE ekko-bstyp, "Category
        bsart TYPE ekko-bsart, "Type
        lifnr TYPE ekko-lifnr, "Vendor
       END OF ty_ekko,

       BEGIN OF ty_text,
        spras TYPE t161t-spras,
        bsart TYPE t161t-bsart,
        bstyp TYPE t161t-bstyp,
        batxt TYPE t161t-batxt, "PO Info
       END OF ty_text,

       BEGIN OF ty_ekpo,
        ebeln TYPE ekpo-ebeln, "Purchase Order
        ebelp TYPE ekpo-ebelp, "PO Item
        matnr TYPE ekpo-matnr, "Material
        werks TYPE ekpo-werks, "Plant
        lgort TYPE ekpo-lgort, "Storage Location
        matkl TYPE ekpo-matkl, "Material Group
        menge TYPE ekpo-menge, "Quantity
        meins TYPE ekpo-meins, "Unit
       END OF ty_ekpo,

       BEGIN OF ty_out1,
        ebeln TYPE ekko-ebeln,
        bukrs TYPE ekko-bukrs,
        bstyp TYPE ekko-bstyp,
        bsart TYPE ekko-bsart,
        lifnr TYPE ekko-lifnr,
        batxt TYPE t161t-batxt,
       END OF ty_out1.

* Declaring work area & internal table
DATA:
      wa_ekko TYPE ty_ekko,                   "Header table work area
      it_ekko TYPE STANDARD TABLE OF ty_ekko, "Header internal table
      wa_text TYPE ty_text,                   "Info table work area
      it_text TYPE STANDARD TABLE OF ty_text, "Info internal table
      wa_out1 TYPE ty_out1,                   "Basic output work area
      it_out1 TYPE STANDARD TABLE OF ty_out1, "Basic output internal table
      wa_ekpo TYPE ty_ekpo,                   "Item table work area
      it_ekpo TYPE STANDARD TABLE OF ty_ekpo, "Item internal table

      v_repid TYPE sy-repid,
      v_user  TYPE sy-uname,
      v_date  TYPE sy-datum,

      v_field1 TYPE char40,
      v_field2 TYPE char40,
      v_value1 TYPE char40,
      v_value2 TYPE char40.

* Event Initialization
INITIALIZATION.
  v_repid = sy-repid. "Program Name
  v_user  = sy-uname. "User name
  v_date  = sy-datum. "Current Date

* Declaring selection screen
  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  SELECT-OPTIONS   s_ebeln FOR ekko-ebeln OBLIGATORY.
  SELECTION-SCREEN END OF BLOCK b1.

* Event Start of Selection
START-OF-SELECTION.  PERFORM get_ekko.     "Get data from header table
  PERFORM get_t161t.    "Get data from Info table
  PERFORM basic_output. "Preparing the primary output
  PERFORM disp_basic.   "Displaying output of first list

* Event At line selection for Double click operation
AT LINE-SELECTION.
* It passes the field and value to the current cursor position
* When double click is happened on the PO field of Primary list
  GET CURSOR FIELD v_field1 VALUE v_value1.

  CASE v_field1.
*   When we double click on PO number on Basic output list
    WHEN 'WA_OUT1-EBELN'.
      PERFORM get_ekpo.    "Get data from Item table
      PERFORM ekpo_output. "Displaying output of second list
  ENDCASE.

* It passes the field and value to the current cursor position
* When double click is happened on the Material field of Secondary list
  GET CURSOR FIELD v_field2 VALUE v_value2.

  CASE v_field2.
*   When we double click on Material on Second list
    WHEN 'WA_EKPO-MATNR'.
      PERFORM get_mara. "Get Information by calling MM03 Transaction
  ENDCASE.

* Event top of page for Basic list / Primary list
TOP-OF-PAGE.  PERFORM top_page1.

* Event top of page for Second list
TOP-OF-PAGE DURING LINE-SELECTION.  PERFORM top_page2.

*&---------------------------------------------------------------------*
*&      Form  get_ekko
*&---------------------------------------------------------------------*
*       Get data from header table
*----------------------------------------------------------------------*
FORM get_ekko .

* Selection of header table data
  SELECT ebeln bukrs bstyp bsart lifnr
  FROM ekko INTO TABLE it_ekko
  WHERE ebeln IN s_ebeln.

  IF sy-subrc = 0.
    SORT it_ekko BY ebeln.
  ELSE.
    MESSAGE 'Purchase Order doesn''t exist.' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " get_ekko
*&---------------------------------------------------------------------*
*&      Form  get_t161t
*&---------------------------------------------------------------------*
*       Get data from Info table
*----------------------------------------------------------------------*
FORM get_t161t .

* Seelction of Info table data
  IF it_ekko IS NOT INITIAL.      "Prerequisite of For all Entries
    SELECT spras bsart bstyp batxt
    FROM t161t INTO TABLE it_text
    FOR ALL ENTRIES IN it_ekko
    WHERE spras = sy-langu        "System language at login time
      AND bsart = it_ekko-bsart
      AND bstyp = it_ekko-bstyp.

    IF sy-subrc = 0.
      SORT it_text BY bsart bstyp.
    ENDIF.
  ENDIF.

ENDFORM.                                                    " get_t161t
*&---------------------------------------------------------------------*
*&      Form  basic_output
*&---------------------------------------------------------------------*
*       Preparing the primary output
*----------------------------------------------------------------------*
FORM basic_output .

* Preparing the basic output table
  IF it_ekko IS NOT INITIAL.
    LOOP AT it_ekko INTO wa_ekko.
      wa_out1-ebeln = wa_ekko-ebeln.
      wa_out1-bukrs = wa_ekko-bukrs.
      wa_out1-bstyp = wa_ekko-bstyp.
      wa_out1-bsart = wa_ekko-bsart.
      wa_out1-lifnr = wa_ekko-lifnr.

      READ TABLE it_text INTO wa_text
      WITH KEY bsart = wa_ekko-bsart
               bstyp = wa_ekko-bstyp BINARY SEARCH.
      IF sy-subrc = 0.
        wa_out1-batxt = wa_text-batxt.
      ENDIF.

      APPEND wa_out1 TO it_out1.
      CLEAR: wa_out1, wa_ekko, wa_text.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " basic_output
*&---------------------------------------------------------------------*
*&      Form  disp_basic
*&---------------------------------------------------------------------*
*       Displaying output of first list
*----------------------------------------------------------------------*
FORM disp_basic .

  IF it_out1 IS NOT INITIAL.
    LOOP AT it_out1 INTO wa_out1.
      AT FIRST"Control Break Statement - triggers at first
        WRITE: /  'Purchase Order',
               20 'Company',
               30 'Category',
               40 'Type',
               50 'Vendor',
               65 'PO Info.'.
        ULINE.
        SKIP.
      ENDAT.

      WRITE: /  wa_out1-ebeln,
             20 wa_out1-bukrs,
             33 wa_out1-bstyp,
             40 wa_out1-bsart,
             50 wa_out1-lifnr,
             65 wa_out1-batxt.

      AT LAST"Control Break Statement - triggers at last
        SKIP.
        ULINE.
        WRITE: /12 '~~End of Report~~'.
      ENDAT.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " disp_basic
*&---------------------------------------------------------------------*
*&      Form  get_ekpo
*&---------------------------------------------------------------------*
*       Get data from Item table
*----------------------------------------------------------------------*
FORM get_ekpo .

* Local temporary variable for conversion
  DATA: lv_ebeln TYPE ekko-ebeln.

  IF v_value1 IS NOT INITIAL.

*   To convert the value from output format to input format
*   and passing it from input format to output format
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = v_value1
      IMPORTING
        output = lv_ebeln.

    IF lv_ebeln IS NOT INITIAL.

*     Selection of Item table
      SELECT ebeln ebelp matnr werks lgort
             matkl menge meins
        FROM ekpo INTO TABLE it_ekpo
        WHERE ebeln = lv_ebeln.

      IF sy-subrc <> 0.
        MESSAGE 'PO Item doesn''t Exist.' TYPE 'I'.
        LEAVE LIST-PROCESSING.      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_ekpo
*&---------------------------------------------------------------------*
*&      Form  ekpo_output
*&---------------------------------------------------------------------*
*       Displaying output of second list
*----------------------------------------------------------------------*
FORM ekpo_output .

* Preparing secondary output
  IF it_ekpo IS NOT INITIAL.
    LOOP AT it_ekpo INTO wa_ekpo.

      AT FIRST.
        WRITE: /  'Purchase Order',
               20 'PO Item',
               30 'Material',
               48 'Plant',
               55 'Storage',
               65 'Material Group',
               83 'PO Quantity',
              100 'Unit'.
        ULINE.
        SKIP.
      ENDAT.

      WRITE: /  wa_ekpo-ebeln,
             20 wa_ekpo-ebelp,
             30 wa_ekpo-matnr,
             48 wa_ekpo-werks,
             55 wa_ekpo-lgort,
             70 wa_ekpo-matkl,
             75 wa_ekpo-menge,
            100 wa_ekpo-meins.

      AT LAST.
        SKIP.
        ULINE.
        WRITE: /12 '~~End of PO Item~~'.
      ENDAT.

    ENDLOOP.
  ENDIF.

ENDFORM.                    " ekpo_output
*&---------------------------------------------------------------------*
*&      Form  get_mara
*&---------------------------------------------------------------------*
*       Get Information by calling MM03 Transaction
*----------------------------------------------------------------------*
FORM get_mara .

* Local temporary variable for conversion
  DATA: lv_matnr TYPE mara-matnr.

  IF v_value2 IS NOT INITIAL.

*   Converting material from output format to input format
*   and passing it from input format to output format
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = v_value2
      IMPORTING
        output       = lv_matnr
      EXCEPTIONS
        length_error = 1
        OTHERS       = 2.

    IF lv_matnr IS NOT INITIAL.

*     Calling the MM03 transaction needs parameter ID
*     which is available on domain of MATNR
      SET PARAMETER ID 'MAT' FIELD lv_matnr.
      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_mara

*&---------------------------------------------------------------------*
*&      Form  top_page1
*&---------------------------------------------------------------------*
*       Event top of page for Basic list / Primary list
*----------------------------------------------------------------------*
FORM top_page1 .

  WRITE: / 'Purchase Order Header',
         / 'Date: ',   12 v_date DD/MM/YYYY,
         / 'User: ',   12 v_user,
         / 'Report: '12 v_repid.
  ULINE.
  SKIP.

ENDFORM.                                                    " top_page1
*&---------------------------------------------------------------------*
*&      Form  top_page2
*&---------------------------------------------------------------------*
*       Event top of page for Second list
*----------------------------------------------------------------------*
FORM top_page2 .

  WRITE: / 'Purchase Order Item List',
         / 'Date: ',   12 v_date DD/MM/YYYY,
         / 'User: ',   12 v_user,
         / 'Report: '12 v_repid.
  ULINE.
  SKIP.

ENDFORM.                                                    " top_page2


Below is the output:


Primary Listing:


If we double click on the PO in this list then following will be generated:

Share this

Related Posts