Object reference variables are either class references or interface reference variables.
An up cast in object references is possible in the following cases:
For all other cases, not listed above under the up cast, assignment can only be programmed using a down cast.
Declaration of interfaces and classes, creation of an object in the subclass and access to the components of the object. In the statement CREATE OBJECT, an up cast occurs implicitly from c2 to iref. The interface reference iref can only be used to access the components declared in the interface i2. Method m1 of the object cannot be called using iref. After assigning the object reference to the class reference cref using a down cast, m1 can be accessed dynamically but not statically.
INTERFACE i1.
DATA a1 TYPE ...
ENDINTERFACE.
INTERFACE i2.
INTERFACES i1.
ALIASES a1 FOR i1~a1.
DATA a2 TYPE ...
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.
CLASS c2 DEFINITION INHERITING FROM c1.
PUBLIC SECTION.
METHODS m1.
ENDCLASS.
...
DATA: iref TYPE REF TO i2,
cref TYPE REF TO c1.
...
CREATE OBJECT iref TYPE c2.
... iref->a1 ...
... iref->a2 ...
...
TRY.
cref ?= iref.
CALL METHOD cref->('M1').
CATCH cx_sy_move_cast_error
cx_sy_dyn_call_illegal_method.
...
ENDTRY.