Tuesday, September 20, 2011

ABAP Memory - EXPORT / IMPORT Statement

Pass internal table from one Program to another using ABAP memory.

The memory area of each session (SAP GUI window) contains an area called ABAP memory. An internal session memory contains the ABAP program and its associated data.

EXPORT statement saves data to ABAP memory
IMPORT statement retrieves data from ABAP memory

ABAP memory is used basically when we need to transfer variable or internal table from one from program to another within a session.

The use of ABAP memory is demonstrated below:

In following example, ZPROG1 report is saving internal table 'it-vbak' to memory id 'MEM1' and calling ZPROG2 which in turn is retrieving 'it_vbak' from memory id and displaying the document number (VBELN)

*&---------------------------------------------------------------------*
*& Report ZPROG1
*&---------------------------------------------------------------------*
REPORT zprog1.

TABLES: vbak.

DATA:it_vbak TYPE TABLE OF vbak.

SELECT *
  FROM vbak
    INTO TABLE it_vbak
       UP TO 2 ROWS.

EXPORT it_vbak TO MEMORY ID 'MEM1'.

SUBMIT zprog2.


*&---------------------------------------------------------------------*
*& Report ZPROG2
*&---------------------------------------------------------------------*
REPORT zprog2.

DATA: it_vbak TYPE TABLE OF vbak,
            wa_vbak type vbak.

IMPORT IT_vbak FROM MEMORY ID 'MEM1'.

READ TABLE it_vbak INTO wa_vbak INDEX 1.
WRITE: wa_vbak-vbeln.

CLEAR: wa_vbak.
READ TABLE it_vbak INTO wa_vbak INDEX 2.
WRITE / wa_vbak-vbeln.

FREE MEMORY ID 'MEM1'.

No comments:

Post a Comment