If there are entries with the same key.
sort itab by key. delete adjacent duplicates from itab comparing key.
Does anyone know which one will be deleted if delete adjacent duplicates..comparing key? The first one or second one?
If there are entries with the same key.
sort itab by key. delete adjacent duplicates from itab comparing key.
Does anyone know which one will be deleted if delete adjacent duplicates..comparing key? The first one or second one?
From F1 help on "delete adjacent duplicate"
In the case of several double lines following one another, all the lines - except for the first - are deleted.
So the second (identical) line should be deleted
Regards,
Instead of sorting a standard table, you could consider declaring another internal table as a sorted table of the same type with a unique key corresponding to the fields you're comparing to eliminate the duplicates. It's faster, allows you to keep your original table unchanged, and, in my opinion, makes your code more readable because it's easier to understand which rows are kept and which ones are not. Example:
LOOP AT itab ASSIGNING <itab_row>.
INSERT <itab_row> INTO TABLE sorted_itab.
ENDLOOP.
INSERT
statement will not cause a runtime error when it encounters a duplicate primary key; it will simply return subrc 4 and continue without inserting the row. I've also done some testing of both implementations, and it appears my solution is exponentially faster than sorting and deleting adjacent duplicates (if you want I can provide you with a test program and the results). –
Cyndy If data in your itab are fetched from DB, it's better than you use ORDER BY addition in SELECT and than you can use the delete adjacent duplicates . Sorting algorithm costs nlog(n) and is better that DBMS does these type of operation instead ABAP. Obviously that if you can do the DISTINCT or GROUP BY in SQL you avoid to use both SORT and delete adjacent duplicates and you should solve all performance problems
© 2022 - 2024 — McMap. All rights reserved.