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

abt conditional statements

former_member223446
Active Participant
0 Likes
605

hi all

difference between exit check continue stop.

thanks in advance

kiran

4 REPLIES 4
Read only

Former Member
0 Likes
577

EXIT.

Gets you out of the current processing block.

INside a loop, if would get you out of the loop(Even if it is inside some processing block inside the loop).

In start-of-selection event, it gets you out of the program.

check.

it would get you out of the current processing block if condition is met.

continue.

Goes to the next loop pass.

stop.

comes out of the start-of-selection event and goes to the first statement of end-of-selection.

Regards,

Ravi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
577

Taken from F1 help.

<i>

Terminating Loops

ABAP contains termination statements that allow you to terminate a loop prematurely. There are two categories of termination statement - those that only apply to the loop, and those that apply to the entire processing block in which the loop occurs. The STOPand REJECT statements belong to the latter group (see Exiting Eventblocks).

The termination statements that apply only to the loop in which they occur are CONTINUE, CHECKand EXIT. You can only use the CONTINUE statement in a loop. CHECK and EXIT, on the other hand, are context-sensitive. Within a loop, they only apply to the execution of the loop itself. Outside of a loop, they terminate the entire processing block in which they occur (subroutine, dialog module, event block, and so on).

CONTINUE, CHECK and EXITcan be used in all four loop types in ABAP (DO, WHILE, LOOP and SELECT).

Terminating a Loop Pass Unconditionally

To terminate a single loop pass immediately and unconditionally, use the CONTINUE statement in the statement block of the loop.

CONTINUE.

After the statement, the system ignores any remaining statements in the current statement block, and starts the next loop pass.

DO 4 TIMES.

IF sy-index = 2.

CONTINUE.

ENDIF.

WRITE sy-index.

ENDDO.

The list output is:

1 3 4

The second loop pass is terminated without the WRITE statement being processed.

Terminating a Loop Pass Conditionally

To terminate a single loop pass conditionally, use the CHECK condition statement in the statement block of the loop.

CHECK condition.

If the condition is not true, any remaining statements in the current statement block after the CHECK statement are ignored, and the next loop pass starts. condition can be any logical expression.

DO 4 TIMES.

CHECK sy-index BETWEEN 2 and 3.

WRITE sy-index.

ENDDO.

The list output is:

2 3

The first and fourth loop passes are terminated without the WRITE statement being processed, because sy-index is not between 2 and 3.

Exiting a Loop

To terminate an entire loop immediately and unconditionally, use the EXIT statement in the statement block of the loop.

EXIT.

After this statement, the loop is terminated, and processing resumes after the closing statement of the loop structure (ENDDO, ENDWHILE, ENDLOOP, ENDSELECT). In nested loops, only the current loop is terminated.

DO 4 TIMES.

IF sy-index = 3.

EXIT.

ENDIF.

WRITE sy-index.

ENDDO.

The list output is:

1 2

In the third loop pass, the loop is terminated before the WRITE statement is processed.

</i>

Regards,

Rich Heilman

Read only

RaymondGiuseppi
Active Contributor
0 Likes
577

Within a loop structure:

<b>EXIT</b> Within a loop structure: Terminates loop processing (DO, WHILE, LOOP, SELECT).

Within subroutines and other modularization units (but not in a loop structure):

Leaves the subroutine or modularization unit (FORM, MODULE, FUNCTION, TOP-OF-PAGE, END-OF-PAGE).

Outside loop structures and modularization units (report processing):

Terminates report processing and triggers list display.

<b>CONTINUE</b> Within loop structures, terminates the current loop pass, returns the processing to the beginning of the loop and starts the next loop pass, if there is one.

<b>CHECK</b> if condition is true, the processing continues with the next statement else work like CONTINUE.

<b>STOP</b> This statement terminates a processing block in an executable program.(exit from an INITIALIZATION, AT SELECTION-SCREEN, START-OF-SELECTION, and GET events and go to END-OF-SELECTION) better use EXIT

Regards

Read only

former_member223446
Active Participant
0 Likes
577

thanks for ur reply