Application Development 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: 

exit

Former Member
0 Kudos

what is the difference in functionality between exit and continue.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sandeep,

Both work almost the same way when used in a loop but for a small differenct. Exit would get you out of the loop and continue processing the code which starts after the "Endloop" statement. But contrarily, continue statement would skip the following peice of code written within the loop after the continue statement and starts a new pass for the Loop statement.

"Exit" could be used not only in a loop. Any such usage outside the loop would enable the control to exit out of that logical processing block of code.

Reward points if this explains,

Kiran

7 REPLIES 7

Former Member
0 Kudos

Hi Sandeep,

Both work almost the same way when used in a loop but for a small differenct. Exit would get you out of the loop and continue processing the code which starts after the "Endloop" statement. But contrarily, continue statement would skip the following peice of code written within the loop after the continue statement and starts a new pass for the Loop statement.

"Exit" could be used not only in a loop. Any such usage outside the loop would enable the control to exit out of that logical processing block of code.

Reward points if this explains,

Kiran

Former Member
0 Kudos

Hi,

EXIT : Exits the entire loop and processes the statement after the Endloop

CONTINUE : skips the current loop pass. But it doesnot exit the loop.

Regards

Sourabh

Former Member
0 Kudos

Hi,

The CONTINUE statement can only be used in loops. If it is used, the current loop pass is ended immediately and the program flow is continued with the next loop pass.

Exits can be used in 4 places:

1) If the EXIT statement is listed within a loop, it leaves the loop by ending the current loop process. Program execution is continued after the closing statement in the loop.

2) If the EXIT statement is executed outside of a loop, it will immediately terminate the current processing block.

After the processing block has been executed, the runtime environment behaves in such a way that it follows with the exception Reporting Event Blocks START-OF-SELECTION and GET the schema from Leave Processing Blocks.

3)Incase of SQL : The statement has the effect that implicit cursor processing is terminated after the current subroutine has finished. Processing of the called ABAP program is continued after ENDEXEC, whereby sy-dbcnt contains the number of rows read up until that point and sy-subrc is set to the value 4.

4)During the processing of Table Controls or Steploops with the statement LOOP in the Dynpro-flow logic, this statement effects the immediate termination of the loop. The current ABAP- processing block is instantly left and the dynpro flow logic continues after the statement ENDLOOP. During the PBO-processing, the statement effects that the current and the following table-control-rows resp. steploop-groups are not displayed on the screen. If the statement is not processed during execution of a LOOP-loop in the dynpro flow logic, then the program terminates with a termination message.

Reward points if helpful.

Thanks and Regards.

Former Member
0 Kudos

Hi,

To exit out of the event blocks and the loops we will use exit command.

see these links for more info.

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9af135c111d1829f0000e829fbfe/content.htm

terminating the loop using exit

DO 10 TIMES.

IF sy-index = 3.

EXIT.

ENDIF.

WRITE sy-index.

ENDDO.

COntinue:

CONTINUE terminates the current loop pass, returns the processing to the beginning of the loop and starts the next loop pass, if there is one.

Example

DO loop: Omit an area (10 ... 20)

DO 100 TIMES.

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

CONTINUE.

ENDIF.

...

ENDDO.

Reward if useful

Thanks

Jagadeesh.G

Edited by: Jagadeshwar Gollapelly on Apr 17, 2008 2:51 PM

Former Member
0 Kudos

If you are using EXIT inside a process block(eg .loop endloop.)

control will exit from the process block.

If you are using CONTINUE inside a process block(eg .loop endloop.) then it will skip the remaining statements and control will go to the next itration .

Former Member
0 Kudos

Hi,

EXIT.

Within a loop structure:

Terminates looop 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.

DATA: SAP_COUNT TYPE I,

WA_T100 TYPE T100.

SELECT * FROM T100 INTO WA_T100 WHERE SPRSL = SY-LANGU AND

ARBGB = 'DS'.

WRITE / WA_T100-TEXT.

IF WA_T100-TEXT CS 'SAP'.

ADD 1 TO SAP_COUNT.

IF SAP_COUNT = 3.

EXIT.

ENDIF.

ENDIF.

ENDSELECT.

CHECK logexp.

CHECK evaluates the subsequent logical expression. If it is

true, the processing continues with the next statement.

In loop structures like

DO ... ENDDO

WHILE ... ENDWHILE

LOOP ... ENDLOOP

SELECT ... ENDSELECT

CHECK with a negative outcome terminates the current loop pass

and goes back to the beginning of the loop to start the next

pass, if there is one.

In structures like

FORM ... ENDFORM

FUNCTION ... ENDFUNCTION

MODULE ... ENDMODULE

AT events

GET events

CHECK with a negative outcome terminates the routine or

modularization unit.

If CHECK is neither in a loop nor a routine nor a

modularization unit, a negative logical expression terminates

the current event. In contrast, the statement REJECT terminates

the current event, even from loops or subroutines.

CONTINUE.

Within loop structures like

DO ... ENDDO

WHILE ... ENDWHILE

LOOP ... ENDLOOP

SELECT ... ENDSELECT

CONTINUE terminates the current loop pass, returns the

processing to the beginning of the loop and starts the nex

loop pass, if there is one.

DO loop: Omit an area (10 ... 20)

DO 100 TIMES.

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

CONTINUE.

ENDIF.

...

ENDDO.

Regards,

Satish

harikrishnan_m
Active Participant
0 Kudos

Hi,

Difference b/w EXIT and CONTINUE is....

clear v_count.

LOOP AT itab.

v_count = v_count +1.

CONTINUE.

perform hello.

ENDLOOP.

Here say itab has10 records....and finally after loop execution value of v_count will be 10....but in no execution perform will be executed...since i put continue it will skip rest of the steps after CONTINUE and loop will start with next record.

Now 'EXIT'.

LOOP AT itab.

v_count = v_count +1.

EXIT.

ENDLOOP.

Here v_count will be 1.

EXIT will just come out of the loop. No processing after tht

Rewards if useful.

Regards,

ABAPer 007