CREATE DATA dref [area_handle]
TYPE {abap_type|(name)}
[LENGTH len] [DECIMALS dec].
For abap_type, all predefined data types (apart from b and s) can be used that are more dedicated than the static type of dref or are identical to it. As an alternative, a character-type name data object can be specified in brackets, which when the statement is executed contains the name of a predefined data type that had to be specified in uppercase letters before Release 6.10.
For ABAP types c, n, p and x, the length of the dtype data type can be determined by the specification of a numeric len data object after the LENGTH addition, which when the statement is executed contains a value for the length within the interval limits from the table of built-in ABAP types/ If the LENGTH addition 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 LENGTH addition must not be specified.
For the ABAP type p, the number of
fractional portions can be determined
by the specification of a numeric data object dec after
the DECIMALS addition, which when the statement is executed
contains a value within the interval limits from the table of built-in ABAP types for the fractional
portion. If the DECIMALS addition is not specified, no fractional portions are created. So that the decimal separator is taken into consideration for operations with packed numbers, the
program attribute fixed point arithmetic
has to be set, otherwise the DECIMALS only affects output
formatting on lists. For all other ABAP types and for the dynamic specification of
name, the DECIMALS addition is not permitted.
Depending on the parameters that are passed, the create_data subroutine creates all elementary data objects that are possible with built-in ABAP types.
PARAMETERS: type(10) TYPE c,
length TYPE i,
decimals TYPE i.
DATA dref TYPE REF TO data.
FIELD-SYMBOLS <fs> TYPE ANY.
START-OF-SELECTION.
TRY.
PERFORM create_data USING type
length
decimals
CHANGING dref.
ASSIGN dref->* TO <fs>.
DESCRIBE FIELD <fs> TYPE type
LENGTH length IN BYTE MODE
DECIMALS decimals.
WRITE: type, length, decimals.
CATCH cx_sy_create_data_error.
WRITE: 'Error creating', type, length, decimals.
ENDTRY.
FORM create_data USING value(typ) TYPE c
value(len) TYPE i
value(dec) TYPE i
CHANGING dref TYPE REF TO data
RAISING cx_sy_create_data_error.
TRANSLATE typ TO LOWER CASE.
CASE typ.
WHEN 'd' OR 'f' OR 'i' OR 'string' OR 't' OR 'xstring'.
CREATE DATA dref TYPE (typ).
WHEN 'c' OR 'n' OR 'x'.
CREATE DATA dref TYPE (typ) LENGTH len.
WHEN 'p'.
CREATE DATA dref TYPE p LENGTH len DECIMALS dec.
WHEN OTHERS.
RAISE EXCEPTION TYPE cx_sy_create_data_error.
ENDCASE.
ENDFORM.