2009 Jun 22 10:27 AM
Hi ALL,
I need to provide method that update records in the DB ,
in some cases i get values:
1. to create new records in the table. like create new employee
2. record is already exist in the table (part of it) but need to update some fields on it
like if i had employee and i need to update the employee or cell number,adress .
3. recorded is already exist in the table wity the same .
the recorded is that need to update is exactly the same with persistence record
What is the best way to handle such of thing?
with read before update or like:
INSERT gc_db_tab_objects FROM ls_object.
IF sy-subrc <> 0.
UPDATE gc_db_tab_objects FROM ls_objects.
Best Regards
2009 Jun 22 10:29 AM
Hi,
You can use MODIFY statement.
Regards,
Ankur Parab
2009 Jun 22 10:29 AM
2009 Jun 22 11:29 AM
HI Ankur,
Thanks ,
but how will i know if the record is already exist in the table.
I need to know that.
BR
Michael
2009 Jun 22 11:43 AM
Hi,
If you want to know if your record exists in the database, then write a query checking with your key fields to find if it already exists.
MODIFY statement on the database works either ways. If there is no record, then it inserts one, else it appends one.
2009 Jun 22 10:34 AM
Hi,
Please use "MODIFY".
This does both Insert and Update.
When the record is available in DB, then Update is done; Else, Insert record into DB is done.
Rgds,
Ramani N
2009 Jun 22 11:43 AM
2009 Jun 22 12:53 PM
You dont need to find out if the record exists or not before using "MODIFY" statement.
Modify inserts the record if its not already available, else it will update.
In effect, MODIFY = INSERT + UPDATE functionalities.
If you need to know at all before modifying, you can query the database.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |