Tuesday, March 15, 2016

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.

REPORT  zsr_test NO STANDARD PAGE HEADING.

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.
ENDLOOP.

SUBMIT zsr_test1 WITH SELECTION-TABLE 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).

REPORT  zsr_test1 NO STANDARD PAGE HEADING.

TABLES ekko.
TYPES: BEGIN OF ty_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.

INITIALIZATION.
  SELECT-OPTIONS s_ebeln1 FOR ekko-ebeln.

START-OF-SELECTION.
  PERFORM po_header.

AT LINE-SELECTION.
  GET CURSOR FIELD v_field VALUE v_value.
  CASE v_field.
    WHEN 'WA_EKKO-EBELN'.
      SUBMIT zsr_test2 WITH p_ebeln EQ v_value
                       AND RETURN.
  ENDCASE.

*&---------------------------------------------------------------------*
*&      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'.
          ULINE.
          SKIP.
        ENDAT.

        WRITE: /3 wa_ekko-ebeln,
               20 wa_ekko-bukrs,
               30 wa_ekko-ernam,
               45 wa_ekko-lifnr.
      ENDLOOP.
    ENDIF.
  ENDIF.
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.

REPORT  zsr_test2 NO STANDARD PAGE HEADING.

TABLES ekpo.
TYPES: BEGIN OF ty_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.

INITIALIZATION.
  PARAMETERS p_ebeln TYPE ekpo-ebeln.

START-OF-SELECTION.
  PERFORM get_po_item.

*&---------------------------------------------------------------------*
*&      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'.
          ULINE.
          SKIP.
        ENDAT.

        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.
      ENDLOOP.
    ENDIF.
  ENDIF.
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).

12 comments:

kuntal kundu said...

dear sir please send your mob no.my no is 9231540802

kuntal kundu said...

Your tutorial is very helpful.I am from kolkata.I need your contact details.

Rahul said...

Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog on SAP SD.
SAP SD

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...


Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

sushma said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Unknown said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

sanayamohit said...

Best SAP Success Factor Training in Chennai

http://thecreatingexperts.com/sap-training-in-chennai/
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/

Priyasekar said...

Thanks for your info...Here THE CREATING EXPERTS provide hands on training with real time scenarios

http://thecreatingexperts.com/sap-abap-training-in-chennai/

contact +91-08122241286

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882
http://thecreatingexperts.com/category/sap-hana-training-in-chennai/

Unknown said...

Great information. the information provided is of great

use as i got to learn new things. If you are looking for

real time training by industry experts with live projects

and placement support.kindly contact the creating experts

Reach our Technical Experts @ 8122241286 / 9003085882