Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sharing Runtime objects to shared memory using SHMA

sriharsha_parayatham
Participant
0 Likes
1,455

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.!

2 REPLIES 2
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,138

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.