Abap remove adjacent duplicates

If there are entries with the same key.

sort itab by key. remove adjacent duplicates from the itab comparison file.

Does anyone know which one will be deleted if neighboring duplicates are deleted. First or second?

+6
source share
3 answers

From F1 help to "delete adjacent duplicate"

In the case of several double lines following each other, all lines - except the first - are deleted.

So the second (identical) line should be deleted

Hi,

+10
source

Instead of sorting a standard table, you might consider declaring another internal table as a sorted table of the same type with a unique key corresponding to the fields you are comparing to eliminate duplicates. This is faster, allows you to keep the original table unchanged and, in my opinion, makes your code more readable, because it is easier to understand which lines are stored and which are not. Example:

LOOP AT itab ASSIGNING <itab_row>. INSERT <itab_row> INTO TABLE sorted_itab. ENDLOOP. 
+4
source

If the data in your itab is retrieved from the database, this is better than using the ORDER BY padding in SELECT, and you can use remote neighboring duplicates. The algorithm is nlog (n) sorting algorithm and it is better that the DBMS performs this type of operation instead of ABAP. Obviously, if you can use DISTINCT or GROUP BY in SQL, you avoid using both SORT and deleting neighboring duplicates, and you should solve all performance problems.

0
source

Source: https://habr.com/ru/post/899560/


All Articles