Changing Values using SAP Open SQL

UPDATE is the open SQL statement to change the values in the database table. First declare a work area as the line structure of database table and populate the work area with the desired values for a specific key in the database table. Then update the values for the specified key in the database table using UPDATE statement.

The syntax for the UPDATE statement is as follows.

UPDATE <database table> FROM <work area>

If the database table contains a line with the same primary key as specified in the work area, the operation is completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set to 4.

DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'JOSEPH'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.

UPDATE zemployee FROM gwa_employee.

EMPLOYEE table entries before UPDATE


EMPLOYEE table entries after UPDATE


We can also change certain columns in the database table using the following syntax

UPDATE <target> SET <set1> <set 2> … [WHERE <condition>].

The WHERE clause determines the lines that are changed. If we do not specify a WHERE clause, all lines will be changed.

UPDATE zemployee SET place = 'MUMBAI' WHERE dept_id = 2.

EMPLOYEE table entries after UPDATE


Be the first to comment

Leave a Reply

Your email address will not be published.