‎2006 Sep 07 10:19 AM
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
‎2006 Sep 07 10:28 AM
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.
‎2006 Sep 07 10:21 AM
u can even use a modify statement to update a table from a work area
‎2006 Sep 07 10:23 AM
use the fllowing..
UPDATE dbase_table
FROM work_area
SET dbase_table-primary_key = work_area-primary_key.
~Suresh
‎2006 Sep 07 10:23 AM
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
‎2006 Sep 07 10:25 AM
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
‎2006 Sep 07 10:26 AM
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.
‎2006 Sep 07 10:28 AM
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.
‎2006 Sep 07 10:33 AM
Hi,
UPDATE VBAK SET ERDAT = SY-DATUM WHERE KUNNR = 'zzzzzzz'.
Rgds
‎2012 Jun 20 12:02 AM
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.