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

helpppppp

Former Member
0 Likes
837

i make new tread hoping that i could get new response

i have a an internal table with 10 field (field1, field2, field3 ...)

i need to retreive duplicate record as per the the first 5 field (that is by field 1 , 2 ,3 , 4 , 5) .

i don't want to use at new or at end

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
818

Hi,

You can do as below :


"Declare two internal tables similar to actual internal table.

itab2 [] = itab1 [].

sort itab1 by f1 f2 f3 f4 f5.

sort itab2 by f1 f2 f3 f4 f5.

loop at itab1.

read table itab2 with key f1 = itab1-f1
                                    f2 = itab1-f2
                                    f3 = itab1-f3
                                    f4 = itab1-f4
                                    f5 = itab1-f5.

if sy-subrc eq 0.
  itab3 = itab1.
  append itab3.
  clear itab3.
endif.

endloop.

Thanks,

Sriram Ponna.

7 REPLIES 7
Read only

Former Member
0 Likes
818

hi,

DELETE ADJACENT DUPLICATES FROM itab

COMPARING f1 .. fn

The system deletes all adjacent entries with the same key field contents apart from the first entry.

You can prevent the system from only comparing the key field using the COMPARING addition. If you sort

the table by the required fields beforehand, you can be sure that only unique entries will remain in the

table after the DELETE ADJACENT DUPLICATES statement.

You can use this in your code, and compare the work area and the internal table. Pass the fields you want to compare in comparing syntax.

In the COMPARING addition, the system compares the field contents of a data record with those in the

work area for equality.

Hope this helps, Do reward.

Edited by: Runal Singh on Mar 11, 2008 4:51 PM

Edited by: Runal Singh on Mar 11, 2008 4:52 PM

Read only

former_member386202
Active Contributor
0 Likes
818

Hi,

First sort ur internal table

and then use delete adjacent duplicates

sort itab by field1.

delete adjacent duplicates from itab comparing field1.

Regards,

Prashant

Read only

Former Member
0 Likes
818

Let the internal table u have with u be itab1.

Data itab2 like table of itab1 with header line.

Data itab3 like table of itab1 with header line.

itab2[] = itab1[].

sort itab2 by field1 field2 field3 field4 field5.

delete adjacent duplicates from itab2 comparing field1 field2 field3 field4 field5.

loop at itab1.

read table itab2 with key field1 = itab1-field1

field2 = itab1-field2

field3 = itab1-field3

field4 = itab1-field4

field5 = itab1-field5.

if sy-subrc =0.

append itab1 to itab3.

endif.

endloop.

*Now we have the duplicate entries in itab3...

Reward points if useful

Thanks Arjun

Read only

Former Member
0 Likes
818

sort itab by f1 f2 f3 f4 f5.

loop at itab.

v_counter = v_counter + 1.

If v_counter = 1.

itab1 = itab.

endif.

If v_counter > 1.

if itab-f1 = itab1-f1 and

itab-f2 = itab1-f2 and

itab-f3 = itab1-f3 and

itab-f4 = itab1-f4 and

itab-f5 = itab1-f5.

itab3 = itab.

append itab3.

clear itab3.

else.

clear: itab1 , v_counter.

endif.

endif.

endloop.

itab3 has duplicate records ...

Read only

Former Member
0 Likes
819

Hi,

You can do as below :


"Declare two internal tables similar to actual internal table.

itab2 [] = itab1 [].

sort itab1 by f1 f2 f3 f4 f5.

sort itab2 by f1 f2 f3 f4 f5.

loop at itab1.

read table itab2 with key f1 = itab1-f1
                                    f2 = itab1-f2
                                    f3 = itab1-f3
                                    f4 = itab1-f4
                                    f5 = itab1-f5.

if sy-subrc eq 0.
  itab3 = itab1.
  append itab3.
  clear itab3.
endif.

endloop.

Thanks,

Sriram Ponna.

Read only

vinod_vemuru2
Active Contributor
0 Likes
818

HI,

Check this

SORT itab BY f1 f2 f3 f4 f5.

LOOP AT i_tab INTO wa_tab.

CLEAR w_value.

w_value = wa_tab-f1.

CHECK wa_tab-f1 EQ w_value

AND wa_tab-f2 EQ w_value

AND wa_tab-f3 EQ w_value

AND wa_tab-f4 EQ w_value

AND wa_tab-f5 EQ w_value.

Do ur processing

ENDLOOP.

I sugest u to go with first solution which is more efficient and proper.

Regards,

Vinod.

Edited by: Vinod Kumar Vemuru on Mar 11, 2008 5:03 PM

Read only

Former Member
0 Likes
818

hye..

This can be achieved using a loop inside a loop.

  • create an internal table with the fields u want to compare.

data: begin of it_compare,

fld1....

fld2...

end of it_compare.

  • itab is the original table from which data is collected and it_out is the table which has the duplicate entries collection.

loop at itab into wa.

move-corresponding itab[] to it_compare.

endloop.

loop at itab into wa.

loop at it_compare into wa_compare.

if ( wa_compare-fld1 = wa-fld1and

wa_compare-fld2 = wa-fld2 and...)

count = count + 1.

endif.

if count > 1.

append wa into it_out.

exit.

endif.

endloop.

endloop.

hope this works, reward if found helpful.

Thanks,

Imran.