Application Development and Automation 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: 
Read only

Internal table

prabhu_s2
Active Contributor
0 Likes
764

Hi Experts

PS: I'm trying to avoid nested loops.

I want to delete contents on an internal table at one shot wihtout looping. Hence i used the following

delete itab where matnr not in ditab.

here ditab is another internal table but this doesnt work as it is not in the strucutre of RANGES (error in syntx check)

Is there a way to acheive this functionality without nested loops?

thkx

Prabhu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
748

You could Loop at itab and use the WHERE clause to resctict iterations based on ditab

i.e you will only loop at itab where the current entry is not in ditab

9 REPLIES 9
Read only

former_member386202
Active Contributor
0 Likes
748

Hi,

Do like this

data : lv_index type sy-index.

Loop at itab.

lv_index = sy-tabix.

read table ditab with key matnr = itab-matnr

binary search.

if sy-subrc NE 0.

delete itab index lv_index.

endif.

endloop.

Regards,

prashant

Read only

0 Likes
748

yep this will work ut i dont wanna to use read either.....

Read only

Former Member
0 Likes
749

You could Loop at itab and use the WHERE clause to resctict iterations based on ditab

i.e you will only loop at itab where the current entry is not in ditab

Read only

0 Likes
748

yep that right but again nested loops comes here

Read only

0 Likes
748

Sorry, correction to my last post you would do some thing like this

LOOP AT itab WHERE matnr = ditab-matnr.

do some logic here . . .

ENDLOOP.

you can avoid looping (nested loop) at ditab with this code (provided ditab is filled with data)

Regards,

Conor.

Read only

0 Likes
748

this will not work as the where clause will not validate for all entries in the internal table ditab

Read only

0 Likes
748

Fair enough but, I wouldnt use FOR ALL ENTRIES in ditab.

you want to delete entried from itab if they are in ditab with some like

DELETE itab FOR ALL ENTRIES IN ditab.

and then I presume you will LOOP through the reduced itab . . .

so what I'm saying is that the where clause used with with the LOOP will do that same thing as your DELETE then LOOP (wouldn't used the FOR ALL ENTRIES after the WHERE clause in the LOOP)

Its just another way of doing the same thing, mabe you want to reduce program memory, not sure

regards ,

Conor.

Read only

Former Member
0 Likes
748

hi,

try to populate ranges before loop...like


RANGES : s_matnr FOR marc-matnr.
LOOP AT ditab.
  s_matnr-low = ditab-matnr.
  s_matnr-option ='EQ'.
  s_matnr-sign = 'I'.
  APPEND s_matnr.
ENDLOOP.

DELETE itab WHERE matnr NOT IN s_matnr.

Read only

0 Likes
748

here the issue will be on performance as my db hit will get 10000+