Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Calling and leaving program units →  Exiting Program Units →  Exiting Processing Blocks 

EXIT - processing_block

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


EXIT. 

Effect

If the statement EXIT is located outside a loop, the statement immediately terminates the current processing block.

After the processing block is exited, the runtime environment responds in the same way as when the processing block is exited in a regular way (with the exception of the event block LOAD-OF-PROGRAM and the reporting event blocks START-OF-SELECTION and GET) . In particular, the output parameters of procedures are passed on to the bound actual parameters.

  • The event block LOAD-OF-PROGRAM cannot be exited using EXIT.
  • After the reporting event blocks START-OF-SELECTION and GET have been exited using EXIT, the runtime environment does not raise any more reporting events and instead calls the list processor directly to display the basic list.

Programming Guideline

Only use RETURN to exit procedures


Example

The method main contains two EXIT statements. Whereas the first statement exits the LOOP loop, the second statement exits the entire method. The RETURN statement should be used instead of the EXIT statement.

TYPES: 
  BEGIN OF line, 
    col1 TYPE string, 
    col2 TYPE string, 
  END OF line, 
  itab TYPE STANDARD TABLE OF line WITH EMPTY KEY. 

CLASS demo DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS main IMPORTING char TYPE string 
                                itab TYPE itab. 
ENDCLASS. 

CLASS demo IMPLEMENTATION. 
  METHOD main. 
    LOOP AT itab INTO DATA(wa). 
      FIND char IN wa-col1 RESPECTING CASE. 
      IF sy-subrc = 0. 
        EXIT. 
      ENDIF. 
    ENDLOOP. 
    FIND to_upper( char ) IN wa-col2 RESPECTING CASE. 
    IF sy-subrc <> 0. 
      EXIT.                  "works as RETURN here! 
    ENDIF. 
    ... 
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION. 
  DATA(itab) = VALUE itab( 
    ( col1 = `aaaa` col2 = `AAAA` ) 
    ( col1 = `bbbb` col2 = `XXXX` ) 
    ( col1 = `cccc` col2 = `CCCC` ) ). 
  demo=>main( char = `b` 
              itab = itab ).