Deleting Entries using SAP Open SQL

DELETE is the open SQL statement to delete entries from database table. First declare a work area as the line structure of database table and populate the work area with the  specific key that we want to delete from the database table. Then delete the entries from the database table using DELETE statement.

The syntax for the DELETE statement is as follows.

DELETE <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 deleted, 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.

DELETE zemployee FROM gwa_employee.

EMPLOYEE table entries before DELETE


EMPLOYEE table entries after DELETE


We can also multiple lines from the table using the WHERE clause in the DELETE statement.

DELETE FROM <database table> WHERE <condition>


DELETE FROM zemployee WHERE dept_id = 2.

EMPLOYEE table entries after DELETE


Be the first to comment

Leave a Reply

Your email address will not be published.