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.

Related Articles

ABAP COLLECT statement syntax to add up all numeric internal table values within SAP
ABAP DELETE statement keyword to delete data from SAP internal and database tables
ABAP DESCRIBE statement keyword to get information about tables and fields
PERFORM TABLES command passing internal table as parameter
ABAP read command to read line of internal table in SAP
ABAP UPDATE command to modify database field values
AUTHORITY-CHECK abap Statement / command
ABAP delete command in SAP
ABAP MODIFY statement to update SAP data within database and internal tables
ABAP WRITE statement command with in SAP to display data report to users
SAP ABAP Statement syntax including basic implementation code
Concatenate ABAP statement syntax for concatenating data objects, sting values or rows of an SAP internal table
IF, CHECK & WHEN ABAP commends example source code and information
Call Function module IN BACKGROUND TASK - Execute abap code in seperate background process
Function module IN UPDATE TASK statement - Execute abap code in seperate unit of work
ABAP STRLEN command to get the value length of a SAP field
SAP ABAP SELECT command and its different uses
SELECT..ENDSELECT command
ABAP FOR ALL ENTRIES SELECT statement addition in SAP data retrieval
ABAP SELECT inner join statement to select from two tables at the same time
SELECT directly into an internal table
SELECT directly into an internal table when field order is different
Function module STARTING NEW TASK statement - Execute abap code in seperate work process