Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Casting Help

Hi,

i learn OO and maybe someone can explain me

what is the action in bold is doing ?

r_cargo ?= r_plane.

Regards

DATA: r_cargo TYPE REF TO lcl_cargo_plane.

DATA: r_plane TYPE REF TO lcl_airplane.

LOOP AT airplane_list INTO r_plane.

TRY.

r_cargo ?= r_plane.

cargo = r_cargo->get_cargo( ).

IF re_cargo < cargo.

re_cargo = cargo.

ENDIF.

CATCH cx_sy_move_cast_error INTO r_exc.

ENDTRY

replied

Hi,

As CL_ABAP_TYPEDESCR is an Abstract class having the static method as DESCRIBE_BY_DATA.

and its RETURNING parameter is typed as a reference to this superclass. since the actual parameter

gx_table is typed on the subclass CL_ABAP_STRUCTDESCR, so the object has to be assigned using

Widening Cast with operator ?= .

Please check this document which would give your more clear idea...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f2dac69e-0e01-0010-e2b6-81c1e8e5ce50

Hope this would help you.

Good luck

Narin

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question