‎2005 Dec 15 1:36 AM
Hi,
I hav 2 internal tables with some values . I want to compare the 2 tables and elimate
duplicate entries.Wht logic i hav to use in looping ?
Rgds,
SAPUser100
‎2005 Dec 15 1:45 AM
Which internal table do you want to remove the duplicates from, the first, or second.
If it is ok to combined the internal tables into one. Then I would suggest this.
* Add the contents of itab2 to itab1.
Loop at itab2.
clear itab1.
move itab2 to itab1.
append itab1.
Endloop.
* Now get rid of the duplicate records.
delete adjacent duplicates from itab1.Regards,
Rich Heilman
‎2005 Dec 15 1:45 AM
Which internal table do you want to remove the duplicates from, the first, or second.
If it is ok to combined the internal tables into one. Then I would suggest this.
* Add the contents of itab2 to itab1.
Loop at itab2.
clear itab1.
move itab2 to itab1.
append itab1.
Endloop.
* Now get rid of the duplicate records.
delete adjacent duplicates from itab1.Regards,
Rich Heilman
‎2005 Dec 15 1:54 AM
Hi,
just a small correction... sort itab1 & then use the delete adjacent duplicates statement.
On the other hand, if you want to delete an entry in itab1 if it exists in itab2.. then it depends on the structure of the itabs. You can loop at one itab and read the other itab with key and delete the entry if
sy-subrc eq 0.
Regards,
Suresh Datti
Message was edited by: Suresh Datti
‎2005 Dec 15 1:55 AM
‎2005 Dec 15 2:02 AM
Sam's got the right idea if you want to delete the "duplicates" out of itab2. If it is the other way around, then you would do the same thing swapping the itab names. If you want to do get rid of the duplicates in both itabs and keep both itabs you will have to do it twice.
LOOP AT itab1.
READ TABLE itab2 WITH KEY val = itab1-val.
IF sy-subrc = 0.
DELETE itab2 INDEX sy-tabix.
ENDIF.
CLEAR: itab1,
itab2.
ENDLOOP.
LOOP AT itab2.
READ TABLE itab1 WITH KEY val = itab2-val.
IF sy-subrc = 0.
DELETE itab1 INDEX sy-tabix.
ENDIF.
CLEAR: itab1,
itab2.
ENDLOOP.Regards,
Rich Heilman
‎2005 Dec 15 10:57 AM
you can also give a field in the internal table
you want for your comparison:
delete adjacent duplicates from itab1 comparing table_line.
Regards,
Marc
‎2005 Dec 15 1:52 AM
you alsco can directly copy the data of one table to another:
<i>append lines of it1 [from nf] [to nt] to it2.</i>
then just do delete duplicate entries as above.
‎2005 Dec 15 1:53 AM
Is this what you want?
LOOP AT itab1.
READ TABLE itab2 WITH KEY val = itab1-val.
IF sy-subrc = 0.
DELETE itab2 INDEX sy-tabix.
ENDIF.
CLEAR: itab1,
itab2.
ENDLOOP.