ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Assigning References →  Setting Reference Variables → 

GET REFERENCE

Quick Reference

Syntax

GET REFERENCE OF dobj INTO dref.

Effect

This statement sets the reference in the reference variable dref in a way that makes it point to the data object dobj. The following can be specified for dref:

The data object is specified directly and in accordance with the rules described in the section Reading Positions. If offsets/lengths (+off(len)) are specified, the data type dobj here cannot be string or xstring.

Notes

Example

Creates data references to the individual characters of a data object text and saves them in an internal table. Direct dereferencing at an operand position is possible because the data reference is fully typed. After the output, an alternative implementation with an iteration expression and the instance operator NEW is shown that has the same result.

TYPES c1 TYPE c LENGTH 1.

DATA: dref     TYPE REF TO c1,
      dref_tab     LIKE TABLE OF dref WITH EMPTY KEY,
      dref_tab_new LIKE dref_tab.

DATA: text TYPE c LENGTH 10 VALUE '0123456789',
      off  TYPE i.

DO 10 TIMES.
  off = sy-index - 1.
  GET REFERENCE OF text+off(1) INTO dref.
  APPEND dref TO dref_tab.
ENDDO.

LOOP AT dref_tab INTO dref.
  cl_demo_output=>write( |{ dref->* }| ).
ENDLOOP.

cl_demo_output=>display( ).

dref_tab_new = VALUE #(
  FOR j = 0 UNTIL j > 9 ( REF #( text+j(1) ) ) ).
ASSERT dref_tab_new = dref_tab.

Exceptions

Non-Handleable Exceptions