How to Delete records from the internal table in SAP ABAP

The Data records present in the internal table can be deleted in following ways.

  • Key or work area (structure)
  • WHERE conditions.
  • Index
  • From Index TO Index
  • Clean, Refresh, free

DATA lt_internal_table TYPE TABLE OF ztt_db_table2.

DATA ls_structure TYPE ztt_db_table2.

SELECT *FROM ztt_db_Table2 INTO TABLE lt_internal_table.

              ls_structure – contact_id = 102.

              ls_structure – contact_name = ‘Thiru’.

              ls_structure – contact_address = ‘Street 10’.

Key or Work Area:

DELETE TABLE lt_internal_Table FROM ls_structure.

Only for key or structure, ‘TABLE’ is written explicitly after DELETE in the syntax.

WHERE:

DELETE lt_internal_table WHERE contact_id = 102.

INDEX:

DELETE lt_internal_table INDEX 2.

FROM INDEX TO INDEX:

DELETE lt_internal_table FROM 2 TO 3.

If the deletion is successful, then the system field sy-subrc will hold the value 0. If it is not successful, it will hold the value 4.