References are pointers to instances, and in ABAP are contained in reference variables. Reference variables are data objects whose data type is a reference type.
Reference types are always created with the addition REF TO. You can check the content of reference variables using the logical expression IS BOUND. It is true if a reference variable points to a valid object. References in reference variables ensure that the reference object is retained when the Garbage Collector is executed. However, weak references can also be madeto instances of classes.
The reference type is the static type of a reference variable. It defines the types of the instances its references can point to. The dynamic type of a reference variable is the type from which an object to which a reference variable points was instanced. The static type is always more general than or the same as the dynamic type. A dynamic type can be a data type or a class. A reference type or static type can be a type for a data reference variable or object reference variable. The latter is subdivided into class reference variables and interface reference variables.
Special conversion rules apply for assignments assignment reference variables, depending on the static type. These rules ensure that the dynamic type is never more general than the static type (up cast, down cast).
Data references can point to any data objects. The static type of their reference variables is either the built-in generic type data or any non-generic data type. Data reference variables can be used in statement CREATE DATA to dynamically generate data objects. You can use statement GET REFERENCE to write references to existing data objects in data reference variables. During processing of internal tables, most statements have the addition REFERENCE INTO, to make references to table rows.
You use the dereferencing operator ->* to access the data object that a data reference points to. If the static type of the data reference variable is not generic, you can write the expression dref->* at any operand positions. For data reference variables with a generic static type, you can only use statement ASSIGN dref ->* TO <fs>to assign the data object to which the data reference points to a field symbol.
Object references can point to instances of classes. The static type of their reference variables is either a class or an interfaces. You can use both types to generate objects with statement CREATE OBJECT.
From a technical point of view, a reference in ABAP does not refer directly to an object, instead it refers to what is known as a header that contains the address of the actual object as well as additional information. See also Memory management of deep data objects.