ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Assigning References →  Setting Reference Variables → 

=, ?= - Up Cast and Down Cast

Syntax

destination_ref =|?= source_ref.

Effect

Assignment between two reference variables. The reference in source_ref is assigned destination_ref. If the assignment is successful, destination_ref points to the same object as source_ref (reference semantics). The assignment of reference variables is a special form of assignments of data objects; assignments between reference variables require two assignment operators, used in accordance with the assignment rules for reference variables:

The same applies to the right side and left side as when assigning data objects, with the following restrictions:

Notes

Example

The first two assignments in the following source code section are up casts:

The next two assignments are down casts:

CLASS c1 DEFINITION INHERITING FROM object.
ENDCLASS.

CLASS c2 DEFINITION INHERITING FROM c1.
ENDCLASS.

CLASS c3 DEFINITION INHERITING FROM c2.
ENDCLASS.

DATA oref TYPE REF TO object.
DATA oref1 TYPE REF TO c1.
DATA oref2 TYPE REF TO c2.
DATA oref3 TYPE REF TO c3.

oref1 = NEW c2( ).

oref = oref1.

TRY.
    oref2 ?= oref.
  CATCH cx_sy_move_cast_error.
    ...
ENDTRY.

TRY.
    oref3 ?= oref2.
  CATCH cx_sy_move_cast_error.
    ...
ENDTRY.

Exceptions

Catchable Exceptions

CX_SY_MOVE_CAST_ERROR