Aug 28, 2025

What is the Difference between Statement RETURN and EXIT in SAP ABAP?

Both RETURN and EXIT are control flow statements, but they serve different purposes and behave differently depending on the context. Here's a clear breakdown:

🔁 RETURN Statement

Purpose:
Used to exit a procedure—like a function module, method, or form—immediately and return control to the calling program.

Where it's used:

  • Function modules
  • Methods
  • Subroutines (FORM routines)

Behavior:

  • Ends the current procedure and returns to the caller.
  • No further code in the procedure is executed after RETURN.

Example:

FORM my_form. 

  IF sy-subrc <> 0. 

    RETURN. 

  ENDIF. " More code here won't run if RETURN is triggered 

ENDFORM.


🚪 EXIT Statement

Purpose:
Used to exit a loop or control structure like DO, WHILE, or LOOP.

Where it's used:

  • Inside loops (LOOP, DO, WHILE)
  • Not valid in procedures like methods or function modules (outside loops)

Behavior:

  • Immediately exits the current loop, but the rest of the surrounding code continues.
  • Does not exit the entire procedure.

Example:

LOOP AT it_table INTO wa_table. 

  IF wa_table-flag = 'X'. 

    EXIT. " Exits the LOOP, not the FORM 

  ENDIF. 

ENDLOOP.


🧠 Summary Table




Let me know if you want to see how CHECK fits into this trio—it’s another control statement that behaves a bit differently again.