10-10-2007 8:38 AM
Hi All,
I want to detect all duplicates in itab and then display entries with duplicates. My itab only has one columns. How do I do this?
I do not wish to delete the duplicates. Thanks.
Tyken
10-10-2007 8:44 AM
10-10-2007 8:46 AM
10-10-2007 8:46 AM
sort table itab.
itab1[] = itab. " copy itab to itab1.
delete adjacent duplicates from itab1. "delete adjacent duplicates from itab1
loop at itab. " loop at itab which has duplicates
read table itab1 index sy-tabix. "read itab1 for the same index
check sy-subrc = 0.
if itab-field1 <> itab1-field1. " compare whether the fields are same or not
write: itab-field1, itab-field2. "not same means that is the duplicate record in itab.
endif.
endloop.
10-10-2007 8:54 AM
Hi,
what if i have multiple duplicate entries meaning there are several entries with duplicates?
thanks.
10-10-2007 8:47 AM
Hi,
Try like this
v_index = 2.
Loop at itab watab.
read table itab into watab1 index v_index.
if watab-field1 = watab1-field1.
move : watab-field to watab2-field.
append itab1 from watab2.
endif.
v_index = v_index + 1.
endloop.
Now itab1 will have all duplicate entries.
Regards,
Nagaraj
10-10-2007 8:56 AM
simplified version of the nagraj's code..
Hi,
data : act_indx type sy-tabix. " actual index number
data : tmp_indx type sy-tabix . " temp index number
Loop at itab1 watab1.
act_indx = sy-tabix.
tmp_indx = sy-tabix + 1.
read table itab into watab2 index tmp_indx
if watab1-field1 = watab2-field1.
append itab2 from watab2.
endif.
endloop.
No Rewards Plz
Now itab2 will have all duplicate entries.
try this it may work also for multiple dublicate entries
10-10-2007 9:01 AM
10-10-2007 9:19 AM
10-10-2007 9:12 AM
Hi,
you can write a small logic to detect the duplicates.
if ITAB contains the one cloumn,
then declare another ITAB1 which will collect the duplicates from ITAB.
try following logic,
<b>loop at itab.
at new Field1.
clear v.
endat.
v = v + 1. " Declare V as a variable
if v > 1.
move itab-field1 to itab1-field1.
append itab1.
clear itab1.
endif.
endloop.</b>
So your ITAB1 will contain only duplicates from ITAB.
reward if it helps.
Gud luck,
Bhawani
Message was edited by:
BHAWANI SHANKAR MOHANTY
10-10-2007 11:06 AM
Hi
Just execute the following code to display the duplicate records
data: begin of itab occurs 0,
name(10) type c,
address(30) type c,
end of itab.
data: v_rec like itab-name.
itab-name = 'name'.
itab-address = 'address'.
append itab.
itab-name = 'name1'.
itab-address = 'address1'.
append itab.
itab-name = 'name2'.
itab-address = 'address2'.
append itab.
itab-name = 'name3'.
itab-address = 'address3'.
append itab.
itab-name = 'name2'.
itab-address = 'address3'.
append itab.
itab-name = 'name3'.
itab-address = 'address5'.
append itab.
write:/ 'itab contents'.
loop at itab.
write:/ itab-name,itab-address.
endloop.
uline.
skip.
sort itab.
loop at itab.
on change of itab-name.
v_rec = itab-name.
if v_rec <> ' '.
delete itab.
endif.
endon.
endloop.
write:/ 'duplicate contents in itab'.
loop at itab.
write:/ itab-name,itab-address.
endloop.
Regards
Varalakshmi.K
10-10-2007 2:08 PM
hi,
declare one more itab and wa of same type as of your itab. name it as itab2. in this itab collect all entries which have duplicate entries.
sort your itab ascending.
you need to loop it
loop at itab into wa.
if sy-tabix = 1.
wa2-field = wa-field
append wa2 to itab2.
clear wa.
endif.
if wa2-field <> wa-field.
delete itab2 where field = wa2-field.
wa2-field = wa-field.
clear wa.
else.
append wa to itab2.
endif.
endloop.