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

Problem with Loop index.....

Former Member
0 Likes
587

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.

3 REPLIES 3
Read only

Former Member
0 Likes
545

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...

Read only

Former Member
0 Likes
545

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

Read only

0 Likes
545

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