Skip to content

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

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 indexes 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. To actually delete the rows 2 to 4, the FROM TO addition of the DELETE statement is used. The third deletion fails, since the table now has only three rows.

The addition FROM TO of the statement DELETE can be used to actually delete the rows 2 to 4.