Register Login

Updating a database table

Updated May 18, 2018

1. Updating records in the database table from an internal table
2. Updating a single entry
3. Updating multiple entries

1. Updating records in the database table from an internal table

table: personel.
data: itab like personel.

* Read records from the database table where name is space, into an internal table
select * from personal into table itab
where name = space.

* Update name in the internal table to Unknown
loop at itab.
itab-name = 'Unknown'
endloop.

* Modify records in the database table. Only records with the same key values as then
* internal table is modified
MODIFY personel from table itab.


2. Updating a single entry

In this example the entry with the key value Customerno = 1 is changed.

table customer.

customer-customerno = 1.
customer-customnavme = 'John'.

UPDATE customer.
if sy-subrc 0.
..... No entry with the customerno = 1, add error handling
endif.


3. Updating multiple entries

Examle updating the field zchecked to 'X'

UPDATE zcostcheck set zchecked = 'X'
WHERE zcostcheck-zaar = zaar and
zcostcheck-zmaaned = zmaaned and
zcostcheck-zbukrs = zbukrs and
zcostcheck-zsaknr = zsaknr2 and
zcostcheck-zgsber = zgsber.


×