SAP DELETE DUPLICATES ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• ADJACENT DUPLICATES DELETE itab

DELETE itab, duplicates
Short Reference

ABAP_SYNTAX
... ADJACENT DUPLICATES FROM itab $[USING KEY keyname$]
$[COMPARING ${comp1 comp2 ...$}$|${ALL FIELDS$}$] ...

ABAP Addition
1 ... USING KEY keyname
2 ... COMPARING ${comp1 comp2 ...$}$|${ALL FIELDS$}

What does it do?
Using these additions, the statement DELETE deletes all lines except for the first line of the group in groups of consecutive lines that have the same content in certain components. If the addition COMPARING is not specified, the groups are determined by the content of the key fields of the table key used. If no explicit table key is specified, the primary table key is used implicitly.
The order of the table lines that are used to form the groups is determined by the table key used. If no key keyname is specified after USING KEY, the order is the same as when processing a statement LOOP without an explicit key specification.
Lines are considered to be duplicate if the content of neighboring line matches in the components examined. In the case of multiple duplicate lines following one another, all but the first line are deleted.
If the primary table key is used to access a standard table and the key is empty, no lines are deleted. If this is known statically, the syntax check produces a warning.



Latest notes:

The use of ADJACENT DUPLICATES usually requires a suitable sorting by the components compared in the statement.
When using the primary table key, it should be noted that this key can be the standard key, which can also have unexpected consequences:
For structured line types, the standard key covers all character-like and byte-like components.
The standard key of a standard table can be empty.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Deletion of all multiple lines with respect to the primary key in the internal table city_connections.
ABEXA 00194
ABAP_EXAMPLE_END
• USING KEY DELETE ADJACENT DUPLICATES

ABAP Addition