Skip to Content

confusion about casting operator ?= in webdynpro

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Feb 02, 2012 at 08:24 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.