我有一张包含一些数据的表格:
101
101
102
101
102
103
103
我需要删除这样的重复项:
101
102
101
102
103
但在这种情况下,我无法使用delete adjacent duplicates
。
我该怎么办?
答案 0 :(得分:1)
DATA: LS_PREV LIKE LINE OF TAB.
" Set LS_PREV to some value you know will not occur in the table
LOOP AT TAB INTO LS_TAB.
IF LS_TAB EQ LS_PREV.
DELETE TAB.
ENDIF.
LS_PREV = LS_TAB.
ENDLOOP.
或vwegert指出如下:
DELETE ADJACENT DUPLICATES FROM TAB.
答案 1 :(得分:0)
假设您的表格为: lt_tab 。 然后
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.
另一种方法是: 假设您在 DUPCOL '中有重复数据。在表格 lt_tab 。
中然后,
SORT lt_tab BY DUPCOL.
DELETE ADJACENT DUPLICATES FROM lt_tab COMPARING DUPCOL.
答案 2 :(得分:0)
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.
答案 3 :(得分:0)
DELETE ADJACENT DUPLICATES FROM (tableName)
。结果:仅删除重复行中的行的条目。
注意:仅在对内部表进行排序之前,所有重复项都将被删除。