I have a table with some data:
101
101
102
101
102
103
103
and I need to delete duplicates like this:
101
102
101
102
103
but in this case I cant use delete adjacent duplicates
.
What can I do?
I have a table with some data:
101
101
102
101
102
103
103
and I need to delete duplicates like this:
101
102
101
102
103
but in this case I cant use delete adjacent duplicates
.
What can I do?
This should work just fine.
REPORT z_teste_brl.
TYPES : ty_n TYPE n LENGTH 3.
DATA : t_n TYPE TABLE OF ty_n WITH DEFAULT KEY.
DATA : curr_n TYPE ty_n.
DATA : last_n TYPE ty_n.
APPEND '101' TO t_n.
APPEND '101' TO t_n.
APPEND '102' TO t_n.
APPEND '101' TO t_n.
APPEND '102' TO t_n.
APPEND '103' TO t_n.
APPEND '103' TO t_n.
LOOP AT t_n INTO curr_n.
IF sy-tabix GT 1 AND curr_n EQ last_n.
DELETE t_n INDEX sy-tabix.
CONTINUE.
ELSE.
last_n = curr_n.
ENDIF.
ENDLOOP.
BREAK-POINT.
Suppose your table is: lt_tab. Then
LOOP AT lt_tab INTO ls_tab.
IF ls_tab_prev EQ ls_tab.
DELETE lt_tab INDEX sy-tabix.
ENDIF.
ls_tab_prev = ls_tab
ENDLOOP.
Another approach is : Suppose you have duplicate data in 'DUPCOL' In table lt_tab.
Then,
SORT lt_tab BY DUPCOL.
DELETE ADJACENT DUPLICATES FROM lt_tab COMPARING DUPCOL.
or as vwegert points out below: