Skip to content

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

CREATE DATA - REF TO

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CREATE DATA dref [area_handle] 
                 TYPE REF TO {type|(name)}.

Effect

The addition TYPE REF TO is used by the statement CREATE DATA to create a reference variable. The static type of the reference variable can be specified either directly as type or dynamically in name.

When type is specified, the same rules apply as to the definition of reference types using the statement TYPES. For data reference variables, either the generic type data or a fully specified data type can be specified. For object reference variables, either a class or an interface can be specified.

For name, a character-like field can be specified that has to contain the name of a class, an interface, or a data type when the statement is executed. The name of the reference type in name can also be specified as an absolute type name.


Note

Object types in name can also be specified dynamically in lowercase letters.


Example

Creation of an anonymous data object as reference variable of the static type of a class. The dereferenced reference variable can be used to create an object of the class and for access to its components.

CLASS cls DEFINITION. 
  PUBLIC SECTION. 
    DATA attr TYPE string VALUE `Oh my ...`. 
ENDCLASS. 

TYPES reftype TYPE REF TO cls. 

DATA dref TYPE REF TO reftype. 

CREATE DATA dref TYPE REF TO cls. 

CREATE OBJECT dref->*. 

cl_demo_output=>display( dref->*->attr ). 

Executable Example

Creating Reference Variables

Continue

Creating Reference Variables