Search on this Website

Sunday, December 16, 2007

Updating database tables - SQL Query

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'

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

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


Updating multiple entries

Examlpe 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.

No comments: