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

Exit statement

Former Member
0 Likes
1,021

Hi

Based on the condition, how to block the execution of the statement following the condition

Cheers

Christina

1 ACCEPTED SOLUTION
Read only

former_member673464
Active Contributor
0 Likes
997

hi,

You can try like this.

Exiting a Loop

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

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 output is:

1 2

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

regards,

Veeresh

10 REPLIES 10
Read only

Former Member
0 Likes
997

Hi,

Use CHECK statement.

For more details check this link:

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9afe35c111d1829f0000e829fbfe/content.htm

Regards

Adil

Read only

former_member673464
Active Contributor
0 Likes
998

hi,

You can try like this.

Exiting a Loop

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

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 output is:

1 2

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

regards,

Veeresh

Read only

Former Member
0 Likes
997

hi,

Use Check statement ...


check v_value ne 0.

Refer

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/check.htm

Read only

Former Member
0 Likes
997

Hi,

If ur in a loop u can exit from the loop.

else u can use IF or CHECK conditions.

Anju

Read only

former_member195383
Active Contributor
0 Likes
997

Simply use the if endif statement..

if <Condition>.

statement.

endif.

Read only

Former Member
0 Likes
997

Hi,

You can Use EXIT or STOP Satement To Execute The Next statement to be Executed.

In Case of EXIT it does not trigger END-OF-SELECTION.

But in case of STOP It do that display the Output before STOP.

Regards,

Sujit

Read only

Former Member
0 Likes
997

Hi,

We have commands like EXIT, CHECK, STOP,CONTINUE to control the flow of the execution.

Please read the help for the above conditions and use according to your requirement.

Read only

Former Member
0 Likes
997

Hi Christina,

U can check the condition with IF Condition and depending on the condition u can use EXIT to block the execution of the ststements.

or

You can use CHECK statement.

Best regards,

raam

Read only

Former Member
0 Likes
997

Hi

Try using TRY Block,CATCH Block,CLEANUP Block. In this you can catch the exception which need not be executed and catch it using CATCH BLOCK and for prevent it from being executed use CLEAN UP BLOCK.

Regards

Divya

Read only

Former Member
0 Likes
997

Hello

1. If condition is simple, use check.

ex: check sy-subrc = 0.

2. If condition is complex, use exit.

ex:

if cond1 > 0 and cond2 > 0 and cond3 > 0.

exit.

endif.