Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Program Flow Logic →  Exception Handling →  Class-Based Exceptions →  TRY 

CLEANUP

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CLEANUP [INTO oref]. 

Addition

... INTO oref

Effect

Introduces a statement block of a TRY control structure where cleanups can be performed.

A CLEANUP block is executed when a class-based exception in the TRY block of the same TRY control structure is raised, but is handled in a CATCH block of an external TRY control structure. A CLEANUP block is executed immediately before the context of the exception is deleted:

  • If the addition BEFORE UNWIND is specified for the handling CATCH block, the context is deleted when the CATCH block is exited and the CLEANUP block is executed accordingly after handling.
  • If the addition BEFORE UNWIND is not specified, the context is deleted before the CATCH block is executed and the CLEANUP block is executed accordingly.
  • If RESUME is used to resume processing after a resumable exception, the context is not deleted and accordingly no CLEANUP block is executed.

The CLEANUP block must be executed completely and must be exited using ENDTRY so that the exception can be propagated to its handler. If an attempt is made to exit the context of a CLEANUP block prematurely, a runtime error occurs. A CLEANUP block cannot contain any statements where the system can detect (statically) that it cannot return to the CLEANUP block. Program calls using SUBMIT and CALL TRANSACTION should also be avoided here.


Notes

  • The context of the TRY block can be cleaned up in a CLEANUP block. For example, objects can be updated to a consistent state or external resources released to which an external handler would no longer have access.
  • Since a CLEANUP block must always be executed completely, all the exceptions raised there must also be handled there.

Addition

... INTO oref

Effect

If the addition INTO is specified, a reference to the exception object is saved to oref. The following can be specified for oref:

  • An existing object reference variable of the type CX_ROOT
  • An inline declaration DATA(var), where an object reference variable of the type CX_ROOT is declared.

oref can be used to access the exception object.


Note

Within the CLEANUP block, do not raise the current exception again using RAISE EXCEPTION oref, since this would modify the attributes of the exception object.