Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Creating Objects and Values →  CREATE DATA 

CREATE DATA - TYPE, LIKE

Quick Reference

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 generated 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, a public data type of a global class, or any data type of the same program already defined defined using TYPES and that is either more specific than or identical to the static type of dref. Alternatively, a character-like data object name 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 in name can also be an absolute type name. If a standard table type with a generic primary table key is specified after TYPE, 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 generated data object inherits the current data type. If dobj 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 completely typed field symbol or parameter, the declared type is used. A data object does not have to be connected.

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 generated data object inherits the attributes of the row type of the internal table.


Notes

  • LIKE can be used to reference the public attributes of global classes.
  • If a type of another program is specified using an absolute type name in 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 an anonymous data object is created with an enumerated type, the same rules apply for this object as for every other data object of this type.
  • When a data type type is used, the instance operator NEW acts like the statement CREATE DATA dref TYPE type and can be used in general expression positions. The content of name cannot be specified dynamically here.

Example

Creates an anonymous data object of type SCARR. The static data type of the data reference variable is generic. If can only be dereferenced and used on operand positions by means of assignment to a field symbol.

DATA dref TYPE REF TO data. 

CREATE DATA dref TYPE scarr. 
ASSIGN dref->* TO FIELD-SYMBOL(<fs>). 

SELECT SINGLE * 
       FROM scarr 
       WHERE carrid = 'LH' 
       INTO @<fs>. 

ASSIGN COMPONENT 'CARRID'   OF STRUCTURE <fs> TO FIELD-SYMBOL(<fs1>). 
ASSIGN COMPONENT 'CARRNAME' OF STRUCTURE <fs> TO FIELD-SYMBOL(<fs2>). 

cl_demo_output=>display( |{ <fs1> }, { <fs2> }| ). 

Executable Example

Creating Structured Data Objects

Continue

Creating Structured Data Objects