SAP ABAP - Exit Statement



EXIT statement is used to terminate an entire loop unconditionally and immediately. As soon as the EXIT statement is executed, the loop is terminated and the statements following the loop are processed.

The syntax for exit statement is −

EXIT.

Note − If the EXIT statement is used in a nested loop, only the current loop is executed after the EXIT statement is processed.

Block Diagram

Exit Statement

Example

Report YH_SEP_15.  
DO 5 TIMES.  
IF SY-INDEX = 3.  
EXIT.  
ENDIF.  
Write / SY-INDEX.  
ENDDO.

The above code produces the following output −

1
2
sap_abap_loop_control.htm
Advertisements