ABAP Memory ID : How to use EXPORT or IMPORT data

ABAP Shared Memory

How to use EXPORT or IMPORT data to and from ABAP Memory ID.

This is a sample ABAP Code to let you Transfer ABAP internal Table from one report to another using Memory ID.

Main memory area that can be accessed by all work processes in an instance.

The term shared memory is also used to mean the main memory area shared by the RDBMS processes.

Export Internal Table Data To ABAP MEMORY ID

Use the Statement to export Data to ABAP Memory ID

EXPORT {ABAP_VAR} TO MEMORY_ID {memory_id}.

The following ABAP Sample will give an example how to use the ABAP Memory to export an ABAP Internal Table:

" Generate the ABAP Internal Table Data "
REPORT  ZREPORT1.
DATA: LT_TAB TYPE TABLE OF ZTAB. 

SELECT *  FROM ZTAB INTO TABLE LT_TAB.

" Export Internal Tab to Memory 
EXPORT LT_TAB TO MEMORY ID 'ITAB'.

Import Internal Table Data From ABAP MEMORY ID

ABAP Memory ID

The Key Statement to import Data from ABA Memory is:

IMPORT {ABAP_VAR} FROM MEMORY ID {Memory_id}.

The following ABAP code will help retrieve a whole Internal Table from ABAP Memory id:

" Second Program where the export Internal Table to be used
REPORT ZREPORT. 
DATA: LT_TAB TYPE STANDARD TABLE OF ZTAB. 
FIELD-SYMBOLS:  LIKE LINE OF LT_TAB. 

START-OF-SELECTION. 
" Import SAP ABAP Internal Table Data from Memory 
IMPORT LT_TAB TO LT_TAB FROM MEMORY ID 'ITAB'. 
" Display Internal Table Data (sample) 
LOOP AT LT_TAB ASSIGNING . 
   WRITE:/5(4) SY-TABIX, CURR_TB-WAERS, CURR_TB-LTEXT. 
ENDLOOP. 

Source: Sample ABAP Program to EXPORT or IMPORT internal table TO or FROM ABAP Memory

Read also How to Create Shared Memory Object Class in ABAP

ABAP MEMORY AND SAP MEMORY

SAP memory is a memory area to which all main sessions within a Sapgui have access.

You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another. Application programs that use SAP memory must do so using SPA/GPA parameters (also known as SET/GET parameters).

These parameters can be set either for a particular user or for a particular program using the SET PARAMETER statement. Other ABAP programs can then retrieve the set parameters using the GET PARAMETER statement.

The most frequent use of SPA/GPA parameters is to fill input fields on screens

ABAP’s memory is a memory area that all ABAP programs within the same internal session can access using the EXPORT and IMPORT statements. Data within this area remains intact during a whole sequence of program calls.

To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made.

The internal session of the called program then replaces that of the calling program. The program called can then read from the ABAP memory.

If control is then returned to the program which made the initial call, the same process operates in reverse.

External session: – when the user logs on to R/3 system, the system creates a new terminal session called external session. E.g. System Session.

Internal session: – created by calling a transaction (with CALL TRANSACTION), a dialog module (with CALL DIALOG) or a report (with SUBMIT or RETURN).

In general each user can open up to six R/3 windows in a single SAPgui session. Each of these windows corresponds to a session on the application server with its own area of shared memory.

The first application program that you start in a session opens an internal session within the main session.

The internal session has a memory area that contains the ABAP program and its associated data.

When the program calls external routines (methods, subroutines or function modules) their main program and working data also loaded into the memory area of the internal session.

Only one internal session is ever active. If the active application program calls a further application program, the system opens another internal session.

Here, there are two possible cases:

If the second program does not return control to the calling program when it has finished running, the called program replaces the calling program in the internal session.

The contents of the memory of the calling program are deleted. If the second program does return control to the calling program when it has finished running, the session of the called program is not deleted.

Instead, it becomes inactive, and its memory contents are placed on a stack.

The memory area of each session contains an area called ABAP memory. ABAP’s memory is available to all internal sessions.

ABAP programs can use the EXPORT and IMPORT statements to access it. Data within this area remains intact during a whole sequence of program calls.

To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made. The internal session of the called program then replaces that of the calling program.

The program called can then read from the ABAP memory. If control is then returned to the program which made the initial call, the same process operates in reverse.

All ABAP programs can also access the SAP memory. This is a memory area to which all sessions within a SAPgui have access. You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another.

Application programs that use SAP memory must do so using SPA/GPA parameters (also known as SET/GET parameters). These parameters are often used to preassign values to input fields.

You can set them individually for users, or globally according to the flow of an application program. SAP memory is the only connection between the different sessions within a SAPgui.

Read more on Comparison between ABAP Memory and SAP Memory.