‎2009 Feb 03 6:52 PM
I'm using an internal table in a shared memory area. Depending on the existance of rows i would like to modify these rows or appending new rows.
So i need read and write access.
I tried to use attach_for_write( ) but after that i cannot read the table, sy-subrc is always 4.
So i tried to read the table with attach_for_read( ) first. I can read it, and the result is now sy-subrc = 0.
But after attaching the table via attach_for_write i'm unable to modify the table, how can i do this?
‎2009 Feb 03 7:07 PM
Use method ATTACH_FOR_UPDATE to modify the data in the shared memory.
First Read it using the ATTACH_FOR_READ.
Now get the object by ATTACH_FOR_UPDATE
Call your Update method
Commit work by
my_handle->detach_commit( ).
Regards,
Naimesh Patel
‎2009 Feb 03 6:57 PM
assign a field symbol to ur internal table and make changes to ur field symbol. the changes shud get reflected in ur internal table also.
‎2009 Feb 03 7:07 PM
Use method ATTACH_FOR_UPDATE to modify the data in the shared memory.
First Read it using the ATTACH_FOR_READ.
Now get the object by ATTACH_FOR_UPDATE
Call your Update method
Commit work by
my_handle->detach_commit( ).
Regards,
Naimesh Patel
‎2009 Feb 03 7:26 PM
The problem is the modify statement itself, using modify the report abends because the modify statement does not have a binding to that table anymore.
fieldsymbols do not work, they are modifying the table directly which will not work if i'm in the read phase.
‎2009 Feb 03 7:34 PM
Do you try to modify after the DETACH?
I am able to modify my shared memory data using this code:
TRY.
my_handle = ztest_np=>attach_for_update( ).
CREATE OBJECT my_data AREA HANDLE my_handle.
my_handle->set_root( my_data ).
*.. data modification logic begin
CLEAR: my_data->t_data.
SELECT vbeln
FROM vbap
INTO CORRESPONDING FIELDS OF TABLE my_data->t_data
UP TO 25 ROWS.
*.. data modification logic end
my_handle->detach_commit( ).
CATCH cx_shm_attach_error.
...
ENDTRY.
Regards,
Naimesh Patel
‎2009 Feb 03 7:45 PM
To simplify, just use ROOT attribute :
TRY.
my_handle = ztest_np=>attach_for_update( ).
*.. data modification logic begin
CLEAR: my_handle->root->t_data.
SELECT vbeln
FROM vbap
INTO CORRESPONDING FIELDS OF TABLE my_handle->root->t_data.
UP TO 25 ROWS.
*.. data modification logic end
my_handle->detach_commit( ).
CATCH cx_shm_attach_error.
...
ENDTRY.
‎2009 Feb 03 8:13 PM
myshmhandle = zca_shm_repstat_area=>attach_for_update( ).
CREATE OBJECT myroot AREA HANDLE myshmhandle.
read table myshmhandle->root->it_stat with key mandt = sy-mandt report = sy-repid
ASSIGNING <p>.
if sy-subrc = 0.
<p>-freq = wa_stat-freq + 1.
<p>-ldate = sy-datum.
<p>-ltime = sy-uzeit.
<p>-userid = sy-uname.
ins = abap_false.
else.
wa_stat-mandt = sy-mandt.
wa_stat-report = sy-repid.
wa_stat-freq = 1.
wa_stat-ldate = sy-datum.
wa_stat-ltime = sy-uzeit.
wa_stat-userid = sy-uname.
ins = abap_true.
append wa_stat to myroot->it_stat.
endif.
myshmhandle->set_root( myroot ).
myshmhandle->detach_commit( ).
Running the first time, everyting is ok. Running the second time the read will give back sy-subrc = 0 and <p> contains the correct values. after running to the end the table has no rows at all and is inconsitent I cant see what i'm doing wrong.
‎2009 Feb 03 10:01 PM
I think this should work with these corrections :
myshmhandle = zca_shm_repstat_area=>attach_for_update( ).
* CREATE OBJECT myroot AREA HANDLE myshmhandle. "DELETE
read table myshmhandle->root->it_stat with key mandt = sy-mandt report = sy-repid
ASSIGNING <p>.
if sy-subrc = 0.
<p>-freq = wa_stat-freq + 1.
<p>-ldate = sy-datum.
<p>-ltime = sy-uzeit.
<p>-userid = sy-uname.
ins = abap_false.
else.
wa_stat-mandt = sy-mandt.
wa_stat-report = sy-repid.
wa_stat-freq = 1.
wa_stat-ldate = sy-datum.
wa_stat-ltime = sy-uzeit.
wa_stat-userid = sy-uname.
ins = abap_true.
* append wa_stat to myroot->it_stat. "DELETE
append wa_stat to myshmhandle->root->it_stat. "ADD
endif.
* myshmhandle->set_root( myroot ). "DELETE
myshmhandle->detach_commit( ).