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: 

Duplicates

Former Member
0 Kudos

Hi,

I want to find the duplicates in an internal table...Does anyone have sample code for this?

Thanks.

2 REPLIES 2

Former Member
0 Kudos

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

ferry_lianto
Active Contributor
0 Kudos

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