SAP Tutorials Blog

 

 


Reference Variables

The syntax for declaring reference variables is −

DATA <ref> TYPE REF TO <type> VALUE IS INITIAL. 

REF TO addition declares a reference variable ref.

The specification after REF TO specifies the static type of the reference variable.

The static type restricts the set of objects to which <ref> can refer.

The dynamic type of reference variable is the data type or class to which it currently refers.

The static type is always more general or the same as the dynamic type.

The TYPE addition is used to create a bound reference type and as a start value, and only IS INITIAL can be specified after the VALUE addition.


Example

CLASS C1 DEFINITION. 

PUBLIC SECTION. 

DATA Bl TYPE I VALUE 1. 

ENDCLASS. DATA: Oref TYPE REF TO C1 , 

Dref1 LIKE REF TO Oref, 

Dref2 TYPE REF TO I . 

CREATE OBJECT Oref. 

GET REFERENCE OF Oref INTO Dref1. 

CREATE DATA Dref2. 

Dref2→* = Dref1→*→Bl.



Serkan AKKAVAK

Computer Engineer BSc

SAP Department Manager

Contact : serkurumsal@yandex.com