天天看点

SAP ABAP实用技巧介绍系列之 ABAP内存管理学习

使用如下report 测试ABAP memory:

REPORT ztest_export.

DATA: lv_memory TYPE char10 VALUE 'memory_id',

     lv_v1     TYPE string VALUE 'test1',

     lv_v2     TYPE string VALUE 'test2',

     ls_v3     TYPE comm_product,

     lv_task   TYPE char8 VALUE '001'.

ls_v3 = VALUE #( product_id = 'MCF-0001' product_type = '02' ).

EXPORT value1 = lv_v1 value2 = lv_v2 value3 = ls_v3 TO MEMORY ID lv_memory.

WRITE: / 'test by normal function call...' COLOR COL_NEGATIVE.

CALL FUNCTION 'ZIMPORT_TEST'.

WRITE: / 'test by starting new task...' COLOR COL_GROUP.

CALL FUNCTION 'ZIMPORT_TEST' STARTING NEW TASK lv_task PERFORMING import ON END OF TASK.

WRITE: / 'Call via DESTINATION NONE...' COLOR COL_KEY.

CALL FUNCTION 'ZIMPORT_TEST' DESTINATION 'NONE'.

FORM import USING id TYPE clike.

 WRITE: / 'Executed in PERFORM on end of task...' COLOR COL_KEY.

 IMPORT value1 = lv_v1 value2 = lv_v2 value3 = ls_v3

  FROM MEMORY ID lv_memory.

 WRITE: / 'Value1: ' , lv_v1 COLOR COL_NEGATIVE,

        / 'Value2: ' , lv_v2 COLOR COL_TOTAL,

        / 'Product ID: ', ls_v3-product_id COLOR COL_GROUP,

        'Product Type: ', ls_v3-product_type COLOR COL_POSITIVE.

ENDFORM.根据SAP help里的定义,ABAP memory只能用于在同一个external session下的不同internal session之间共享数据。因此上述report的三种测试scenario,只有第一种normal call的方式能够成功import到memory里的数据:

继续阅读