sapdev logo background
sapdev logo sapdev logo
Comments

SAP C DESTRUCTOR documentation, setup help and example usage



Return to SAP documentation index


ARTICLE

The C Destructor
A destructor is a special method that is called automatically when an object is deleted. Destructors can be used to release resources used by the object that are not included in garbage collection . ABAP Objects do not currently have a destructor in which a regular ABAP processing block can be programmed.
For special cases and for internal use only , the predefined instance method destructor can be declared in the public visibility section of a class:

CLASS class DEFINITION.
PUBLIC SECTION.
METHODS destructor [NOT AT END OF MODE].
...
ENDCLASS .
In the implementation of the method destructor only one statement can currently be used:

CLASS class IMPLEMENTATION.
METHOD destructor.
SYSTEM-CALL c-destructor 'name' USING attr.
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 to ensure that no syntax errors occur.
When the optional addition NOT AT END OF MODE is used, the destructor is not executed if the
internal session is closed anyway. A destructor is usually also executed at the end of a session and should mainly be used to release external resources that are not released automatically when the session is closed.
When the C routine is called, attributes attr1 , attr2 , and so on, 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 session, the time at which the method destructor is executed depends on when the garbage collector is started. When an internal session is closed, the destructors that are not declared with the addition NOT AT END OF MODE are executed for all objects. In the case of inheritance, the destructors of subclasses are executed before the destructors of superclasses.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




CX_SQL_EXCEPTION
DATABASE




comments powered by Disqus