10-10-2007 7:16 PM
Hi,
I want to find the duplicates in an internal table...Does anyone have sample code for this?
Thanks.
10-10-2007 7:30 PM
Try this, instead of delete itab you can do whatever you want.
sort itab by f1 f2.
itab1[] = itab[].
loop at itab.
l_tabix = sy-tabix + 1 + skip.
loop at itab1 from l_tabix.
if itab1-f1 = itab-f1 and
itab1-f2 = itab-f2.
delete itab.
skip = skip + 1.
continue.
endif.
endloop.
endloop.
Hope it helps!
CL
10-10-2007 7:34 PM
Hi,
Please check this sample code from other thread.
data: begin of itab1 occurs 0,
fld1 type c,
fld2 type c,
fld3 type c,
end of itab1.
data: begin of itab2 occurs 0,
fld1 type c,
fld2 type c,
fld3 type c,
end of itab2.
data: counter type i.
itab1 = 'ABC'. append itab1.
itab1 = 'DEF'. append itab1.
itab1 = 'GHI'. append itab1.
itab1 = 'DEF'. append itab1.
itab1 = 'GHI'. append itab1.
itab1 = 'DEF'. append itab1.
itab2[] = itab1[].
sort itab1 ascending.
delete adjacent duplicates from itab1.
loop at itab1.
clear counter.
loop at itab2 where fld1 = itab1-fld1
and fld2 = itab1-fld2
and fld3 = itab1-fld3.
counter = counter + 1.
endloop.
write:/ itab1-fld1, itab1-fld2, itab1-fld3,
'Number of occurances:', counter.
endloop.
Regards,
Ferry Lianto