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: 

Internal table Issue ( very urgent)

Former Member
0 Kudos

Hi,

There are two internal tables A and B.

Product is one of the fields of both A and B and is the key.

A has say say 10 products and B has 4 products.

I want to delete those products from A which are not there in B.

( It is somewhat like using 'FOR ALL ENTERIES IN ' with Select Statement)

Is this possible in internal tables without 'Loop at'. The actual table would have over 1 million records and and looping is a major concern.

I am new to abap and any help from you guys would be appreciated.....

5 REPLIES 5

Former Member
0 Kudos

Advait,

I think you will need atleast one loop. This loop can be on the table B.

If product is the <b>left most field</b> of table B try this:

The last field for table A must be a flag for don't delete

SORT IT_B by product.

LOOP AT IT_B INTO WA_B.
AT NEW product.
WA_A-dont_delete = 'X'.
MODIFY IT_A FROM WA_A TRANSPORTING dont_delete WHERE product = wa_b-product.  
ENDAT.
ENDLOOP.

DELETE IT_A WHERE dont_delete <> 'X'.

Former Member
0 Kudos

Hi

What is wrong to loop the Internal table even if one million records are there.

If it is a database table using in a Loop there will be some problem.

do like this

data l_tabix type i.

sort itab1 by product.

sort itab2 by product.

loop at itab1. (having more records and some to be deleted)

l_tabix = sy-tabix.

read table itab2 with key product = itab1-product binary search.

if sy-subrc = 0.

delete itab1 index l_tabix.

endif.

endloop.

Regards

Anji

Former Member
0 Kudos

Thanks Srihari and Anji for your quick replies.....

I was concerned about looping because of performance reasons

0 Kudos

Looping on an internal table will not eat into your program run time as much as an non - optimized select will do.

However, It is good to avoid unnecessary loops on an internal table as well. In this case you really can help but loop into the table. What you can try to do is check hoe the rest of your code works, and figure out if you can perform these operations in one of the other loops you might have already written.

Regards,

Srihari

Former Member
0 Kudos

Hi,

You can use like this,

Declare another internal table C of type A.

select * from A

into table C

for all entries in B

where product = B-product.

Regards,

Sheron