ABAP Keyword Documentation → ABAP − Reference → Creating Objects and Values → CREATE DATA
CREATE DATA - TYPE abap_type
Other versions: 7.31 | 7.40 | 7.54
Syntax
CREATE DATA dref [area_handle]
TYPE {abap_type|(name)}
[LENGTH len] [DECIMALS dec].
Effect
Creates a data object with an explicitly specified data type. For the data type, all
built-in data types
(apart from b
and s
) can be used that are more
specific than the static type of dref
or are identical to it. The name of the type can be specified as follows:
-
abap_type
abap_type
.
-
(name)
name
(not case-sensitive). The following can be specified for name
:
- Literal or constant
If the data objectname
is specified as a character literal or as a constant, it can be evaluated statically and the specified type is identified as the used object.
- Variable
If the data objectname
is specified as a variable, it is specified only dynamically and the content is not evaluated statically.
name
is not evaluated until runtime (in both cases).
In the ABAP types c
, n
, p
,
and x
, the length of the data type dtype
can be
determined by specifying a numeric data object len
after the addition LENGTH
, which, when the statement is executed, contains a value within the
length range defined for the type in question.
If the addition LENGTH
is not specified, the standard length from the table
is used. For all other ABAP types, the length is determined by the value in the table and the addition LENGTH
cannot be specified.
In the ABAP type p
, the number of
decimal places is
determined by specifying a numeric data object dec
after the addition
DECIMALS. If DECIMALS
is specified, the same applies as in the statement
TYPES
. If the addition
DECIMALS is not specified, no decimal places are created. The decimal separator is ignored in operations with packed numbers if the
program attribute
fixed point arithmetic is not set. If it is not set, the addition DECIMALS
is applied only to dynpros and in the statement WRITE [TO]
. For all other ABAP types and if name
is specified dynamically, the addition DECIMALS
is not permitted.
Note
When a data type abap_type
is used, the
instance operator
NEW
acts like the statement CREATE DATA dref TYPE abap_type
and can be used in
general expression positions. The content of name
cannot be specified dynamically here.
Example
Creation of an anonymous data object of packed number type with length specification and decimals. As the static data type of the data reference variable is generic, data referencing is only possible by assignment to a field symbol.
DATA dref TYPE REF TO data.
CREATE DATA dref TYPE p LENGTH 8 DECIMALS 3.
ASSIGN dref->* TO FIELD-SYMBOL(<fs>).
<fs> = 1 / 3.
cl_demo_output=>display( <fs> ).
Executable Example
Creating Elementary Data Objects