Skip to content

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

LEAVE PROGRAM

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


LEAVE PROGRAM. 

Effect

This statement ends the current main program immediately and deletes its internal session, including all loaded programs, instances, and their data.

The statement LEAVE PROGRAM can appear anywhere within any processing block. It ends the program regardless of the program or object in which it is executed or in which program group of the internal session.

The way the runtime environment responds to LEAVE PROGRAM depends on how the main program was called in the internal session:

  • If the main program was called using CALL TRANSACTION, SUBMIT AND RETURN, or CALL DIALOG, the runtime environment returns to the calling program after the call point. If the main program was called using CALL DIALOG, the output parameters of the dialog module are passed to the calling program.
  • If the main program was called using LEAVE TO TRANSACTION or using a transaction code from within a dynpro, the runtime environment returns to the point at which the first program in the current call sequence was called.
  • If the main program was called using SUBMIT without the addition AND RETURN, the runtime environment returns to the point at which the calling program was started.


Notes

  • If procedures are still registered when a program is exited in the current SAP LUW, the SAP LUW is ended without calling or rolling back the procedures. Any registered update function modules are preserved in the database, but can no longer be executed. In this case, the statement COMMIT WORK or ROLLBACK WORK should be executed explicitly before leaving the program.
  • The statement LEAVE without additions is obsolete.

Example

Leaving a program after a failed authorization check.

CALL FUNCTION 'AUTHORITY_CHECK_TCODE' 
  EXPORTING 
    tcode  = sy-tcode 
  EXCEPTIONS 
    ok     = 1 
    not_ok = 2 
    OTHERS           = 3. 

IF sy-subrc > 1. 
  LEAVE PROGRAM. 
ENDIF.