ABAP Keyword Documentation → ABAP - Reference → Declarative statemnts → Classes and Interfaces → ABAP Objects - Overview
Objects
Objects are instances of classes. There can be any number of objects or instances in a class. Each object has a unique identity and its own attributes.
As standard, all objects have the same priority in the data area of an internal session. This means that objects can only be accessed from within an internal session.
For transaction-independent objects, shared objects are available, which can be accessed by all programs of an application server at the same time.
Object Services are available for handling persistent objects in the database. These link the attributes of objects with the content of database tables and can execute object-oriented transactions.
Other versions: 7.31 | 7.40 | 7.54
Creating Objects
If you want to create an object, you need an object reference variable that can point to the required class:
- Having declared a class reference variable
obj
for a classclass
, you can create an object of that class using the statement CREATE OBJECT obj. This statement creates an instance of the classclass
and the reference variableobj
contains a reference to this object.
- Having declared a class reference variable
obj
for a superclass of the classclass
or an interface reference variableobj
for an interface implemented by the classclass
, you can use the TYPE class addition of theCREATE OBJECT obj
statement to create an instance of the classclass
.
Access to Instance Components
A program can access the visible instance components of an object only through references in reference variables. For the syntax, see Accessing Components of Classes.
Lifetime of Objects
An object is kept alive for as long as it is used in the internal session (Heap). The system will continue use the object provided that at least one Heapreference points to the object, an instance attribute or part of the instance attribute or provided that at least one method of the object is registered as an event handler. Field symbols to which an instance attribute or part of an instance attribute is assigned still work in the same way as data references.
As soon as an object has no more references and none of its methods is registered as an event handler, it can be deleted by the Garbage Collector). This releases the identity of the object to be taken by a new object.
Note
Alongside these regular references, weak references represented by objects exist that do not keep an object alive.