SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference →Creating Objects and Values
This section describes how data objects and instances are created and values constructed.
Creating Objects
Creating an object or data object is equivalent to creating an instance of a data type or a class dynamically. While instances of classes can only be created as described in this section, instances of data types (data objects) that are declared with the statement DATA, or related statements, such as CONSTANTS, are created automatically as named data objects when their context is loaded into the internal session. Data objects only need to be created dynamically if the data type is made known for the first time only when the program is executed, or if large amounts of memory are allocated only for short periods of time.
Dynamically created objects can only be addressed using reference variables, and can be deleted from the internal session by the Garbage Collector if they are no longer referenced.
There are two statements and an operator for creating objects:
Data objects and objects are created by default in the internal session of the current program, and only programs of the same internal session can access them. It is also possible to create shared objects in the shared memory.
Note
The use of the statement ASSIGN LOCAL COPY to create objects is now obsolete.
Constructing Values
The attribute values of a new instance of a class can be constructed using the instance constructor of the class. The input parameters of the instance constructor can be filled using the EXPORTING addition of the statement CREATE OBJECT or using actual parameters for the instance operator NEW.
The values of dynamically or statically declared data objects can be constructed using the following constructor expressions:
Note
Like any constructor expression, the value operator VALUE can be used in general expression positions and functional operand positions, in particular the right side of an assignment to an inline declaration.
Example
Inline declarations of a reference variable dref and a structured variable dobj. The instance operator NEW creates an anonymous data object, referenced by dref. Using functional method calls, the instance operator NEW and the value operator VALUE are used to construct and assign values for the components of the structures.