06-06-2006 4:02 AM
Hello ABAP Experts,
situation:
1) itable1.field1 contains A,B,C
2) itable2.field1 contains B,D,E
i should be in a position to delete records with the D and E entries from itable2 ( because they are not there in itable1)
any suggestions for code highly appreciated.
Thanks,
BWer
06-06-2006 4:16 AM
Hi,
Sort itab1 by field1.
Sort itab2 by field1.
loop at itab2 into wa_itab2.
read table itab1 with key field1 = itab2-field1 binary search.
if sy-subrc <> 0.
delete wa_itab2 from itab2.
endif.
endloop.
Regards,
Tanveer.
<b>Please mark helpful answers</b>
06-06-2006 4:06 AM
try this..
sort: itab1 by field1,itab2 by field1.
loop at itab2.
read table itab1 with key field1 = itab2-field1
binary search.
if sy-subrc ne 0.
delete itab2.
endif.
endloop.
Regards,
Suresh Datti
06-06-2006 4:16 AM
Hi,
Sort itab1 by field1.
Sort itab2 by field1.
loop at itab2 into wa_itab2.
read table itab1 with key field1 = itab2-field1 binary search.
if sy-subrc <> 0.
delete wa_itab2 from itab2.
endif.
endloop.
Regards,
Tanveer.
<b>Please mark helpful answers</b>
06-06-2006 4:19 AM
Hello Tanver & Suresh,
which is better, looping on itable2 or itable1? assuming that itable2 would be greater than itable1
please suggest.
Thanks,
BWer
06-06-2006 4:23 AM
You should loop at the table from which the entries are to be deleted.If yu think there could be duplicate entries, then use
delete adjacent duplicates from itab2 after the sort.
Regards,
Suresh Datti
06-06-2006 6:33 AM
sort itab1 by f_field1.
sort itab2 by f_field1.
delete adjacent duplicates from itab2.
loop at itab2.
read table itab1 with key f_field1 = itab2-f_field1
binary search.
if sy-subrc ne 0.
delete itab2.
endif.
endloop.
reward points if it helps
regds
gunjan