sapdev logo background
sapdev logo sapdev logo
Comments

ABAP DELETE DUPLICATES Statement syntax, information and example SAP source code



Return to Statement index



DELETE itab - duplicates

Short Reference

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

ABAP_ADDITIONS:
1 ... USING KEY keyname
2 ... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

What does it do? Using these additions, the statement DELETE deletes all rows in certain groups of rows, except for the first row of the group. These are groups of rows that are sequential and 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 being used. If no explicit table key is specified, the primary table key is used implicitly.
The order of the table rows that are used to form the groups is determined by the table key being used. If no key keyname is specified after USING KEY , the order is the same as when processing a LOOP statement without explicit specification of a key.
Rows are considered to be duplicate if the content of neighboring row is the same in the components examined. In the case of multiple duplicate rows following one another, all the rows (except for the first) are deleted.
If the primary table key is used to access a standard table and the key is
empty , then no rows are deleted. If this is statically identifiable, the syntax check produces a warning.
Latest notes: When using the primary table key, note that this key can be the standard key , which can also have unexpected consequences:
For structured row types, the standard key covers all character-like and byte-like components.
The standard key of a standard table can be
empty .

ABAP_ADDITION_1 ... USING KEY keyname

Latest notes: Unlike the processing of a hash table when a primary key is used, a preceding sort using the SORT statement has no influence on the processing sequence when a secondary hash key is specified.

ABAP_ADDITION_2 ... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

What does it do? If the addition COMPARING is specified, the groups are determined either by the content of the specified components
comp1 comp2 ... or the content of all components ALL FIELDS . The specification of individual components comp is made as described in the section Specification of Components . Access to class attributes is possible using the object component selector.

Example ABAP Coding Deletes all multiple rows with respect to the primary key in the internal table connection_tab . The result of this example corresponds to the one in the example for the position specification for INSERT .
DATA: BEGIN OF connection,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
distid TYPE spfli-distid,
distance TYPE spfli-distance,
END OF connection.

DATA connection_tab LIKE SORTED TABLE OF connection
WITH NON-UNIQUE KEY cityfrom cityto
distid distance.

SELECT cityfrom cityto distid distance
FROM spfli
INTO TABLE connection_tab.

DELETE ADJACENT DUPLICATES FROM connection_tab.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




DELETE_DBTAB_OBSOLETE
DELETE_DYNPRO




comments powered by Disqus