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 database table from a work area

Former Member
0 Likes
75,521

hi!

I have a workarea that is like the corresponding database table. There are a lot of fields so I dont want to update each field with an UPDATE but instead I want to do som sort of:

UPDATE dbase_table

FROM work_area

WHERE dbase_table-primary_key = work_area-primary_key

I could only find a statement called UPDATE dbase_table FROM work_area but I dont understand how without specifying a WHERE clause it knows which rows to update.

regards

Baran

1 ACCEPTED SOLUTION
Read only

Former Member
18,294

Hi baran,

1. In such cases,

we can use MODIFY statement.

2. MODIFY will AUTOMATICALLY

take care of insert/update

based upon the primary key field combination,

found / not found

in the database table,

w.r.t to values in the work area.

regards,

amit m.

8 REPLIES 8
Read only

gopi_narendra
Active Contributor
18,294

u can even use a modify statement to update a table from a work area

Read only

suresh_datti
Active Contributor
18,294

use the fllowing..

UPDATE dbase_table

FROM work_area

SET dbase_table-primary_key = work_area-primary_key.

~Suresh

Read only

Former Member
0 Likes
18,294

UPDATE dbtab FROM wa. or

UPDATE (dbtabname) FROM wa.

Extras:

1. ... CLIENT SPECIFIED

2. ... CONNECTION con

Effect

Changes one single line in a database table, using a primary key to identify the line and taking the values to be changed from the specified work area, wa. The data is read out of wa from left to right, matching the line structure of the database table dbtab. The structure of wa remains unchanged. This means that wa must be at least as wide (see DATA) as the line structure of dbtab, and have the same alignment. Otherwise, a runtime error occurs.

If either the database table, dbtab, or the work area, wa, contain Strings, wa must be compatible with the line structure of dbtab.

Example

Changing the telephone number of the customer with customer number '12400177' in the current client:

DATA wa TYPE scustom.

SELECT SINGLE * FROM scustom INTO wa

WHERE id = '12400177'.

wa-telephone = '06201/44889'.

UPDATE scustom FROM wa.

When the command has been executed, the system field SY-DBCNT contains the number of updated lines (0 or 1).

Examples

Update discount for the customer with the customer number '00017777' to 3 percent (in the current client):

DATA: wa TYPE scustom.

SELECT SINGLE * FROM scustom INTO wa

WHERE id = '00017777'.

wa-discount = '003'.

UPDATE scustom FROM wa.

The Return Code is set as follows:

SY-SUBRC = 0:

The specified line has been updated.

SY-SUBRC = 4:

The system could not update any line in the table, since there is no line with the specified primary key.

BR< JAcek

Read only

Former Member
0 Likes
18,294

UPDATE dbtab FROM wa. will do it for you.

The structure of wa and dbtab must be the same.

it will update the record which matches the key in the work area. No need to specify the where condition.

or you can also use:

MODIFY dbtab FROM wa.

eg:

DATA: wa TYPE scustom.

wa-id = '12400177'.

wa-name = 'Robinson'.

wa-postcode = '69542'.

wa-city = 'Heidelberg'.

wa-custtype = 'P'.

wa-discount = '003'.

wa-telephone = '06201/44889'.

MODIFY scustom FROM wa.

But this statement, unlike update, inserts a row, if no match id found for the key fields.

Regards,

ravi

Read only

Former Member
0 Likes
18,294

Hi Baran,

you can use this statement.

MODIFY dbtable FROM work_area.

where it will change the non primary keys with the primary key combination.

-Anu.

Read only

Former Member
18,295

Hi baran,

1. In such cases,

we can use MODIFY statement.

2. MODIFY will AUTOMATICALLY

take care of insert/update

based upon the primary key field combination,

found / not found

in the database table,

w.r.t to values in the work area.

regards,

amit m.

Read only

Former Member
18,294

Hi,

UPDATE VBAK SET ERDAT = SY-DATUM WHERE KUNNR = 'zzzzzzz'.

Rgds

Read only

Former Member
0 Likes
18,294

Hi Baran,

MODIFY statement will be used to update the required fields with out updating entire record.

MODIFY itab FROM wa WHERE primary_key = wa-primary_key TRANSPORTING field1 field2.

The above statement will be used to update the field1, field2 values in ITAB entry WHERE wa-primary_key is same as ITAB primary key.

Thank YOu.

Shyam.