References in ABAP
A reference is a pointer to an instance, and is contained in a reference variable. A reference variable
is a data object, whose type you specify using the REF TO
addition in the TYPES or DATA statement.
There are various types of reference variables. The type specifies the instances to which the reference can point. The following reference types are currently supported:
References --+-- Data references
|
+-- Object references --+-- Class references
+-- Interface references>
The main distinction is between data and object references.
-
A data reference can point to any data object. You specify its type using the additions
TYPE REF TO DATA or TYPE
REF TO type to the TYPES and DATA
statements . With the CREATE DATA statement you can use data references
to create data objects dynamically. You can write references to existing data objects in to reference
variables using the GET REFERENCE statement.
In order to access
the field that a data reference points to, you use the dereferencing operator
->*. If the data reference is completely typed, that is it
has no generic type, you can insert the expression dref->*
at any operand position. For all data reference variables you can use
ASSIGN dref->* TO <fs> assign the field that
a data reference indicates to a field symbol .
The statements and techniques discussed above
are only suitable for working with generic data references. You can also assign
a type and, as a result, directly address data references.
- Object references can point to objects in ABAP Objects. An object reference can be a class reference or an interface reference:
- Class references allow you to access all of the components of a class. You specify their type using
the
TYPE REF TO class