Get Example source ABAP code based on a different SAP table
ID GET-REFERENCE • GET REFERENCE OF ABAP Statement • INTO GET REFERENCE
GET REFERENCE> Short Reference >
ABAP_SYNTAX GET REFERENCE OF dobj INTO dref.>
What does it do? This statement sets the reference> in the reference variable dref> so that it points to the data object dobj> . The following can be specified for dref>:
An existing 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 the assignment rules for reference variables >.
An inline declaration DATA(var)>> or FINAL(var)>>. This declares a data reference variable whose static type is the data type of dobj>. The data type of dobj> must be known statically as a complete type or as the generic type data>. Field symbols and formal parameters with other generic types, in particular any>, are not possible. The data object is specified directly and in accordance with the rules described in the section Read Positions>. If offsets/lengths (+off(len) >>) are specified, the data type dobj> here cannot be string> or xstring>.
Latest notes:
In addition to the reference operator REF>> and the addition REFERENCE INTO>>, the statement GET REFERENCE> is the only option for internal table statements to create stack references>. Stack references can become invalid if the referenced data object is deleted.
When applied to data objects in the heap> GET REFERENCE> creates memory-retaining heap references>.
The content of two reference variables filled with GET REFERENCE> is only the same if the remaining administration information is the same, apart from the referenced data objects. For example, a reference that is obtained directly by specifying the data object is not the same as a reference that is obtained by specifying a field symbol if it has a different data type due to a casting>.
For an internal table with a header line>, a data reference variable can only point to this or the table body>. In the statement GET REFERENCE>, the name of an internal table with a header line addresses the header line. To address the table body, []> must be appended to the name as usual. 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.
If references are set using GET REFERENCE>, permission to access the corresponding data object is only checked at the position of the statement. The references can then be passed on to any destination and can be used to access the associated data objects from any position using the references. To prevent access to private and read-only attributes using references outside classes, do not publish references to these attributes externally. A constant or read-only input parameter, however, can never be made modifiable by passing its reference.
The reference operator> REF>> works like the statement GET REFERENCE> and can be used in general expression positions>. NON_V5_HINTS
A data reference obtained using GET REFERENCE> that references a data object in the shared objects memory> can also be stored in a closed area instance version>. The restrictions described for the addition AREA HANDLE>> of the statement CREATE DATA>> must be respected. ABAP_HINT_END
Example ABAP Coding
Creation of 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 completely typed. After the output, an alternative implementation with an iteration expression> and the reference operator REF>> is shown that has the same result. ABEXA 00305 ABAP_EXAMPLE_END
Runtime Exceptions
Non-catchable Exceptions
Reason for error:
The data object specified after INTO> is not a reference variable.