‎2007 Dec 13 11:22 AM
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
‎2007 Dec 13 11:28 AM
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
‎2007 Dec 13 11:27 AM
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
‎2007 Dec 13 11:45 AM
‎2007 Dec 13 11:28 AM
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
‎2007 Dec 13 11:54 AM
‎2007 Dec 13 12:03 PM
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.
‎2007 Dec 13 12:13 PM
this will not work as the where clause will not validate for all entries in the internal table ditab
‎2007 Dec 13 12:24 PM
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.
‎2007 Dec 13 11:31 AM
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.
‎2007 Dec 13 11:49 AM
here the issue will be on performance as my db hit will get 10000+