sapdev logo background
sapdev logo sapdev logo
Comments

ABAP DATA REFERENCES Statement syntax, information and example SAP source code



Return to Statement index



DATA - REF TO

Short Reference

ABAP Syntax_3 DATA ref { {TYPE REF TO type}
| {LIKE REF TO dobj} }
[VALUE IS INITIAL]
[READ-ONLY] .

What does it do? The addition REF TO declares a reference variable ref . The entry behind REF TO specifies the static type of the reference variable. The static type limits the set of objects to which ref can point. The dynamic type of a reference variable is the data type or the class to which it currently points. The static type is always more general or the same as the dynamic type (see also conversion rule for reference variables).
The syntax and meaning of the additions TYPE and LIKE are the same as the definition of reference types in the section TYPES - REF TO , but here they are used to create a bound reference type.
Only IS INITIAL can be specified as a start value after the addition VALUE .

Latest notes: Reference variables are opaque, which means their content cannot be accessed directly. A reference consists of the address of an object and other administration information.

Example ABAP Coding In this example, an object reference oref and two data references dref1 and dref2 are declared. Both data references are typed fully and can be dereferenced using the dereferencing operator - * in operand positions.
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA a1 TYPE i VALUE 1.
ENDCLASS.

DATA: oref TYPE REF TO c1,
dref1 LIKE REF TO oref,
dref2 TYPE REF TO i.

CREATE OBJECT oref.
dref1 = REF #( oref ).

CREATE DATA dref2.
dref2->* = dref1->*->a1.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




DATA_RANGES
DATA_REFERRING




comments powered by Disqus