Defining a Class Implicitly
1. CREATE OBJECT oref
[area_handle] [parameter_list].
Defining a Class Explicitly
2. CREATE OBJECT oref
[area_handle]
TYPE {class|(name)} [parameter_list].
The CREATE OBJECT statement creates an instance of a class or object and assigns the object reference to the reference variable oref. Directly after the object has been created, the instance constructor of the class is executed.
By default, the object is created in the internal session of the current program and remains there as long as it is needed. When it is no longer referenced by any reference variable, it is deleted from the garbage collector. You can use the area_handle addition 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).
You can use the TYPE addition to specify the class of the created object. The static type of the object reference variable must be more general than or identical to the class of the created object, in accordance with the rules for Assignments Between Object Reference Variables.
With the parameter_list addition you must fill the non-optional input parameters of the first explicitly implemented instance constructor, which is on the path of the inheritance tree from the instantiated class to the root class object. You can also use the parameter_list addition to assign return values to the non-class-based exceptions of the instance constructor.
If an exception that can be handled occurs in the runtime environment during the creation of the object,
it is not created and the object reference variable oref
is initialized. If, after the object has been created, an exception that can be handled occurs in the instance constructor of the class or a
message is sent using
MESSAGE RAISING, the created object is deleted and the object reference oref is initialized.
Return Value
If the CREATE OBJECT
statement is executed successfully, sy-subrc is set to 0. Values other than 0 are set by specifying
EXCEPTIONS in parameter_spec when non-class-based exceptions of the instance constructor are handled.
You can only create an instance of a class where permitted by the AB>CREATE> addition to the CLASS DEFINITION statement.
Catchable Exceptions
CX_SY_CREATE_OBJECT_ERROR
Non-Catchable Exceptions