2010 Mar 03 11:57 PM
Hi,
I have implemented change docs for an own application. I use the functional moduls (not only the generated one) because there is a little bit extra stuff around it.
Anyhow I face a problem with I have not yet identified.
My question: can i use "modify" statement to update into a table with change document or do I need to use update and insert separatly? I use "modify" and asked myself whether this is the problem.
I just hope that someone of you has the answer out of the box so I dont have to figure that out by my own...
Thanks!
2010 Mar 04 2:31 AM
Hi Eddie,
Here we go.
The differences between UPDATE and MODIFY
In case of UPDATE
In case of MODIFY
<li>
<li>If there is no row in the database with the same content of the primary key for a row in the internal table, or if the change would lead to a double entry in a unique secondary key, the respective row is not changed and sy-subrc is set to 4.
UPDATE sflight FROM TABLE sflight_tab.
Thanks
Venkat.O
<li>
<li>If there is no row in the database with the same content of the primary key for a row in the internal table, record is created and subrc is set to 0. or if the change would lead to a double entry in a unique secondary key, the respective row is changed and sy-subrc is set to 0.
MODIFY t100 FROM TABLE message_wa.
2010 Mar 04 3:55 AM
Hello,
UPDATE works only when a data which needs to be changed exists in a table. If you try to update a record which is non existant then sy-subrc is returned as 4. Nothing happens in this case.
MODIFY works as a combination of UPDATE and INSERT. If a record exists then it is updated with new values but if it does not exist then a new records is created and added to the table.
Hope this clarifies your doubt regarding in issue that you are facing.
Regards,
Sachin
2010 Mar 04 4:30 AM
Hello Eddie,
The differance between insert , update and modify is as follows.
INSERT - Inserts a new record. INSERT expects that a record with the required key does NOT exist in the table. Therefore, if a record with the same key already exists, a runtime error occurs.
UPDATE -Update an existing record. UPDATE expects that a record with required key exists in the table. If a record with the required key does not exist, it issue an error (sy-subrc is 4).
MODIFY - Acts like a combination of INSERT and UPDATE. If a record with the specified key does not exist, it adds it to the table. If a record with the specified key does exist, it modifies it. So MODIFY actually acts like "Insert or change record".
To summarize:
INSERT - Adds a new record to the table. If the row (key) exists, issues an error.
UPDATE - Updates an existing record to the table. If the row (key) does not exist, issues an error.
MODIFY - If the key exists, modifies the record. If the key does not exist, adds the record to the table.
Regards,
Soundarya.
2010 Mar 04 10:38 AM
Thank you all for your answers.
Maybe I was not so clear with what my question is:
I know that modify acts as an insert or an update. But can I use this statement in order to create a change record?
I only saw examples with update and insert and the change indicator only has insert of update.
My application uses modify and does not work. But I have quite a bit development around the change documents
and just wanted to get feedback whether my modify statements are the problem.
But i think I will just write a small program and test it in a small standard environment.
Thanks for you help!
2014 Mar 18 7:18 AM
Hi ,
i think this is helpful for u...
TYPES: BEGIN OF ty_str ,
r1(10) TYPE c,
r2(10) TYPE c,
END OF ty_str.
DATA: it_str TYPE TABLE OF ty_str,
wa_str LIKE LINE OF it_str.
data: lv_r1 TYPE string,
lv_r2 TYPE string.
lv_r1 = 10.
lv_r2 = 20.
wa_str-r1 = lv_r1.
wa_str-r2 = lv_r2.
APPEND wa_str to it_str.
CLEAR wa_str.
wa_str-r1 = '100'.
wa_str-r2 = '200'.
APPEND wa_str to it_str.
CLEAR wa_str.
wa_str-r1 = '55'.
wa_str-r2 = '66'.
INSERT wa_str INTO it_str INDEX 2.
CLEAR wa_str.
wa_str-r1 = '155'.
wa_str-r2 = '166'.
APPEND wa_str to it_str.
CLEAR wa_str.
DELETE it_str INDEX 4.
*MODIFY TABLE it_str FROM wa_str .
LOOP AT it_str INTO wa_str.
read TABLE it_str INTO wa_str INDEX 2.
if sy-subrc = 0.
wa_str-r1 = 'roopa'.
MODIFY it_str FROM wa_str INDEX 1 .
endif.
ENDLOOP.
LOOP AT it_str INTO wa_str.
WRITE:/ wa_str-r1, wa_str-r2.
ENDLOOP.
Thanks,
roopa.k