sapdev logo background
sapdev logo sapdev logo
Comments

ABAP EXPORT data TO MEMORY ID and import it back again




The import and export data to memory ID command allows you to pass data between different sap programs, reports, bsp's, web dynpros etc. The below is the ABAP code for 2 reports, one gets the data and stores in memory and the other retrieves this data from memory and displays it to the user.

In this example program 1 calls program 2 which selects the data and stores it in memory a ID based on the user name (sy-uname). Processing then returns to program 1 where it imports the data from memory into a local itab and displays the data to the user.

Program 1 - Imports data from memory
*&---------------------------------------------------------------------*
*& Report  ZPROG1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT  ZPROG1.

data: it_lfa1prog1 type STANDARD TABLE OF lfa1,
      wa_lfa1      type lfa1.


************************************************************************
START-OF-SELECTION.

*Clear memory id
FREE MEMORY ID sy-uname.

*Execute Program 2
submit ZPROG2 and return.

************************************************************************
END-of-SELECTION.
*Import data from memory. Although the import statement must refrerence
*the same variable name the data was export with, the the local
*itab(it_lfa1prog2) where data is being imported too can have a
*different name (i.e. it_lfa1prog1).
import it_lfa1prog2 to it_lfa1prog1 from memory id sy-uname.

*Just for clarification if the the following lines of code were
*implemented it would pass a syntax check but would not retrieve any
*data as the importing field name is different to that exported.
***import it_data to it_lfa1prog1 from memory id sy-uname.
***import it_lfa1 to it_lfa1prog1 from memory id sy-uname.


*Display data
LOOP AT it_lfa1prog1 INTO WA_LFA1.
  write:/ WA_LFA1-LIFNR.
ENDLOOP.


Program 2 - Exports data to memory
&---------------------------------------------------------------------*
*& Report  ZPROG2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT  ZPROG2.

data: it_lfa1prog2 type STANDARD TABLE OF lfa1.

************************************************************************
START-OF-SELECTION.

* Select data
  select *
    UP TO 10 rows
    from lfa1
    into table it_lfa1prog2.

*Export data to memory using sy-uname as memory ID. When importing this
*data elsewhere you need to reference this same variable name. 
  EXPORT it_lfa1prog2 to MEMORY ID sy-uname.






comments powered by Disqus