‎2010 May 15 5:05 AM
Hi Experts,
i have a problem with Loop index, bcoz i am using Loop inside Loop, i know we cant use loop under loop, but as per my requirement i need to use loop under loop.
my code is like:
Loop AT itab1 into wa_itab1.
read table table it_header into wa_header with key field1 = wa_itab1-field1.
if sy-subrc = '0'.
Loop AT itab2 into wa_itab2 where field2 = wa_header-field2.
here processing logic........
delete itab2 from wa_itab2. ( or) del the specific record from ITAB1.
Modify itab1 from wa_itab1 TRANSPORTING FIELD3.
endloop.
endif.
endllop.
Here my requirement is from ITAB1 allways i need to loop first, since i am modifying or delete the records from ITAB1.
from ITAB1 in second loop also i neeed to pic first record, But here prob is 2nd time SY-TABIX becoming 2,
so How to make SY-TABIX should be 1.
i have checked like Loop AT itab1 into wa_itab1 FROM '1'. ( also not working).
can anyone give me the logic.....
Regards,
Sudha.
‎2010 May 15 6:04 AM
As per my understanding u have to delete/ modify the specific index of ITAB1,
For this you have to declare one variable of type SY-tabix, then u have to assign the current index to it
and at the specified condition u can perform ur operation
using:
delete itab1 index ..................
modify itab1 index ... transporting...
‎2010 May 15 6:13 AM
HI Sudha,
data : tabix type sy-tabix. " add this one
Loop AT itab1 into wa_itab1.
read table table it_header into wa_header with key field1 = wa_itab1-field1.
if sy-subrc = '0'.
*Loop AT itab2 into wa_itab2 where field2 = wa_header-field2." avoid this loop with read table
read table itab2 into wa_itab2 with key field2 = wa_header-field2.
if sy-subrc = 0.
* here processing logic........
delete itab2 index sy-tabix." ( or) del the specific record from ITAB1.
DELETE ITAB2 WHERE FIELD2 = WA_HEADER-FIELD2 " Incase you want to delete multiple records
endif,
*endloop." Avoid this one
endif.
" Unless you modify WA_ITAB1 you dont required this modify statement
" Since you are not changing FIELD3 of WA_ITAB1 you dont need to modify this ITAB1
Modify itab1 from wa_itab1 TRANSPORTING FIELD3. " This should be in First LOOP only
endllop.Cheerz
Ram
‎2010 May 15 7:41 AM
Hi Ram, Thank you for your replay..
but here the itab2 should repeat multiple times until the cond is satisfied. if i use Read stat it cant repeat right...
if wa_header-load_qt > 0.
Loop AT itab2 into wa_itab2 where field2 = wa_header-field2. ( should repeat multiple times)
here processing logic........
delete itab2 from wa_itab2. ( or) del the specific record from ITAB1.
Modify itab1 from wa_itab1 TRANSPORTING FIELD3.
endloop.
endif.
Edited by: sudhasumathi on May 15, 2010 8:43 AM