Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  DELETE itab 

Internal Tables - Deleting Rows Using the Index

This example demonstrates how rows can be deleted from internal tables using the index.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA itab TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line.

    FIELD-SYMBOLS <line> LIKE LINE OF itab.

    DATA(out) = cl_demo_output=>new( ).

    itab = VALUE #( FOR j = 1 UNTIL j > 5 ( j ) ).

    DELETE itab INDEX: 2, 3, 4.

    out->write( |sy-subrc: { sy-subrc }| ).

    LOOP AT itab ASSIGNING <line>.
      out->write( |{ sy-tabix } { <line> }| ).
    ENDLOOP.

    out->display( ).

Description

A sorted table itab is filled with five rows. Then an attempt is made to delete the rows with the indices 2, 3, and 4 using a chained statement. However, after the deletion of each individual row, the index of each subsequent row is lowered by 1.This means, the second delete operation actually deletes the row which originally had the index 4. The third delete operation fails because the table is now made up of only 3 rows.

To actually delete the rows 2 to 4, the FROM TO addition of the DELETE statement is used.