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: 

How to delete entries from a itab using values in another itab?

Former Member
0 Kudos
285

Hi All,

I am having two internal tables itab1, itab2 with one common field. Also two tables contains some records, what i want is to delete the entries from itab1 which are not in itab2.

Example:

itab1

A B C

1 a b

2 z a

3 e t

4 d r

itab2

A D E

1 s d

3 f g

After the deletion itab1 should only contain records 1 & 3.

I know we can do this using loop and read, but i want to know if there is someother better way to do this...

Thanks in advance...

Regards

Karthik D

1 ACCEPTED SOLUTION

Former Member
0 Kudos
49

Hi,

Do like this.

Loop at itab2 into wa2.

read table itab1 into wa1 with key field1 = wa2-field1.

if sy-subrc NE 0.

delete itab1 from wa1.

endif.

endloop.

Regards,

Satish

4 REPLIES 4

Former Member
0 Kudos
50

Hi,

Do like this.

Loop at itab2 into wa2.

read table itab1 into wa1 with key field1 = wa2-field1.

if sy-subrc NE 0.

delete itab1 from wa1.

endif.

endloop.

Regards,

Satish

Former Member
0 Kudos
49

Hi Karthik ,

One of the options if to loop on the table and see if the entry exists in the other table , if it does not exist the delete the entry.

Regards

Arun

Former Member
0 Kudos
49

Hi Karthik,

this code should do it.

data : temp type sy-tabix.

clear temp.

loop at itab1. "if internal table with header line

temp = sy-tabix.

read table itab2 with key A = itab1-A.

if sy-subrc = 4.

delete itab index temp.

endif.

endloop.

*else if without header line

data : temp type sy-tabix.

clear temp.

loop at itab1 into wa_itab1. "if internal table is without header line

temp = sy-tabix.

read table itab2 with key A = itab1_wa-A into wa_itab2.

if sy-subrc = 4.

delete itab index temp.

endif.

endloop.

0 Kudos
49

Hi anurag,

Thanks for your help...

I know this way and just wanted to know whether there is anyother way is there.

Anyhow your way of explanation is fine....

Regards

KArthik D