Former Member

To exit from a loop

Dear all,

The structure of my code is as follows :-

LOOP AT ITAB. (1)

.....

....

DO. (2)

....

....

DO. (3)

....

....

IF I > 2.

....GOT TO NEXT LOOP PASS (1).

ENDIF.

ENDDO.

ENDDO.

ENDLOOP.

Which statement can I use to get out of the two DO loops and go to the next Loop pass of LOOP (1).

Archana

10|10000 characters needed characters exceeded

Related questions

Posted on Oct 13, 2005 at 07:02 AM

Hi Archana!

Easiest way: make a flag for this:

```data next_loop type xflag.
loop at itab.
clear next_loop.
do.
do.
if ...
next_loop = 'X'.
exit. (3)
endif.
enddo.
if next_loop = 'X'.
exit.   (2)
endif.
enddo.
if next_loop = 'X'.
continue. (1)
endif.
... (optional coding)
endloop.
```

Regards,

Christian

10|10000 characters needed characters exceeded
• Former Member

Hi Christian,

Thanx so much....

Ur solution has solved my problem...

have rewarded u the points as well...

• Former Member
Posted on Oct 13, 2005 at 07:03 AM

Hi Archana,

There is not one statement to get out of the innermost DO-loop and the outermost DO-loop at once.

You will have to program 2 consecutive EXITs (one for each DO-ENDDO) to accomplish this.

Regards,

John.

10|10000 characters needed characters exceeded
• Former Member
Posted on Oct 13, 2005 at 07:03 AM

Hi Archana,

You can use CONTINUE to come out of the current loop.

DO 100 TIMES.

IF SY-INDEX >= 10 AND SY-INDEX <= 20.

CONTINUE.

ENDIF.

...

ENDDO.

if solution is helpful kindly reward the points

10|10000 characters needed characters exceeded
• Former Member
Posted on Oct 13, 2005 at 07:03 AM

Hi,

U can use EXIT or STOP Statement.

Simple example of a DO loop:

DO.

WRITE SY-INDEX.

IF SY-INDEX = 3.

EXIT.

ENDIF.

ENDDO.

The output is:

1 2 3

http://help.sap.com/saphelp_erp2004/helpdata/en/fc/eb3564358411d1829f0000e829fbfe/frameset.htm>

Thanks&Regards,

Ruthra

10|10000 characters needed characters exceeded
• Former Member
Posted on Oct 13, 2005 at 07:03 AM

There is no single staemant you can use - you can EXIT to extr to DO-LOOP. But to go to the next LOOP you have to use CONTINUE.

Define a help-variable ex. l_exit and set this to TRUE if you want to exit and check for this.

10|10000 characters needed characters exceeded
• Former Member
Posted on Oct 13, 2005 at 07:04 AM

Hi!

The idea is the following - place DO(2) and DO(3) loops inside separate FORMS and handle return parameters from them bottom-up.

Regards,

Maxim.