Passing table data to the layout without changing the driver program

By Joyjit Ghosh, IBM India

I have seen a typical requirement from client that SAP script layout need to be changed (additional data need to be displayed) without modifying the driver program (mainly standard SAP program). This tip will show us how to pass table data (multiple records at a time) to layout without changing the driver program. 

Step1. Create a standard text from SO10. 

Create a blank standard text. This will store the table data

 

 

Step2. Create a subroutine pool and a routine in it that can be called from SAP script.

From transaction SE38 create a subroutine pool.

 

Now create subroutine with proper interface to fetch the data from the table.

 

Step3. Within this routine write the logic to fetch the table data and populate the standard text.

***************************************************************
* Fetch table data and upload the data in proper format to the
* standard text
***************************************************************
  DATA: i_zemployee TYPE STANDARD TABLE OF zemployee INITIAL SIZE 0,
        w_zemployee TYPE zemployee,
        i_text TYPE STANDARD TABLE OF tline INITIAL SIZE 0,
        w_header LIKE  thead,
        w_text TYPE tline.
  CONSTANTS: c_par  TYPE char2 VALUE ',,'. " Sign for tabs
* Fetch data for employee
  SELECT * FROM zemployee
  INTO TABLE i_zemployee.
  IF sy-subrc = 0.
*  Create text table
    LOOP AT i_zemployee INTO w_zemployee.
*     Store default paragraph format
      w_text-tdformat = '*'.
*     Add all the required fields separated by tab
      CONCATENATE w_zemployee-empno  w_zemployee-empname
      INTO w_text-tdline
      SEPARATED BY c_par.
*     Store table data
      APPEND w_text TO i_text.
    ENDLOOP.
    check sy-subrc = 0.
*   Populate header info
*   Text object
    w_header-tdobject = 'TEXT'.
*   Standard text name
    w_header-tdname = 'Z_TABLE_DATA'.
*   Text id
    w_header-tdid = 'ST'.
*   Language
    w_header-tdspras = 'E'.
*  Populate the standard text with table data
    CALL FUNCTION 'SAVE_TEXT'
      EXPORTING
        header                = w_header
        insert                = 'X'
        savemode_direct       = 'X'
      TABLES
        lines                 = i_text
     EXCEPTIONS
       id                    = 1
       language              = 2
       name                  = 3
       object                = 4
       OTHERS                = 5
              .
    IF sy-subrc <> 0.
    ENDIF.
  ENDIF. 

Step4. Call the routine and standard text from the SAP script layout.

Note: For the sake of simplicity this tip is shown in a custom layout that is called from a custom report. 

/*   Call the routine
/:   PERFORM FETCH_TABLE_DATA  IN PROGRAM Z_SUBROUTINE_POOL
/:   USING &INVAR1&
/:   CHANGING &OUTVAR1&
/:   ENDPERFORM
/*   Now call the standard text
/:   INCLUDE Z_TABLE_DATA OBJECT TEXT ID ST LANGUAGE EN 

 

Step5. Test the SAP script form 

Activate the SAP script debugger

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image