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: 

delete rec in itable2 which are not present in itable1

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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>

5 REPLIES 5

suresh_datti
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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>

0 Kudos

Hello Tanver & Suresh,

which is better, looping on itable2 or itable1? assuming that itable2 would be greater than itable1

please suggest.

Thanks,

BWer

0 Kudos

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

0 Kudos

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