Application Development and Automation 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: 
Read only

internal table issue

0 Likes
1,140

HI experts , how to pick the duplicates from the internal table . Pl see that i am not talking of delete adjacent duplicate.

any key word or function module is there in sap Abap.

Moderator message: please use more descriptive subject lines from now on.

Edited by: Thomas Zloch on Nov 30, 2010 11:53 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,102

Hi,

You would have to sort the table and then read the data one by one if there is another row with the same value.

eg: loop at itab into wa_tab.

read table itab into wa_tab2 with key field1 = wa_tab-field1.

if sy-subrc = 0.

count = count + 1.

endif.

endloop.

count will give you the no of duplicates. If you want the entries that are repeates you can append the data for wa_tab2 into an internal table.

Hope it help.

Thanks,

Anju

12 REPLIES 12
Read only

Former Member
0 Likes
1,102

Hi,

I don't think there is any FM in ABAP to do so.

Need to write the coding to check if there are any duplicates and get the same.

Regards,

Srini.

Read only

Former Member
0 Likes
1,103

Hi,

You would have to sort the table and then read the data one by one if there is another row with the same value.

eg: loop at itab into wa_tab.

read table itab into wa_tab2 with key field1 = wa_tab-field1.

if sy-subrc = 0.

count = count + 1.

endif.

endloop.

count will give you the no of duplicates. If you want the entries that are repeates you can append the data for wa_tab2 into an internal table.

Hope it help.

Thanks,

Anju

Read only

0 Likes
1,102

Thanks , but if you check sy-subrc it will definitely be 0 , since the field is present in itab. But what about the duplicate , even if the field is not duplicate sy-subrc will be 0.

Read only

Former Member
0 Likes
1,102

hi,

try it using at new field...in loop..

thanks..

balu

Read only

Former Member
0 Likes
1,102

Hi,

if its indexed table.,... sort it using the field...

loop at itab into wa_itabl.

if sy-tabix eq 1.

continue.

endif.

read itabl into wb_itabl index (sy-tabix-1). "sysntax might be wrong

if wb_itab1-field eq wa_itab1-field.

append wb_itabl-field into tab2.

endif.

endloop.

delte adjacnt duplicat entries in tab2.

now tab2 contains unique duplicate entires in itab1.

thanks,

srini

<removed by moderator>

Edited by: Thomas Zloch on Nov 30, 2010 12:57 PM - please not ask for ...

Read only

Former Member
0 Likes
1,102

Hi,

I dont know what exactly you want to do after finding the duplicate records , but you can use keyword

AT NEW


data : wfirst_rec type c.

sort itab by field1.

loop at itab.

at new field1.
" what ever logic you want to implement
endat.


endloop.

Regards,

Madhukar Shetty

Read only

Former Member
0 Likes
1,102

SORT itab BY ebeln.

LOOP AT itab INTO wa_tab.

AT NEW ebeln.

lv_counter = 1.

ENDAT.

IF lv_counter = 1.

MOVE-CORRESPONDING wa_tab TO wa_prev.

ELSEIF lv_counter = 2. " Its duplicate Record

APPEND wa_prev TO dup_tab.

APPEND wa_tab TO dup_tab.

ELSEIF lv_counter > 2. " Its duplicate Record

APPEND wa_tab TO dup_tab.

ENDIF.

lv_counter = lv_counter + 1.

AT END OF ebeln.

CLEAR : lv_counter, wa_prev.

ENDAT.

ENDLOOP.

Read only

himanshu_gupta2
Participant
0 Likes
1,102

hi

You can use the at new to find the dupicates.

loop at itab into wa.

at new field1 .

flag = 1.

endat.

Read only

himanshu_gupta2
Participant
0 Likes
1,102

hi

You can use the at new to find the dupicates.

loop at itab into wa.
flag = 2.
 at new field1 .
   flag =  1.
 endat. 

if flag = 2. 
 append wa into dup_itab.
endif. 

endloop.

This code will read all the duplicates records .

Read only

Former Member
0 Likes
1,102

just sort, loop the table watching the next registry

sort itab.
mirror_tab = itab.

loop at itab.
l_tabix = sy-tabix+1.
read table mirror_tab index l_tabix.

if itab-key = mirror_Tab-key.
" duplicate registry here.
endif.


endloop.

regards, Sebastian

Read only

Clemenss
Active Contributor
0 Likes
1,102

Hi obaid,

data:
  itab type table of mystructure, "this is your table
  itab_nodup type sorted table of mystructure with unique key table_line,
  itab_dup type table of mystructure.
field-symbols:
  <any> type any.
loop at itab assigning <any>.
  insert <any> into table itab_nodup.
  if sy-subrc <> 0.
    append <any> to itab_dup.
  endif.
endloop.

This will put the duplicates to itab_dup.

NEXT time use a subject.

Regards,

Clemens

Read only

Former Member
0 Likes
1,102

null

Edited by: BrightSide on Nov 30, 2010 12:54 PM

Edited by: BrightSide on Nov 30, 2010 12:56 PM