ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables → DELETE itab → DELETE itab - duplicates
Internal Tables - Deleting Duplicate Rows
This example demonstrates how adjacent duplicate rows in internal tables can be deleted.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE c LENGTH 1,
END OF line.
DATA itab LIKE STANDARD TABLE OF line
WITH NON-UNIQUE KEY col2.
line-col1 = 1. line-col2 = 'A'. APPEND line TO itab.
line-col1 = 1. line-col2 = 'A'. APPEND line TO itab.
line-col1 = 1. line-col2 = 'B'. APPEND line TO itab.
line-col1 = 2. line-col2 = 'B'. APPEND line TO itab.
line-col1 = 3. line-col2 = 'B'. APPEND line TO itab.
line-col1 = 4. line-col2 = 'B'. APPEND line TO itab.
line-col1 = 5. line-col2 = 'A'. APPEND line TO itab.
cl_abap_demo_services=>list_table_with_offset( table = itab
offset = 0 ).
DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.
cl_abap_demo_services=>list_table_with_offset( table = itab
offset = 14 ).
DELETE ADJACENT DUPLICATES FROM itab COMPARING col1.
cl_abap_demo_services=>list_table_with_offset( table = itab
offset = 28 ).
DELETE ADJACENT DUPLICATES FROM itab.
cl_abap_demo_services=>list_table_with_offset( table = itab
offset = 42 ).
Description
In the main
method, a standard table is created and filled. The first
DELETE statement deletes the second row because it has the same content as the first row. The
second DELETE
statement deletes the second row from the remaining table because
the content of the field col1
is the same as in the first row. The third
DELETE
statement deletes the third and fourth rows of the remaining table
as the content of the key field col2
is the same as in the second row. Although
the content of the key fields for the first and fifth rows is the same, the fifth row is not deleted because it is not adjacent to the first row.