2008 Jul 15 3:57 AM
hi,
i need to add record to sap standard table.
if i use insert then repeated key field not allowed me to do so.
should i do like this.
if record found use update whereas if record not found use insert.
loop
UPDATE ... SET ...
WHERE ....
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
insert ....
COMMIT WORK
ENDIF.
endloop.
thanks
2008 Jul 15 4:28 AM
if the strucuture of the internal table which you are looping is same as the database table, with out any loop you can directly put..
modify <DBtable> from <itab>."DBtable and Itab need to be of same structure
if the strucuture of the internal table which you are looping is same as the database table, with out any loop you can directly put..
modify <DBtable> from <itab>."DBtable and Itab need to be of same structure
2008 Jul 15 4:02 AM
hey,
use modify stmt.... it will modify the record if it existing otherwise will add a new record ........
thanks
Ajantha R
2008 Jul 15 4:28 AM
if the strucuture of the internal table which you are looping is same as the database table, with out any loop you can directly put..
modify <DBtable> from <itab>."DBtable and Itab need to be of same structure
2008 Jul 15 4:41 AM
hi,
if i use modify from table like this
modify <DBtable> from <itab>."DBtable and Itab need to be of same structure
do i still need to add in commit work?
or something like this?
if sy-subrc = 0
commit work.
else
rollback work.
endif.
thanks
2008 Jul 15 5:25 AM
Yes you would still need to add the commit work statement.
cheers,
Sushil Joshi
2008 Jul 15 5:27 AM
If b4 the program ends if u need to read the value u updated then its necessary to write commit work ortherwise once the program ends all the cahnges are committed to the database
but its preferable to write commit
2008 Jul 15 5:32 AM
Hi,
Its always better to commit work to be on safer side.
Its always better to use modify if we need to add a record or update a reacord.
MODIFY dbtable FROM TABLE itab1.
Or
MODIFY dbtable FROM wa_itab1The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.
So we can have like this :
loop at itab1 into wa_itab1
MODIFY dbtable FROM wa_itab1
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
endloop.Or.
MODIFY dbtable FROM TABLE itab1.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.Hope this helps you.
plz reward if useful.
thanks,
dhanashri.
Edited by: Dhanashri Pawar on Jul 15, 2008 6:34 AM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |