Inserting Values using SAP Open SQL

INSERT is the open SQL statement to add values to the database table. First declare a work area as the line structure of database table and populate the work area with the desired values. Then add the values in the work area to the database table using INSERT statement.

The syntax for the INSERT statement is as follows.

INSERT <database table> FROM <work area>

or

INSERT INTO <database table> VALUES <work area>

If the database table does not already contain 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    = 'MARY'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.

INSERT zemployee FROM gwa_employee.

EMPLOYEE table entries before INSERT

sql-select-1

EMPLOYEE table entries after INSERT

insert-1


1 Comment

Comments are closed.