‎2009 Mar 13 5:55 AM
Dear All,
I have one internal table with 10000 records . I want to read a specific record with certain WHERE clause with logical operators.
Now my requirement is that as soon as that condition is satisfied ,
>control should go to NEXT STATEMENT AFTER Endloop BUT NOT to the next loop pass so that it will not read
>remaining entries.
Using EXIT takes us to Next Loop Pass which I want to avoid and come out of the LOOP ..ENDLOOP,
Using READ TABLE does not allow logical operators like NE, GT,LE...
What can be done? Suggestions are most welcome.
Thanks...........
Edited by: Matt on Mar 13, 2009 8:21 AM - fix formatting
‎2009 Mar 13 5:58 AM
Try using STOP inside the loop...endloop.Stop will come out of the loop.
Also try settings Flag at appropriate place if not working paste the codes.
Regards,
Gurpreet
‎2009 Mar 13 5:58 AM
Try using STOP inside the loop...endloop.Stop will come out of the loop.
Also try settings Flag at appropriate place if not working paste the codes.
Regards,
Gurpreet
‎2009 Mar 13 5:59 AM
you can use a flag and write exit and once that loop exits and comes to another loop..
now check the flag again and if the falg is on,then exit again...
this should serve the purpose..
loop 1
loop2
flag = X
EXIT
endloop
if flag = 'x'
EXIT
endif
Endloop
endloop
Edited by: Sravan Kumar on Mar 13, 2009 7:00 AM
‎2009 Mar 13 6:00 AM
Hi,
EXIT statement , if used inside a loop..will exit the loop and will goto the next statment after the endloop statement. Please check if u are using a nested loop like loop endloop inside another loop endloop.
It works perfect for one of my programs.
see the code below..
data: itab type table of spfli,
wa type spfli,
itab1 type table of sflight.
select * from spfli into table itab
where carrid like 'A%'.
loop at itab into wa where carrid = 'AA'.
write:/ wa-carrid.
exit.
endloop.
write:/ wa-connid.
Keerthi.
Edited by: Keerthy K on Mar 13, 2009 7:02 AM
‎2009 Mar 13 6:01 AM
Hi;
Put
LOOP where <condition>.
ENDLOOP
Next Condition
LOOP would continue till the condition meets and would be in next condition,
Regards
Shashi
‎2009 Mar 13 6:04 AM
do it this way..
loop itab into wa_tab.
if wa-tab-matnr = 'XYZ'. " Write Where Logic in If condition instaed of where in loop.
exit.
endif.
endloop.
‎2009 Mar 13 6:08 AM
Use Check like
loop at itab.
check bbb <> ' '.
endloop.
where bbb is a field of itab. when bbb will be blank the loop terminates.
Hope it solve your problem.
Regards.
Sarbajit
‎2009 Mar 13 7:20 AM
>
> Use Check like
>
> loop at itab.
> check bbb <> ' '.
> endloop.
>
> where bbb is a field of itab. when bbb will be blank the loop terminates.
>
> Hope it solve your problem.
>
> Regards.
>
> Sarbajit
WRONG
CHECK cond works like
IF cond.
CONTINUE.
ENDIF.
‎2009 Mar 13 7:38 AM
Hi Matt
I mean by the follwing code
loop at itab.
check itab-bbb = ' ' .
endloop.
The loop iterates as long as the check condition will be true. But terminates loop iteration if the check condition become false. Is it Wrong?
Please Reply.
What you have written CHECK = IF Continue ENDIF that is true also.
regards.
sarbajit.
‎2009 Mar 13 6:19 AM
Hi,
Here you can use exit.
Actually in a loop:
exit --> execution goes out of loop, to statement next to endloop
continue --> execution goes to next loop phase
stop --> it acts a exit but in reports execution will go to next event.
Regards.
‎2009 Mar 13 6:33 AM
You can use EXIT statement here.
Loop at itab .
If <Condition>.
Exit.
Endif.
Endloop.
Regards,
Joan
‎2009 Mar 13 7:03 AM
Hi,
Use EXIT in the loop. EXIT dose not take you to next loop pass but it takes you out of loop. CONTINUE takes you to next loop pass.
Regards,
Pranaya
‎2009 Mar 13 7:15 AM
Hi,
EXIT statement is the most recommended option fr your problem.
When EXIT is encountered, control comes out of the loop to the next statement after ENDLOOP. On contrary, CONTINUE statement goes to the next pass of the loop.
Try EXIT. It will solve your problem.
Regards,
Vishal.
‎2009 Mar 13 7:24 AM
If you need to cascade an exit from an inner loop, you should do it like this.
LOOP AT itab1.
LOOP AT itab2.
LOOP AT itab3.
IF cond.
l_exit_flag = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF l_exit_flag IS NOT INITIAL.
EXIT.
ENDIF.
ENDLOOP.
IF l_exit_flag IS NOT INITIAL.
EXIT.
ENDIF.
ENDLOOP.EXIT does NOT force a new loop iteration.
‎2009 Mar 13 7:42 AM
Hi Ubhaka
The exit statement takes you out of the current loop.You can set some flag(in the first loop) when your condition is satisfied and can come out of any number of loops-simplest of all .Also using stop will take you to the end of selection event.It all depends on your reqirement.Word of caution-Check and stop will not set the sy-subrc.If you want to use it set numeric value to it before exiting.Hope this solve your query.
Regards.
‎2009 Mar 17 4:23 AM