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: 

exit while in loop

prince_isaac
Active Participant
0 Kudos

hie guys

i am looping at two internal tables and want to exit through an if statement when a condition specified is not met however the code exits both loops.

loop at itab1.

loop at itab2.

if itab2-value eq 0.

exit.

else.

process.

endif.

endloop.

endloop.

however its not behaving as such..i have tryed to use return statement but it still wont work. i have verified my entries and the conditions exist to be true for some entries ie itab2-value ne 0 but the program exists. please assist.

regards.

Isaac Prince

6 REPLIES 6

Former Member
0 Kudos

Hi,

Instead of EXIT statement you can move it to the where clause of the loop statement..

loop at itab1.
loop at itab2 WHERE value NE 0.
process.

endloop.
endloop.

Thanks

Naren

0 Kudos

hie Naren,

i also have some events during the loop like:

loop at itab1.

loop at itab2.

at new value.

process.

endat.

at last value.

add value to total_value.

endat.

endloop.

if total_value eq 0.

exit.

esle.

write values on screen.

endif.

endloop.

could the events be the cause??

0 Kudos

Hello,

Since you have EXIT in the outer loop, control is coming out of both the loops.

loop at itab1.

loop at itab2.

at new value.

process.

endat.

at last value.

add value to total_value.

endat.

endloop.

if total_value eq 0.

exit. <----


Exit in outer loop

esle.

write values on screen.

endif.

endloop.

Former Member
0 Kudos

Hi,

If you have events..then you cannot use WHERE...

but in your last post...if you have mentioned the EXIT statement after the inner loop...that is the reason why it is exiting out of both the loops..

Thanks

Naren

Former Member
0 Kudos

YOU CAN USE IT

BUT THE SECOND TABLA MUS BE SORTED

LOOP AT T_DOCTOS_WORK.

T_DOCTOS_FINAL-BELNR_PAGO = T_DOCTOS_WORK-BELNR.

T_DOCTOS_FINAL-BUDAT_CONCILIA = T_DOCTOS_WORK-AUGDT.

T_DOCTOS_FINAL-BUDAT_PAGO = T_DOCTOS_WORK-BUDAT.

**********************************************************************

      • Se tratan las partidad del proveedor

**********************************************************************

READ TABLE T_DOC_BSIK_BSAK WITH KEY

AUGGJ = T_DOCTOS_WORK-GJAHR

AUGBL = T_DOCTOS_WORK-BELNR

BINARY SEARCH.

IF SY-SUBRC EQ 0.

INDEXK = SY-TABIX.

DO .

READ TABLE T_DOC_BSIK_BSAK INDEX INDEXK.

IF T_DOC_BSIK_BSAK-AUGGJ NE T_DOCTOS_WORK-GJAHR OR

T_DOC_BSIK_BSAK-AUGBL NE T_DOCTOS_WORK-BELNR OR

SY-SUBRC NE 0.

EXIT.

ELSE.

INDEXK = INDEXK + 1.

*MAKE YOUR CODE

ENDIF.

ENDDO.

ENDIF.

ENDLOOP

prince_isaac
Active Participant
0 Kudos

hi

thnx all you guys for yo contributions..Nareen i owe u..i would have to try yo suggestions wen in office 2mrw..points have been awarded..