banner ads

Report to Report Calling by Select Option

Report to Report Calling by Select Option

We already have known to call a report from another report. We have called report by using parameter values. Basically we are passing the parameter values from the calling program to the called program. Now we shall do the same thing by using select option.

We know that the select option is an internal table with header line. So we need to pass the values of that internal table from calling program to called program. To pass this we have to declare another internal table of a standard structure RSPARAMS. It contains 6 fields. Those are Selname (the name of the select option), Kind (type of selection), Sign, Option, Low & High. The last four fields are same as select option.

In the following example our calling program is zsr_test and the called one is zsr_test1. We are declaring a select option s_ebeln in the calling program. We also prepare the table of RSPARAMS where we are mentioning the Selname of the called program (s_ebeln1). The sign, option, low & high will be from the current select option (s_ebeln). After preparing this we call the called program by SUBMIT statement. Here we are using the RETURN clause also to get back the intermediary steps.


TABLES: ekko, rsparams.
DATA: it_params TYPE TABLE OF rsparams,
      wa_params TYPE rsparams.

SELECT-OPTIONS s_ebeln FOR ekko-ebeln.

LOOP AT s_ebeln.
  wa_params-selname = 'S_EBELN1'.
  wa_params-kind    = 'S'.
  wa_params-sign    = s_ebeln-sign.
  wa_params-option  = s_ebeln-option.
  wa_params-low     = s_ebeln-low.
  wa_params-high    = s_ebeln-high.
  APPEND wa_params TO it_params.

                 AND RETURN.

Now in the called program we also have to declare the select option of s_ebeln1. After that to fetch the data from EKKO table we mention the ABAP logic. We also have mentioned the interactive operation of double click. The purpose is to go another report when user double clicks on the PO number of the header output (zsr_test1).


TABLES ekko.
        ebeln TYPE ekko-ebeln,
        bukrs TYPE ekko-bukrs,
        ernam TYPE ekko-ernam,
        lifnr TYPE ekko-lifnr,
       END OF ty_ekko.

DATA: wa_ekko TYPE ty_ekko,
      it_ekko TYPE TABLE OF ty_ekko,
      v_field TYPE char40,
      v_value TYPE char10.

  SELECT-OPTIONS s_ebeln1 FOR ekko-ebeln.


  GET CURSOR FIELD v_field VALUE v_value.
  CASE v_field.
      SUBMIT zsr_test2 WITH p_ebeln EQ v_value
                       AND RETURN.

*&      Form  po_header
*       text
FORM po_header .
  IF s_ebeln1[] IS NOT INITIAL.
    SELECT ebeln bukrs ernam lifnr
      FROM ekko INTO TABLE it_ekko
      WHERE ebeln IN s_ebeln1.

    IF sy-subrc = 0.
      SORT it_ekko.
      LOOP AT it_ekko INTO wa_ekko.
        AT FIRST.
          WRITE: /3 'Purchase Order',
                 20 'Company',
                 30 'Creator',
                 45 'Vendor'.

        WRITE: /3 wa_ekko-ebeln,
               20 wa_ekko-bukrs,
               30 wa_ekko-ernam,
               45 wa_ekko-lifnr.
ENDFORM.                    " po_header

After that we create the third program zsr_test2 for PO item wise report. The RETURN clause will get back to every single intermediary step.


TABLES ekpo.
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        menge TYPE ekpo-menge,
        meins TYPE ekpo-meins,
        netpr TYPE ekpo-netpr,
        peinh TYPE ekpo-peinh,
       END OF ty_ekpo.

DATA: wa_ekpo TYPE ty_ekpo,
      it_ekpo TYPE TABLE OF ty_ekpo.

  PARAMETERS p_ebeln TYPE ekpo-ebeln.


*&      Form  get_PO_item
*       text
FORM get_po_item .
  IF p_ebeln IS NOT INITIAL.
    SELECT ebeln ebelp menge meins netpr peinh
      FROM ekpo INTO TABLE it_ekpo
      WHERE ebeln = p_ebeln.

    IF sy-subrc = 0.
      SORT it_ekpo.
      LOOP AT it_ekpo INTO wa_ekpo.
        AT FIRST.
          WRITE: /3 'Purchase Order',
                 20 'Item',
                 30 'PO Quantity',
                 44 'Unit',
                 49 'Net Price',
                 63 'Currency'.

        WRITE: /3 wa_ekpo-ebeln,
               20 wa_ekpo-ebelp,
               27 wa_ekpo-menge,
               44 wa_ekpo-meins,
               49 wa_ekpo-netpr,
               63 wa_ekpo-peinh.
ENDFORM.                    " get_PO_item

Now we execute the first program zsr_test and get the following output.

The selection screen is from the zsr_test (Calling Program for Testing). 

After giving the selection range we get the following output.

Now the output is coming from the called one zsr_test1 (Called program - PO header). Now we double click on the PO – 4500006374 and get the following output from another report zsr_test2 (Called Program PO Item details).

No comments