Pass BEx Variable values from a Query to other applications using EXPORT TO MEMORY

A simple way to communicate the values of the BEx variables for a BEx Query execution to some other application (another query, an ABAP program…), is to store these values in memory via the command EXPORT to MEMORY

here is a rough description of the development actions to perform to achieve this:

1) Create a user parameter ID in table TPARA => SM30, TPARA, maintain, enter on  empty field, create new… per query whose values you want to export.

2) Add code in ZXRSRU01 for  i_step = 3 for and i_s_rkb1d-compid = <name of the BEx query passing values>.

ex:

if i_step = 3.

case i_s_rkb1d-compid.

when <name of query>.

* <add here code to export parameters>

CALL FUNCTION ‘Z_EXPORT_ZXRSRU01_VALUES’
EXPORTING
i_t_var_range = i_t_var_range
i_parameter_id = ‘MYPARAMETER’.

* ________

endif.

3)  Create the following FM: Z_EXPORT_ZXRSRU01_VALUES. The function does the following:

– a) Generate a unique ID that will be used to identify the variables in the export memory.

– b) This UUID is stored in the user parameter created in step 1 (SET PARAMETER)

-c) Export to memory the whole table i_t_var_range

Example

“1st generate a UUID

DATA: system_uuid TYPE REF TO if_system_uuid,
uuid TYPE sysuuid_c32.

system_uuid = cl_uuid_factory=>create_system_uuid( ).

TRY.

GET  PARAMETER ID ‘ZIP_PS100_JUMP1’ FIELD uuid.
IF uuid IS NOT INITIAL.
DELETE FROM MEMORY ID uuid.
ENDIF.
uuid = system_uuid->create_uuid_c32( ).
” Export to memory
EXPORT p1 = i_t_var_range TO  MEMORY ID uuid.

” Set user related parameter ID to UUID
SET PARAMETER ID ‘ZIP_PS100_JUMP1’ FIELD uuid.

CATCH cx_uuid_error.
ENDTRY.

4) The receiving program should do the following:

DATA:
l_s_range TYPE rsr_s_rangesid,
l_t_var_range TYPE rrs0_t_var_range,
uuid TYPE sysuuid_c32.

FIELD-SYMBOLS:
<s_var_range> TYPE rrs0_s_var_range.

GET PARAMETER ID ‘MYPARAMETER’ FIELD uuid.

IF uuid IS NOT INITIAL.
IMPORT  p1 = l_t_var_range FROM  MEMORY ID uuid.
LOOP AT l_t_var_range ASSIGNING <s_var_range>.
l_s_range-sign = <s_var_range>-sign.
l_s_range-opt = <s_var_range>-opt.
l_s_range-low = <s_var_range>-low.
l_s_range-high = <s_var_range>-high.
APPEND l_s_range TO e_t_range.
ENDLOOP.

ENDIF.

Leave a Reply