DELETE ADJACENT DUPLICATES FROM itab.
Extras:
1. ... COMPARING f1 f2 ...
2. ... COMPARING ALL FIELDS
Effect
Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.
Two lines are regarded as duplicates if their keys are identical.
The Return Code is set as follows:
- SY-SUBRC = 0:
- At least one duplicate was found, and at least one entry was deleted.
- SY-SUBRC = 4:
- No duplicates found, no entries deleted.
Addition 1
... COMPARING f1 f2 ...
Effect
Two lines of the internal table itab are regarded as duplicates if they have identical contents in the fields f1, f2, ...
Addition 2
... COMPARING ALL FIELDS
Effect
Two lines of the internal table are regarded as duplicates if all of their field contents are identical.
Notes
- The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.
- If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.
- You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.
Note
Performance:
- When you delete a line of an internal table, index maintenance costs are incurred. These depend on the index of the table. The runtime is independent of the width of the table line.
Deleting a line from the middle of an internal table with 200 entries usually requires around10 msn (standardized microseconds).
When you delete a set of entries using "DELETE itab FROM idx1 TO idx2." or "DELETE itab WHERE ...", index maintenance costs are only incurred once. This means that it is considerably more efficient than deleting entries in a LOOP.
- If you want to delete adjacent duplicate entries from an internal table, use the variant " DELETE ADJACENT DUPLICATES FROM itab." instead of a LOOP construction.
다음검색