Skip to Content
0
Nov 13, 2019 at 03:17 PM

Sharing Runtime objects to shared memory using SHMA

317 Views Last edit Nov 13, 2019 at 03:23 PM 3 rev

I have been working on shared memory objects, Used it many times to share flat structures.

This time I wanted to share objects(runtime) of a z-class using shared memory.

getting "The exception 'CX_SHM_EXTERNAL_REFERENCE' was raised, but it was not caught anywhere along" when detaching after "attach_for_write( ).".

Below is what I am trying to do.

DATA lr_handle TYPE REF TO ZCL_TEST_SHARED_MEM_AREA. " Area Class

DATA lr_root TYPE REF TO ZCL_TEST_SHARED_MEM_ROOT. " Root attribute of handle class. SHM: Model of a Data Clas
******************************************************
* First Try to Read
data excp type ref to cx_shm_no_active_version.
data lf_readerror type c1.

try.
 lr_handle = ZCL_TEST_SHARED_MEM_AREA=>attach_for_read( ).
 lr_handle->root->get_object( IMPORTING e_grid = gv_docking ).
 lr_handle->detach( ).
catch cx_shm_no_active_version into excp.
 lf_readerror = 'X'.
endtry.
******************************************************
IF lf_readerror = 'X'.
 lr_handle = ZCL_TEST_SHARED_MEM_AREA=>attach_for_write( ).
ELSE.
 lr_handle = ZCL_TEST_SHARED_MEM_AREA=>attach_for_update( ).
ENDIF.

CREATE OBJECT lr_root AREA HANDLE lr_handle.
lr_handle->set_root( lr_root ).
CREATE OBJECT gv_docking.     " this may be any object of my intrest
lr_root->set_object( EXPORTING p_grid = gv_docking ). " a mehtod in root class to save my object to SM
lr_handle->detach_commit( ).

Is it even possible to share class objects using shared memory.!