ABAPGET_REFERENCE - GET REFERENCE

General Material Data   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.

GET REFERENCE

Short Reference



Syntax

GET REFERENCE OF dobj INTO dref.

Effect

This statement gets a reference to a data object dobj and places it into the reference variable dref. Thereference variable dref must be declared as a data reference variable. The static type of the data reference variable must be more general than or the same as the data type dobj, according to theconversion rules for reference variables.

The data object is specified directly and in accordance with the rules described in the sectionData Objectsin Operand Positions. If you have an offset/length specification, the data type dobj here must not be string or xstring.

Notes

  • The GET REFERENCE statement and the addition REFERENCEINTO are the only options available to statements for internal tables to generatedependentdata references. Dependent data references can become invalid if the referenced data object is deleted.

  • The content of two reference variables filled with GET REFERENCE is only the same if the remainingadministration information is the same, apart from the referenced data objects. For example, a referencethat is retrieved directly by specifying the data object is not the same as a reference that is retrieved by specifying a field symbol if this has a different data type due to acasting.

  • When an internal table has a header line, a data reference variable can only point to this or thetablebody. In the GET REFERENCE statement, the name of an internal table with a header line addressesthe header line. To address the table body, [] must be appended to the name in the usual way.A dereferenced data reference to which a table body is assigned behaves in the same way in operand positions as a table without a header line.

  • The context in which a data reference is retrieved using GET REFERENCE determines whether thereferenced data object can be changed. If the data object can be changed in the context of GET REFERENCE,it can be changed at any position, also using the reference. For example, a reference to a private attributeof a class can be retrieved in a method, and passed to external destinations. Since the attribute canbe changed in the class, it can also be changed outside of the class using the reference. Conversely, a constant or a non-changeable input parameter can also be made non-changeable by passing on its reference.

  • As of Release 7.0, a data reference retrieved using GET REFERENCE that references a data object in theshared objects memory can also be stored in a closedareainstance version. The restrictions described for the addition AREAHANDLE of the statement CREATE DATA must not be ignored.


Example

Creating data references to the individual characters of a data object text and storing them in an internal table. Direct dereferencing at an operand position is possible because the data reference is fully typed.

TYPES c1 TYPE c LENGTH 1.

DATA: dref     TYPE REF TO c1,
      dref_tab LIKE TABLE OF dref.

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.
  WRITE / dref->*.
ENDLOOP.

Exceptions

Non-Catchable Exceptions

  • Cause: The data object specified after INTO is not a reference variable.
    Runtime Error: GET_REF_REFERENCE_EXPECTED
  • Cause: GET REFERENCE is not permitted for a substring.
    Runtime Error: GET_REF_SUBSTRING_NOT_ALLOWED









BAL Application Log Documentation   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.


Length: 5937 Date: 20120522 Time: 063534     triton ( 210 ms )