ABAP Keyword Documentation → ABAP - Reference → Creating Objects
CREATE DATA
Other versions: 7.31 | 7.40 | 7.54
Syntax Forms
Defining the data type implicitly
1. CREATE DATA dref [area_handle].
Defining the data type using predefined ABAP types
2. CREATE DATA dref [area_handle]
TYPE {abap_type|(name)}
[LENGTH len] [DECIMALS dec].
Defining the data type using an existing type
3. CREATE DATA dref [area_handle]
{ {TYPE [LINE OF] {type|(name)}}
| {LIKE [LINE OF] dobj} }.
Creating data with reference to a type object
4. CREATE DATA dref [area_handle]
TYPE HANDLE handle.
Creating Reference Variables
5. CREATE DATA dref
[area_handle]
TYPE REF TO {type|(name)}.
Creating internal tables
6. CREATE DATA dref
[area_handle]
{ {TYPE [STANDARD]|SORTED|HASHED TABLE
OF [REF TO] {type|(name)}}
| {LIKE [STANDARD]|SORTED|HASHED TABLE OF dobj} }
[ {WITH [UNIQUE|NON-UNIQUE]
{KEY {comp1 comp2 ...}|(keytab)}|{DEFAULT KEY}}
| {WITH EMPTY KEY} ]
[INITIAL SIZE n].
Effect
The CREATE DATA statement creates an
anonymous data object and assigns the reference to the data object of the dref reference variables.
By default, the data object is created in the internal session
(heap) of the current program and remains there for as long as it is required. If no
data references and no
field symbols point to the data object or to a part of the data objects, it is deleted by
Garbage Collector. The data object can be created as a
shared
object using the addition area_handle.
The reference variable dref must be declared as a data reference variable.
The content of a data object that is created with CREATE DATA can only be accessed using dereferenced data variables or field symbols (see
Data objects in operand positions).
The data type of the data object that is created can be defined using the TYPE
addition and a type specification or with the LIKE addition and the specification
of a data object. The syntax permits the dynamic definition of elementary data types, reference types, and table types. The HANDLE addition can reference any
RTTS type objects. According to the rules in section
Assignments Between Data Reference Variables,
the static type of the data reference variables has to be more general than the data type of the data object created, or be identical with it.
If a handleable exception is raised when the object is being created, the object is not created and the dref data reference variable retains its previous state.
Notes
-
Unlike the
DATAstatement, CREATE DATA creates the data object at execution time.DATAcreates declared data objects when the corresponding program unit is loaded. -
The statement
CREATE DATAcreates a heap reference. All references that point to the anonymous data object or its parts are also heap references and keep the data object alive. The same applies to field symbols.
Exceptions
Catchable Exceptions
CX_SY_CREATE_DATA_ERROR
-
Cause: Illegal value for the
DECIMALSaddition.
Runtime Error:CREATE_DATA_ILLEGAL_DECIMALS -
Cause: Illegal value for the
INITIAL SIZEaddition.
Runtime Error:CREATE_DATA_ILLEGAL_INIT_SIZE -
Cause: Illegal value for the
LENGTHaddition.
Runtime Error:CREATE_DATA_ILLEGAL_LENGTH -
Cause: The
LENGTHaddition was used for a type other thanc,n,x, orp.
Runtime Error:CREATE_DATA_LEN_NOT_ALLOWED -
Cause: The type specified dynamically in
TYPEis not typed completely.
Runtime Error:CREATE_DATA_NOT_ALLOWED_TYPE -
Cause: The type dynamically specified in the
TYPEaddition is not known.
Runtime Error:CREATE_DATA_UNKNOWN_TYPE
Non-Catchable Exceptions
-
Cause: The
drefvariable does not have the correct type.
Runtime Error:CREATE_DATA_REFERENCE_EXPECTED