‎2019 Nov 13 3:17 PM
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.!
‎2023 Aug 04 10:11 AM
Unfortunately not possible, acc. to:
Shared Objects "cx_shm_external_reference" exception
CX_SHM_EXTERNAL_REFERENCE exc. when passing Class instance to Shared memory
‎2023 Aug 04 12:52 PM
If the class is serializable/IF_SERIALIZABLE_OBJECT (that's very rare), you can serialize it into a String or Xstring and then you can share it.