Logic to delete records from DB table
Hello,
We have a requirement to delete data from a DB table. My question is what is the best way to code this requirement?
We could run into situation where the records got deleted and all the sudden there was an ABAP runtime error somewhere later in the execution, and the records had already been delete? How would you recover the records back to the DB tables??
Any input or ideas are greatly appreciated.
Thank you very much
You don't have to. This is done automatically in SAP. If your program abends after your delete but before your COMMIT WORK or before the end of the program if you don't have a COMMIT WORK in your program, the records will not be deleted.
Would this concept work with the insert statement to insert records from an internal table??
Say we inserted records into a DB table from an internal table and after this there was an ABAP runtime error. Definitely we wouldn't want the records inserted earlier to be in the Db table. Would SAP take care of this automatically?? Or do we have to use the rollback statement?
Thanks
please, please tell me that you're not updating an SAP table this way....should always ONLY use the appropriate SAP transaction code, via one of the update technologies, such as BDC, CT, etc. Anything else is likely to be catastrophic. I hope there are nightly backups of the database.
If a custom table, like "Z_whatever", I would think (without looking) that you need to manage the commit work and rollback processes.
Boy... Do I sound that DUMB
No.. I am not updating the SAP tables.
Tell me then MR. indy_abapper. When should I use COMMIT WORK and ROLLBACK and how often?? I can read the SAP Help but I would prefer to hear it from you since you sound like such an EXPERT.
this is the way we do it for a customer table which contains say 10,000 entries and it never gave us any problem for the last 3 years.
data: del_tab like ztable occurs 0 with header line,
del_lines type i.
clear: del_tab, ztable.
refresh: del_tab.
select * from ztable into table del_tab.
if sy-subrc = 0.
delete ztable from table del_tab.
move sy-dbcnt to del_lines.
endif.
write: 'No of deleted lines from Ztable = ', del_lines.
cheers,
syd.