SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Creating Objects and Values → CREATE DATA →
CREATE DATA - TYPE abap_type
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 predefined 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:
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