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 table in db

Former Member
0 Likes
797

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
776

Hi,

You can use MODIFY statement.

Regards,

Ankur Parab

Hi,

You can use MODIFY statement.

Regards,

Ankur Parab

6 REPLIES 6
Read only

Former Member
0 Likes
777

Hi,

You can use MODIFY statement.

Regards,

Ankur Parab

Read only

0 Likes
776

HI Ankur,

Thanks ,

but how will i know if the record is already exist in the table.

I need to know that.

BR

Michael

Read only

0 Likes
776

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.

Read only

former_member229729
Active Participant
0 Likes
776

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

Read only

Former Member
0 Likes
776

This message was moderated.

Read only

Former Member
0 Likes
776

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.