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

Update existing record while inserting new record

Former Member
0 Likes
2,492

Hi All,

I am trying to build a transaction for the users to update an Z table. I am trying to build a logic for modifying a record in the table through a table control scree. When user modifies the record and clicks on the save button. This is what i want the program to do.

1) Update the old record with DEL_IND field set to 'X' and change date as SY-DATUM.

2) The modified record should actually be inserted into the table.

How to update and insert both at the same time ? . Any pointers will be appreciated.

Regards,

Satish M

1 ACCEPTED SOLUTION
Read only

surajarafath
Contributor
0 Likes
1,680

Use Two internal tables one for update and another one for Modify..

Then do

LOOP AT ITAB1 INTO WA1.
..
..
WA1-DEL_IND = 'X'.
WA1-CHANGED_DATE = SY-DATUM.
ENDLOOP.

UPDATE ZXXX FROM ITAB1
..
,,
MODIFY ZXXX FROM ITAB2

5 REPLIES 5
Read only

surajarafath
Contributor
0 Likes
1,681

Use Two internal tables one for update and another one for Modify..

Then do

LOOP AT ITAB1 INTO WA1.
..
..
WA1-DEL_IND = 'X'.
WA1-CHANGED_DATE = SY-DATUM.
ENDLOOP.

UPDATE ZXXX FROM ITAB1
..
,,
MODIFY ZXXX FROM ITAB2

Read only

0 Likes
1,680

i think UPDATE statement is enough to do this task..because when we are using UPDATE statement ,it can be modifies the record if it is exit already.otherwise it can be inserted into Ztable as new record..UPDATE statement can performing two actions..

LOOP AT ITAB INTO WA.

.......

WA-DEL_IND = 'X'.

WA-CHANGED_DATE = SY-DATUM.

APPEND WA TO ITAB.

CLEAR WA.

ENDLOOP.

UPDATE ZTABLE FROM ITAB SET set_expression [WHERE sql_cond] .

Read only

Former Member
0 Likes
1,680

Hi,

loop at itab.

read the table with the key.

if sy-subrc = 0.

del_ind = 'X'.

modify itab.

else.

insert dbtab accepting dupliacate keys.

endif.

endloop.

Read only

Former Member
0 Likes
1,680

Hi,

Using Modify Statement you can do both in sametime.(i.e. Modify statement update(modify) the existing record and if its not available it will insert the new one. Also the sy-subrc value always equals to '0' for modify statement)

you can use as follows:

if sy-subrc eq 0.

loop at itab into wa.

DEL_IND = 'X'.

wa-date = sy-datum.

Modify dbtab from wa.

endloop.

endif.

Thanks,

Renuka.

Read only

0 Likes
1,680

Hi All,

Update statement only can do both tasks...not modify statement...Because Modify statement can modifing the existing records..but with UPDATE statement we can modifing the existing record if record is exist in Ztable .. otherwise inserted the record as a new record......Let it try once....