Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  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.

By default, 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 cross-transaction objects, shared objects exist that can be accessed by all programs of an AS Instance at the same time.

Object Services are available for handling persistent objects in the database. These associate 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

Before an object can be created, an object reference variable is required that can point to the required class:

  • Once a class reference variable obj is declared for a class class, an object of that class can be created using the statement CREATE OBJECT obj. This statement creates an instance of the class class and the reference variable obj contains a reference to this object.
  • Once a class reference variable obj is declared for a superclass of the class class or an interface reference variable obj for an interface implemented by the class class, the addition TYPE class of the statement CREATE OBJECT obj can be used to create an instance of the class class.

The instance operator NEW enables objects to be created in general expression positions.

Access to Instance Components

A program can access the visible instance components of an object only by using 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 (known as the heap). An object is used for as long as at least one heap reference points to the object, to an instance attribute, or to a part of the instance attribute or as long as 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 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.

Continue

Object References

Accessing Class Components

Object References in Internal Tables