在内部表中显示重复项 [英] Show duplicates in internal table
问题描述
每个项目都应具有唯一的SecondNo + Drawing组合。由于输入错误,某些组合会出现两次。
Each an every item should have an uniquie SecondNo + Drawing combination. Due to misentries, some combinations are there two times.
我需要使用ABAP创建一个报告,以识别那些组合,而不反映其他组合。
I need to create a report with ABAP which identifies those combinations and does not reflect the others.
Item: SecNo: Drawing:
121 904 5000 double
122 904 5000 double
123 816 5100
124 813 5200
125 812 4900 double
126 812 4900 double
127 814 5300
我该如何解决?我尝试了两种方法,但均失败了:
How can I solve this? I tried 2 approaches and failed:
-
对数据进行排序,并尝试在上一行的值是等于下一个值
Sorting the data and tried to print out each one when the value of the upper row is equal to the next value
计算重复项并显示所有重复项,然后再重复。
counting the duplicates and showing all of them which are more then one.
我该放在哪里?在循环区域中?
Where do I put in the condition? in the loop area?
我尝试过此操作:
REPORT duplicates.
DATA: BEGIN OF lt_duplicates OCCURS 0,
f2(10),
f3(10),
END OF lt_duplicates,
it_test TYPE TABLE OF ztest WITH HEADER LINE,
i TYPE i.
SELECT DISTINCT f2 f3 FROM ztest INTO TABLE lt_duplicates.
LOOP AT lt_duplicates.
IF f2 = lt_duplicates-f2 AND f3 = lt_duplicates-f3.
ENDIF.
i = LINES( it_test ).
IF i > 1.
LOOP AT it_test.
WRITE :/ it_test-f1,it_test-f2,it_test-f3.
ENDLOOP.
ENDIF.
ENDLOOP.
推荐答案
您可以使用 AT。 ..ENDAT
,前提是您正确排列字段:
You can use AT...ENDAT
for this, provided that you arrange the fields correctly:
TYPES: BEGIN OF t_my_line,
secno TYPE foo,
drawing TYPE bar,
item TYPE baz, " this field has to appear AFTER the other ones in the table
END OF t_my_line.
DATA: lt_my_table TYPE TABLE OF t_my_line,
lt_duplicates TYPE TABLE OF t_my_line.
FIELD-SYMBOLS: <ls_line> TYPE t_my_line.
START-OF-WHATEVER.
* ... fill the table ...
SORT lt_my_table BY secno drawing.
LOOP AT lt_my_table ASSIGNING <ls_line>.
AT NEW drawing. " whenever drawing or any field left of it changes...
FREE lt_duplicates.
ENDAT.
APPEND <ls_line> TO lt_duplicates.
AT END OF drawing.
IF lines( lt_duplicates ) > 1.
* congrats, here are your duplicates...
ENDIF.
ENDAT.
ENDLOOP.
这篇关于在内部表中显示重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!