Small SAP Talk. Saving and Transferring Parameters Between ABAP Programs

Small SAP Talk. Saving and Transferring Parameters Between ABAP Programs

There are often situations where it’s necessary to pass certain values from one ABAP development to another. For example, you might have two ABAP programs: in one of them, you read or prepare some data that needs to be passed to another program, where an important analysis or process will occur.

It’s worth noting that the task of quickly saving a set of parameters is relevant not only for two separate ABAP programs, but also within the lifecycle of a single program — you may need to save data temporarily for later extraction and analysis. So, what are the available options?

Option 1: IMPORT/EXPORT TO MEMORY

See: Using the Shared Memory

Here’s an example of an ABAP program that writes a variable’s value to memory:

REPORT zprogram1.
 
DATA: lv_memory_id     TYPE char10 VALUE \'ZMA_ZPROGRAM1\',
      lv_random_string TYPE string.
 
CALL FUNCTION 'GENERAL_GET_RANDOM_STRING'
  EXPORTING
    number_chars  = 10
  IMPORTING
    random_string = lv_random_string.
 
 
EXPORT  lv_random_string FROM lv_random_string TO MEMORY ID lv_memory_id.
 
SUBMIT zprogram2.

In the second program, we read the value from memory and display it on the screen:

REPORT zprogram2.
 
DATA: lv_random_string TYPE string,
      lv_memory_id     TYPE char10 VALUE \'ZMA_ZPROGRAM1\'.
 
 
IMPORT lv_random_string TO lv_random_string FROM MEMORY ID lv_memory_id.
 
FREE MEMORY ID lv_memory_id.
 
WRITE:/ \'Value from memory: \' ,  lv_random_string.    

Let’s see what happens.

0:00
/0:49

This option is fairly common, but it has some side effects that are well known among programmers.

Option 2: IMPORT/EXPORT TO DATABASE indx(as)

This differs from Option #1 in that the value is written to the cluster table INDX.

See: INDX-like
See: EXPORT - Table Structure
See: EXPORT - medium

Let’s rewrite Program #1 like this:

REPORT zprogram1.
 
DATA: lv_memory_id TYPE char10 VALUE 'ZWA_XXX',
lv_random_string TYPE string.
 
CALL FUNCTION 'GENERAL_GET_RANDOM_STRING'
EXPORTING
number_chars = 10
IMPORTING
random_string = lv_random_string.
 
 
EXPORT lv_random_string = lv_random_string
TO DATABASE indx(ZA)
CLIENT sy-mandt ID lv_memory_id.
 
SUBMIT zprogram2.

And slightly modify Program #2:

REPORT zprogram2.
 
DATA: lv_random_string TYPE string,
lv_memory_id TYPE char10 VALUE 'ZWA_XXX'.
 
IMPORT lv_random_string TO lv_random_string
FROM DATABASE indx(za)
ID lv_memory_id.
IF sy-subrc EQ 0.
WRITE:/ 'Value from INDX table is : ' , lv_random_string.
ENDIF.

Let’s verify the result.

0:00
/0:28

For more information about the "Small SAP Talk" series, refer to the following note:​

See: Small SAP Talk