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

A question about database update

Former Member
0 Likes
933

Hi all,

I got a question to all the experts out there. Whenever we need to update the record in the database, we either use UPDATE or MODIFY statement through either an internal table or work area. Can we like only update the first few fields and leave the rest of the fields in tact? Example, my table has 5 fields. In my internal table, I only populate the first 3 fields and leave the last 2 fields blank. When I use MODIFY/UPDATE, will my record in the database being overwritten by blank values for the last 2 fields? Is there a faster way to only update the required fields without the need to assign all the fields in the internal tables? What if my table is 100 fields long and I only need to update about 5 fields? Any help is greatly appreciated.

8 REPLIES 8
Read only

Sougata
Active Contributor
0 Likes
857

Hi there,

Use this syntax:


TRY.
  UPDATE (table)
  SET        (set_expression)     "<----This is where you set your required columns only to update
  WHERE  (condition).
 CATCH cx_sy_open_sql_db.
   MESSAGE 'Error in update!' TYPE 'I'.
ENDTRY.

Hope this solves your issue.

Cheers,

Sougata.

Read only

mvoros
Active Contributor
0 Likes
857

Hi,

you can write something like this.


UPDATE dbtab SET field1 = value WHERE <some_condition>

Just check ABAP documentation for UPDATE.

Cheers

Read only

vijy_mukunthan
Active Contributor
0 Likes
857

Hi

NEVER USE UPDATE statement in SAP USE ONLY STANDARD FUNCTION MODULE TO UPDATE THE DATABASE

Regards

vijay

Read only

0 Likes
857

>

> Hi

>

> NEVER USE UPDATE statement in SAP USE ONLY STANDARD FUNCTION MODULE TO UPDATE THE DATABASE

>

> Regards

> vijay

Hi Vijay,

Could you kindly enlighten us all with the Standard Function Module name to update my Z table / database?

I think you message should read "Never use UPDATE statement to update SAP standard tables"!!

Sougata.

Read only

Former Member
0 Likes
857

Hi,

You can use LSMW direct input method.

Regards

Md.MahaboobKhan

Read only

Former Member
0 Likes
857

Hi,

It depends upon your Update statment how you have written it .

if you are using Update Dtab values Wa then blank entries will be updated

but if you are using with set statment then you can update only the desired field other fields will be untouched.

Better see complete documentation of Update statment by pressing F1 your querry will be clear.

Regards

Bikas

Read only

Former Member
0 Likes
857

Hi ,

When trying to update values to standard tables always try using some BAPI to do this operation .

If not validat the data you are trying to Update in all possible ways .

Update / Modify as such when used maeks the non filled values in WA to be updated as balnk values in tables.

But as said earlier Update with SET values is porbabaly one of the best options to use .

You may refer the below link for details plus an example too:

http://help.sap.com/saphelp_NW04/helpdata/en/fc/eb3a94358411d1829f0000e829fbfe/frameset.htm

Regards,

Radhika.

Read only

Former Member
0 Likes
857

All,

Thanks for all the answers, but there are other concern including the use of SET & WHERE clauses of the UPDATE statement. The problem arise if I were to update more than 1 records into my table. The only way I see it if I were to use SET & WHERE clause is to include the UPDATE in a loop, which is not good performance wise. Is there another way around just like updating a table through the use of internal table, but only a few fields? Just a recap of my question:

- I need to update more than 1 records in my table with about 100 fields.

- I only need to update about 5 fields. (I do not wish to select ALL the fields from my table prior to the update since I only need 5 of them)

- I do not wish to perform the update inside a loop.

- Is there a way to get this done through using MODIFY rather than UPDATE?