SAP CREATE DATA ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID CREATE-DATA
• CREATE DATA ABAP Statement
• TYPE CREATE DATA

CREATE DATA
Short Reference

ABAP_SYNTAX_FORMS

Defining the Data Type Implicitly
1 CREATE DATA dref $[area_handle $].

Defining the Data Type Using Built-in ABAPTypes
2 CREATE DATA dref $[area_handle $]
TYPE ${abap_type$|(name)$}
$[LENGTH len$] $[DECIMALS dec$].

Defining the Data Type Using an ExistingType
3 CREATE DATA dref $[area_handle $]
${ ${TYPE $[LINE OF$] ${type$|(name)$}$}
$| ${LIKE $[LINE OF$] dobj$} $}.
BEGIN_SECTION VERSION 5 OUT

Creating Data with Reference to a TypeDescription Object
4 CREATE DATA dref $[area_handle $]
TYPE HANDLE handle.
END_SECTION VERSION 5 OUT

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$].


Create Data Object with BDEF DerivedTypes
11 CREATE DATA dref TYPE ( der_type).

What does it do?
The statement CREATE DATA creates an anonymous data object and assigns the reference to the data object to the reference variable dref.
By default, the data object is created in the ABAP_ISESS ( heap) of the current program and is preserved 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 object, it is deleted by the Garbage Collector.
BEGIN_SECTION VERSION 5 OUT The data object can be created as a shared object using the addition area_handle.
END_SECTION VERSION 5 OUT
The reference variable dref must be declared as a data reference variable. The content of a data object created using CREATE DATA can only be accessed using dereferenced data variables or field symbols (see Data Objects in Operand Positions ).
The data type of the created data object can be defined using the addition TYPE and a type specification or using the addition LIKE and a data object specification.
BEGIN_SECTION VERSION 5 OUT The syntax allows the dynamic definition of elementary data types, reference types, and table types. The addition HANDLE can be used to refer to any RTTS type description objects.
END_SECTION VERSION 5 OUT According to the rules in the section Assignments Between Data Reference Variables, the static type of the data reference variable must be more general than the data type of the created data object, or be identical to it.
If a catchable exception is raised when the object is created, the object is not created and the dref data reference variable keeps its previous state.



Latest notes:

Unlike the statement DATA, CREATE DATA creates the data object at the time of execution. Data objects declared using DATA are created when the associated program unit is loaded.
The statement CREATE DATA creates 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.
When a data type is used, the instance operator NEW acts like the statement CREATE DATA dref TYPE type and can be used in general expression positions.
Unlike CREATE OBJECT, the return code sy-subrc is not set for CREATE DATA.
NON_V5_HINTS
ABAP_HINT_END



Runtime Exceptions



Catchable Exceptions
CX_SY_CREATE_DATA_ERROR
Reason for error:
Illegal value for the addition DECIMALS.
Runtime error:
CREATE_DATA_ILLEGAL_DECIMALS
Reason for error:
Illegal value for the addition INITIAL SIZE.
Runtime error:
CREATE_DATA_ILLEGAL_INIT_SIZE
Reason for error:
Illegal value for the addition LENGTH.
Runtime error:
CREATE_DATA_ILLEGAL_LENGTH
Reason for error:
The addition LENGTH was used for a type other than c, n, x, or p.
Runtime error:
CREATE_DATA_LEN_NOT_ALLOWED
Reason for error:
The type specified dynamically in the addition TYPE is not typed in full.
Runtime error:
CREATE_DATA_NOT_ALLOWED_TYPE
Reason for error:
The type specified dynamically in the addition TYPE is not known.
Runtime error:
CREATE_DATA_UNKNOWN_TYPE

Non-catchable Exceptions
Reason for error:
The variable dref does not have the correct type.
Runtime error:
CREATE_DATA_REFERENCE_EXPECTED
ABAP_NONCAT_END

Return to menu