Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Classes and Interfaces →  ABAP Objects - Overview →  Classes →  Components of Classes →  Methods of Classes 

The C Destructor

A destructor is a special method which is called automatically when an object is deleted. Destructors can be used to release resources used by the object that are not included in the Garbage Collection. Currently, ABAP Objects does not include a destructor, in which a regular ABAP processing block can be programmed.

Other versions: 7.31 | 7.40 | 7.54

internal use only

CLASS class DEFINITION.
  PUBLIC SECTION.
    METHODS destructor [NOT AT END OF MODE].
    ...
ENDCLASS.

one

CLASS class IMPLEMENTATION.
  METHOD destructor.
    SYSTEM-CALL c-destructor 'name' USING attr1 attr2 ...
  ENDMETHOD.
ENDCLASS.

This means that the destructor makes it possible to call a C routine name when an object is deleted. The routine must exist in the ABAP kernel so that no syntax error occurs.

When the optional addition NOT AT END OF MODE is used, the destructor is not executed if the internal mode is closed anyway. Usually a destructor is also executed at the end of a mode and should mainly be used to release external resources involved that are not released automatically when the mode is closed.

When the C routine is called, an attribute attr1, attr2, ... of the class of any complex data type can be passed on to the routine. If multiple parameters are to be passed, an appropriate data type must be defined.

During the lifetime of an internal mode, the time when the method destructor is executed depends on when the Garbage Collector is started. When an internal mode is closed, the destructors that are not declared using the addition NOT AT END OF MODE are executed for all objects. In cases of inheritance, the destructors of the subclasses are executed before the destructors of the superclasses.