If used incorrectly, you wipe out contents of entire table. The DELETE statement only needs to take into account your primary key. Can also use logic (WHERE) to determine which records we want to delete. DELETE FROM tablename, without any FROM addition will delete all the records in the table. Can use the DELETE statement to delete individual records or groups of records. The fastest way is by using the table index. Only applies to standard tables and sorted tables, hashed tables do not have an index. With an index you do not use a header line, but directly address the record you want to delete. Can also use this statement in a loop in combination with sy-index (shows the current iteration of a loop). For an internal table, do not use the delete statement without the index addition. Outside of the loop you'll get a runtime error. T o comply with ABAP syntax, you need to add INDEX when using DELETE inside a loop. When you do not know the index and you are dealing with non-unique records, use WHERE statement. Use the WHERE-clause to define the conditions to help you identify the record(s) you need to delete. Try and be as specific as possible, otherwise you might delete too much data. All records that match the logic expression will be removed from the table. Do not need a work area or header record, because you reference the internal table or table directly. When deleting the contents of internal table with header line, first clear out the header line and then the body of the table.
DATA wa_employees LIKE zemployees.
**********************
*** - DELETE
wa_employees-employee = '10000007'. " Employee number is the primary key
DELETE zemployees FROM wa_employees.
IF sy-subrc = 0.
WRITE: / 'Record Deleted Correctly'.
ELSE.
WRITE: / 'We have a return code of ', sy-subrc.
ENDIF.
**********************
DELETE FROM zemployees WHERE surname = 'BROWN'. " 2 records in the table with surname = 'BROWN'
IF sy-subrc = 0.
WRITE: / '2 Records Deleted Correctly'.
ELSE.
WRITE: / 'We have a return code of ', sy-subrc.
ENDIF.
**********************
DELETE FROM zemployees.
**********************
DELETE itab01 INDEX 5.
**********************
LOOP AT itab01.
IF itab01-surname = 'SMITH'.
DELETE itab01 INDEX sy-index.
ENDIF.
ENDLOOP.
**********************
DELETE itab01 WHERE surname = 'SMITH'.