ABAP Keyword Documentation → ABAP - Reference → Creating Objects and Values → CREATE DATA
CREATE DATA - TYPE, LIKE
Other versions: 7.31 | 7.40 | 7.54
Syntax
CREATE DATA dref [area_handle]
{ {TYPE [LINE OF] {type|(name)}}
| {LIKE [LINE OF] dobj} }.
Effect
The type of the new data object is defined by the specified type or data object.
-
type
can be any data type from ABAP Dictionary, in particular the structure of a database table, a classic view, or a CDS entity of a CDS view, a public data type of a global class, or any data type of the same program that is already been defined withTYPES
and that is either more specific than or identical to the static type ofdref
. Alternatively, a character-like data objectname
can be specified in parentheses that contains the name of the existing data type when the statement is executed. This is not case-sensitive. The name inname
can also be an absolute type name. If a standard table type with a generic primary table key is specified afterTYPE
, a new bound table type with standard key is created and used. -
A data object that is visible at this point can be
specified for
dobj
. The new data object inherits the current data type. Ifdobj
is specified as a formal parameter or field symbol, it can be fully or partially generic. When the statement CREATE DATA is executed, a data object must be bound to a generically typed field symbol or parameter and the type of the data object is used. In the case of a fully typed field symbol or parameter, the declared type is used. A data object does not have to be bound.
The optional addition LINE OF
can be used if type
or the name in name
is a table type, or if dobj
is an internal table. As a result, the new data object inherits the attributes of the row type of the internal table.
Notes
-
LIKE
can be used to refer to data objects, and also to the public attributes of global classes. -
If, in
name
, a type of another program is specified using an absolute type name, this program is loaded into a new additional program group or into the current program group, depending on the program type (if not already loaded). -
When a data type is used, the
instance operator
NEW
acts like the statementCREATE DATA dref TYPE type
and can be used in general expression positions.
Example