cancel
Showing results for 
Search instead for 
Did you mean: 

confusion about casting operator ?= in webdynpro

former_member184741
Active Contributor
0 Kudos

hi,

i have created a webdynpro component with a single view MAIN and in wdinit method i have used code wizard and generated the below code for displaying messages ( of course this is not complete code)

DATA lo_api_controller TYPE REF TO if_wd_controller.

DATA lo_message_manager TYPE REF TO if_wd_message_manager.

lo_api_controller ?= wd_this->wd_get_api( ).

CALL METHOD lo_api_controller->get_message_manager

RECEIVING

message_manager = lo_message_manager.

my doubt is at line o_api_controller ?= wd_this->wd_get_api( ) where casting operator ?= is used. as far as my knowledge goes down cast is used when which the type of the target variable more specific than the static type of the source variable

here the source variable/ outpur of the wd_get_api() is IF_WD_VIEW_CONTROLLER and target varible refers to IF_WD_CONTROLLER. here IF_WD_VIEW_CONTROLLER is more specific than IF_WD_CONTROLLER. what i mean to say is IF_WD_VIEW_CONTROLLER has IF_WD_CONTROLLER as one of ts interfaces in 'interfaces' tab ( in se24). so what is wrong here?

thanks

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can have an Up Cast as well. From the online help: Also referred to as widening cast. Assignment between reference variables, where the static type of the target variables is similar or identical to the static type of the source variables.

We are talking about code wizard generation. In this case the Up Cast allows the same code template to be used in a variety of situations where the source varaible might be different.

former_member184741
Active Contributor
0 Kudos

Hi Thomas,

Nice to hear from an expert like you.

I have changed the code from ?= to just = and everyhting worked fine. so in this case whether you use = or ?= does not matter. am i right? Can you give me an example in ABAP webdynpro where the usage of ?= is must.

thanks

Answers (0)