Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Sujit K.Pal
Submitted: 3 Nov,2008
Related Links:  See Below

Objective

To pass data from one program to another program we can use ABAP Memory or SAP memory. When we are using ABAP memory we can go for EXPORT <Field> TO MEMORY ID <ID>option in Called program and IMPORT <Field> FROM MEMORY ID <ID>in calling program to share the data.

When we are using SAP memory we can go for SET PARAMETER ID <ID> FIELD <FIELD> in called Program and GET PARAMETER ID <ID> FIELD <Field>.

Again when we are calling SAP standard program and want to use the data responsible for output of the standard program then we neither can nor use SET PARAMETER ID or EXPORT TO MEMORY ID if there is no proper enhancement or exit is available. And we have to do changes in the SAP standard program if the suitable Exit or Enhancement spot is available.

In this case rather going for changes SAP standard program we can use List object of the standard program.

For that we have to SUBMIT the standard program and export list to memory and return to the calling program.

So Calling program can access the list object for its use.

Called Program

Below is the code snippet of the called program. This program display flight details for carrier id range.

TABLES:sflight.
 
SELECT-OPTIONS: s_carrid FOR sflight-carrid obligatory.
DATA:
     t_sflight LIKE STANDARD TABLE
         OF sflight.
 
START-OF-SELECTION.
 
 
*Fetching Data from Sflight table
  SELECT *
    FROM sflight
    INTO TABLE t_sflight
   WHERE carrid IN s_carrid.
 
*Displaying the list
 CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM             = sy-repid
    I_STRUCTURE_NAME               = 'SFLIGHT'
   TABLES
     t_outtab                       = t_sflight
  EXCEPTIONS
    PROGRAM_ERROR                  = 1.

List output

This screen shot is the output of the called program.


Note : This output is the flight details (Table SFLIGHT) of the carrier code AA.

Calling program

Now we can use this list object of called program in our calling program and do further process like population of the data based on the submit programs data.

REPORT y_test_submit.
 
TABLES:sflight.
 
SELECT-OPTIONS: s_carrid FOR sflight-carrid OBLIGATORY.
 
DATA: t_tab1 TYPE TABLE OF abaplist.
 
DATA: BEGIN OF t_tab2 OCCURS 0,
        w_text (255) TYPE c,
       END OF t_tab2.
 
DATA: w_index LIKE sy-tabix VALUE 4,
       w_lines LIKE sy-tabix,
       w_dummy TYPE c,
       w_date(10) TYPE c.
 
DATA: t_sflight LIKE STANDARD TABLE
         OF sflight,
     wa_sflight LIKE LINE OF t_sflight.
 
DATA:t_sbook LIKE STANDARD TABLE
             OF sbook.
 
START-OF-SELECTION.
 
  SUBMIT y_test_report
              WITH s_carrid IN s_carrid
              EXPORTING LIST TO MEMORY
              AND RETURN.
 
  IF sy-subrc = 0.
 
*Getting the list from memory
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = t_tab1
      EXCEPTIONS
        not_found  = 1.
 
*Converting to ASCII
    CALL FUNCTION 'LIST_TO_ASCI'
      TABLES
        listasci           = t_tab2
        listobject         = t_tab1
      EXCEPTIONS
        empty_list         = 1
        list_index_invalid = 2.
 
    IF sy-subrc <> 0.
      WRITE: / 'LIST_TO_ASCI error'.
    ENDIF.
 
    DESCRIBE TABLE t_tab2 LINES w_lines.
    WHILE w_index LE w_lines.
      READ TABLE t_tab2 INDEX w_index.
      IF sy-subrc = 0.
        SPLIT t_tab2-w_text AT '|' INTO w_dummy
                                        wa_sflight-carrid
                                        wa_sflight-connid
                                        w_date.
 
 CONCATENATE w_date+6(4) w_date+3(2) w_date+0(3) INTO wa_sflight-fldate.
        APPEND wa_sflight TO t_sflight.
      ENDIF.
      CLEAR sflight.
      w_index = w_index + 1.
    ENDWHILE.
 
 
    IF t_sflight IS NOT INITIAL.
      SORT t_sflight BY carrid fldate.
      SELECT *
        FROM sbook INTO TABLE t_sbook
         FOR ALL ENTRIES IN t_sflight
       WHERE carrid = t_sflight-carrid
         AND fldate = t_sflight-fldate.
    ENDIF.
 
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
        i_callback_program = sy-repid
        i_structure_name   = 'SBOOK'
      TABLES
        t_outtab           = t_sbook
      EXCEPTIONS
        program error      = 1.
  ENDIF.

Analysis of process

In the above program we are submitting the Y_TEST_REPORT with Carrier Id and Exporting the list of the flight details into memory. Through Function module LIST_FROM_MEMORY list is being stored into list object internal table. By Function module LIST_TO_ASCII list object is converted to ASCII file. Now here carrier Id and flight date is populated into internal table by Reading the ASCII table by index. Using this internal table we are getting booking details from table SBOOK and displayed in ALV list.

Final output


Note: Output of booking details (Table SBOOK) using list object of Program YH_TEST_REPORT2

Information

When we are populating the data from ASCII file to final internal table if there is any date field, currency field or quantity field then extra manipulation should be done for type compatibility and convertibility. Here I have hard coded the index when reading the ASCII internal table but index is dependent on the list object internal table whether table header is there or not. So for that we have to first check the contents of the AASCII internal table and set the index accordingly.

Related Links

http://help.sap.com/saphelp_nw04/helpdata/EN/9f/dba51a35c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/helpdata/EN/9f/dba50d35c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/helpdata/EN/9f/dba50035c111d1829f0000e829fbfe/content.htm