2007 Nov 16 3:46 AM
Can we compare records within single internal table.how to do it.
Can we compare records within single internal table.how to do it.
2007 Nov 16 3:50 AM
loop at it into wa. "read same itenal table
read table itab from wa with key wa-field wa-field.
endloop.
2007 Nov 16 3:53 AM
Do you want to compare the same field or different fields from the internal table.?
Regards,
Atish
2007 Nov 16 4:03 AM
data : l_lines type sy-tabix.
describe table itab lines l_lines.
loop at itab into watab.
l_tabix = sy-tabix + 1.
loop at itab into wtemp from l_tabix to l_lines where matnr = watab-matnr.
write :/ 'duplicate record exists'.
endloop.
clear : l_tabix,
watab,
wtemp.
endloop.
2007 Nov 16 5:15 AM
Hi Suganya,
Yes, we can compare records within single internal table.
ex:
Case1: Want to compare only the key fields.
i_tab is the internal table without work area.
w_tab is the external work area for the table i_tab.
w2_tab is the second external work area for the table i_tab.
loop at i_tab into w_tab.
loop at i_tab into w2_tab where field1 = w_tab-field and
field2 = w_tab-field.
If the control enter the second loop, the duplicate record exits.
endloop.
endloop.
If u want to count the number of duplicate records exist in the single internal record, then set a counter.
ex : i_tab is the internal table without work area.
w_tab is the external work area for the table i_tab.
w2_tab is the second external work area for the table i_tab.
Declare the structure to count the dup records in the same internal table
types : begin of s_dup_cnt ,
record type i,
count type i.
end of s_dup_cnt.
Declare the internal table & work area
data : t_dup_cnt type standard table of s_dup_cnt.
w_dup_cnt type s_dup_cnt.
loop at i_tab into w_tab.
get the record number
w_dup_cnt-record = SY-TABIX.
w_dup_cnt-count = 0.
loop at i_tab into w2_tab where field1 = w_tab-field and
field2 = w_tab-field.
w_dup_cnt-count = w_dup_cnt-count + 1.
endloop.
append w_dup_cnt to t_dup_cnt.
clear w_dup_cnt.
endloop.
loop at t_dup_cnt into w_dup_cnt.
write w_dup_cnt-record .
write w_dup_cnt-count.
endloop.
t_dup_cnt now contains the record number & the number of times the record repeated * in the same internal table,
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |