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

Updating multiple records into database table using update statement

Former Member
0 Likes
13,753

I have a program where in i want to update mutiple records into database table from an internal table using update statement. i want to update only 1 field into that DB table.

I want to set a field xyz = 'X' where xyz = ' '.

Does anybody have solution for that?

13 REPLIES 13
Read only

Former Member
0 Likes
6,093

Hi,

This is very simple. No matter how many fields you want to update if you put all your data into internal table with updated values and use update statement againest this internal table automatically only those fields you modified will change in the database.


UPDATE DBtable FROM TABLE Internal table.

Hope this helps.

Aswath.

Read only

0 Likes
6,093

I want to update a single field xyz passing an internal table along with condition in the same update statement.Is it possible ?

Read only

0 Likes
6,093

Hi Navya,

You can do like this.



Loop at Itab into wa.

if condition on workarea whatever condition you have.

update dbtable from workarea.

endloop.

If this is not your requirment please provide what condition you have and how you want to update.

Thanks.

Aswath.

Read only

0 Likes
6,093

If i use update within the loop , it would hit the database many times leads to performance issue. So is there any other solution to update from internal table with certain condition other than using loop or update <database tab> from <internal tab> ?

Read only

0 Likes
6,093

HI,

you can use ,

UPDATE DBtable From Internaltable where xyz = 'some'.

Thanks.

Aswath.

Read only

0 Likes
6,093

Hi,

Then u can use

update <database tab> from <internal tab>

By having the records in the internal table where xyz = ' ' & internal table having all the key fields of DB

Regards,

Madhukar Shetty

Read only

0 Likes
6,072

In case we are using adbc how to  update it 

Read only

0 Likes
5,994

Hello, 

While we're happy that you've come to SAP Community to get an answer to your question, you posted your question as an answer in an old thread.

Posting in older threads is not the best way to get guidance.

If you're looking for help, you should start a new discussion: https://community.sap.com/t5/application-development-discussions/bd-p/application-developmentforum-b...
Best regards,
Anne

Read only

Former Member
0 Likes
6,093

Hi

Update Table name

set xyz = 'X'

where xyz = ''.

Regards,

Gopi

Read only

Former Member
0 Likes
6,093

Hi,

Can u tell what data are u having in the internal table ?

Does the internal table have all the key field of the DB table which u want to update ?

If u have the all key field then u can use below logic

LOOP at it where xyz = ' '.

UPDATE ztable 
    SET    xyz = 'X' 
    WHERE  id = it-id "Here u have to add all table key fields
    and        xyz = ' '.

ENDLOOP.

Thanks,

Madhukar Shetty

Read only

Former Member
0 Likes
6,093

Hi Navya,

You can use 'MODIFY' command to update in internal table level ,it wont update in database level.

But if you use 'UPDATE' command it will update the data in database level.So try to use modify command .

Thanks and regards,

Dhaya.G

Edited by: Dhayalinie Ganesh on Feb 23, 2012 7:36 AM

Read only

Former Member
0 Likes
6,093

Hi Navya,

1) Declare a work area type database table OR containing primary key combination.

2) Use the work area to update your database table

Please remember:

1) MODIFY statement - if record is available in DB table, it will modify it. If record is not available, it will create a new entry.

2) UPDATE statment - only to update an existing entry

Regards,

Ajoy

Read only

Former Member
0 Likes
6,093

Hi Navya,

You can refer this ,

Loop at ITAB1 into WA1.

read table ITAB2 into WA2 with key XYZ = WA1-XYZ .

if sy-subrc = 0.

move WA2-field to WA1-field.

modify ITAB1 index sy-tabix from WA1 transporting field.

endif.

endloop.

Thanks and Regards,

Dhaya.G