Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

detect duplicates in ITAB

Former Member
0 Kudos

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

11 REPLIES 11

Former Member
0 Kudos

Is urr data is numeric or alfanumeric

0 Kudos

hi alnoor,

the column is of type c.

thanks.

tyken

hymavathi_oruganti
Active Contributor
0 Kudos

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.

0 Kudos

Hi,

what if i have multiple duplicate entries meaning there are several entries with duplicates?

thanks.

former_member404244
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

whats watab1?

0 Kudos

Workarea with the same linetype as if itab

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.