ABAP - Keyword Documentation →  ABAP - Reference →  Creating Objects and Values → 

CREATE OBJECT

Quick Reference

Syntax Forms


Defining a Class Implicitly

1. CREATE OBJECT oref [ area_handle] [ parameter_list].

Defining a Class Explicitly

2. CREATE OBJECT oref [ area_handle]
                     TYPE { class  [parameter_list] }
                        | { (name) [ parameter_list| parameter_tables] }.


Effect

The statement CREATE OBJECT creates an instance of a class or object and assigns the object reference to the reference variable oref. The instance constructor of the class is called directly after the object is created.

By default, the object is created in the internal session (or heap) of the current program and remains there for as long as it is required. If no more heap references point to the object, the following applies:

Also, if no more methods of the object are registered as event handlers, the object is deleted by the garbage collector. The addition area_handle can be used to create the object as a shared object.

The reference variable oref must be declared as an object reference variable. Instance components of an object created using CREATE OBJECT can only be accessed using object reference variables (see Data Objects in Operand Positions).

The addition TYPE can be used to specify the class of the new object. The static type of the object reference variables must be more general than or identical to the class of the new object (in accordance with the rules for Assignments Between Object Reference Variables).

The additions parameter_list and parameter_tables must be used to fill the non-optional input parameters of the first explicitly implemented instance constructor in the path of the inheritance tree between the instantiated class and the root class object. These additions can also be used to assign return values to the non-class-based exceptions of the instance constructor.

If a handleable exception is raised for the object in the runtime environment, the object is not created and the object reference variable oref is initialized. If a handleable exception is raised when the object is created in the instance constructor of the class, the object is deleted and the object reference variable oref is initialized.

Return Value

If the statement CREATE OBJECT is executed successfully, sy-subrc is set to 0. Values other than 0 can occur when specifying EXCEPTIONS in parameter_spec when non-class-based exceptions of the instance constructor are handled.

Notes

Exceptions

Handleable Exceptions

CX_SY_CREATE_OBJECT_ERROR

Non-Handleable Exceptions



Continue
CREATE OBJECT oref
CREATE OBJECT - TYPE
CREATE OBJECT - AREA HANDLE
CREATE OBJECT - parameter_list
CREATE OBJECT - parameter_tables