SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Assigning References → Setting Reference Variables → Assignment Rules for Reference Variables →Assignments between Data Reference Variables
Data reference variables are either completely typed or typed with the generic type data.
Up Casts in Data References
An up cast in data references is possible in the following cases:
Note
With respect to checks on static types, structured types behave like classes. Two differently structured types do not match, even if they consist of identical components.
Down Casts in Data References
A down cast in data references is only possible if the static type of the source variable is generic and that of the target variable is completely typed. The syntax check makes it impossible that the static types of the source variable and the target variable are both completely typed, but not identical.
Example
The assignment from dref1 to dref2 is an up cast. The assignment from dref2 to dref1 is a down cast, which in the example below raises an exception. If the statement CREATE DATA had the addition TYPE i, the down cast would also have been successful.
DATA: dref1 TYPE REF TO i,
dref2 TYPE REF TO data.
CREATE DATA dref1.
dref2 = dref1.
CREATE DATA dref2 TYPE string.
TRY.
dref1 ?= dref2.
CATCH cx_sy_move_cast_error.
...
ENDTRY.