ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning References → Setting Reference Variables
REF - Reference Operator
Other versions:
7.31 | 7.40 | 7.54
Syntax
... REF type( dobj | table_exp ) ...
Alternatives
1. ... REF type( dobj )
2. ... REF type( table_exp )
Effect
A constructor expression with the reference operator REF
creates either a
data reference variable that points to the argument dobj
or controls a
table expression table_exp
.
Existing data objects and table expressions can be specified as an argument, but no further expressions or function calls.
Alternative 1
... REF type( dobj )
Effect
If a data object dobj
is specified as an argument, the operator REF
functions like the statement GET REFERENCE
and creates a
data reference
variable as a result. This variable points to the specified data object dobj
. type
determines the
static type of the result. The following can be specified for type
:
- A non-generic data type
dtype
that follows the rules of up casts in data references.
- The generic data type
data
.
- The
#
character for a data type, determined in accordance with the following hierarchy:
- If the data type required in an operand position is unique and fully recognized, the operand type is used.
- If the operand type cannot be derived from the context, the data type of
dobj
is used.
- If the data type of
dobj
cannot be recognized statically, the generic typedata
is used.
The parentheses must contain precisely one unnamed argument dobj
. If offsets/lengths
(+off(len)
) are specified,
the data type dobj
here cannot be string
or xstring
.
Notes
- The conversion operator
REF
is suitable for avoiding declarations of helper variables only needed, for example, to specify data reference variables as actual parameters.
- No empty parentheses can be specified after
REF
.
Example
Fills an internal table with the value operator VALUE
, where the component dref
is given a value using REF
. This is an excerpt from the
example for the class CL_ABAP_BROWSER. Other uses can be found in
examples of ADBC, where parameter bindings are used.
TYPES pict_line(1022) TYPE x.
DATA pict TYPE STANDARD TABLE OF pict_line WITH EMPTY KEY.
DATA ext_data TYPE cl_abap_browser=>load_tab.
ext_data = VALUE #( ( name = 'PICT.GIF'
type = 'image'
dref = REF #( pict ) ) ).
Alternative 2
... REF type( tab_exp )
Effect
If a table expression
table_exp
is specified
as an argument, the operator REF
controls the category of its result and enables a default value to be specified for unfound rows, as described in the related
section.