Skip to Content
author's profile photo Former Member
Former Member

Exiting a loop within a loop

Howdy again,

Just a quick question:

I've got the following loop:

<b>loop at bool_data-bseg into bseg.

check bseg-bukrs = '4001'.

loop at itab_setleaf_type.

check bkpf-blart LE itab_setleaf_type-valto.

endloop.

loop at itab_setleaf_vend.

check bseg-lifnr LE itab_setleaf_vend-valto.

endloop.

endloop.</b>

for the two loops within the main loop I weant the program to go onto the next record in the main loop.

Would using check do this - I don't think so...

Does anyone know a command that would?

Thanks!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 10, 2005 at 04:32 PM

    As Jeet pointed out, EXIT inside a LOOP will terminate the LOOP and continue executing at the next statement following ENDLOOP.

    For reference, I will call your loops - 1, 2 and 3.

    So in loop 2, if you EXIT, then execution would continue with loop 3.

    If you want the EXIT in loop 2 to skip loop 3 and continue loop 1, then you will need a flag.

    For example:

    LOOP 1
    Flag = 'Y'.
      LOOP 2.
        IF ...
          Flag = 'N'.
          EXIT.
        ENDIF.
      ENDLOOP.
      IF Flag = 'N'.
        CONTINUE.
      ENDIF.
      LOOP 3.
        IF ...
          EXIT.
        ENDIF.
      ENDLOOP.
    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 10, 2005 at 04:13 PM

    Hello,

    The following code will take away lots of performance.

    First of all you can use LOOP AT ITAB where <Condn>

    Then the CHECK can be replaced by IF ... ENDIF.

    Please derive the program logic as per the need. I hope the above points helps you.

    Regards, Murugesh AS

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 10, 2005 at 04:21 PM

    Steve,

    I agree with Murugresh on the performance part.As far as coming out of inner loop use EXIT statement with if conditions. (Will come out only from inner loop.)

    Jeet

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.