Skip to Content
author's profile photo Former Member
Former Member

? operator

go_employee ?= cl_pt_employee=>get_employee( p_pernr ).

What does this statement mean. In normal abap there is no ? operator.

Pls advice

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 19, 2008 at 04:17 AM

    Hi,

    The ?= operator implements a widening cast, also called a down cast.

    Whenever a static type check is not possible or when the type checks are to be performed at program runtime, you must use the statement

     MOVE ... ?TO ... 

    or the casting operator (?=). The casting assignment replaces the assignment operator (=). In the MOVE... ? TO statement, or when you use the casting assignment, there is no static type check. Instead, the system checks at runtime whether the object reference in the source variable points to an object to which the object reference in the target variable can also point. If the assignment is possible, the system makes it, otherwise, the catchable runtime error MOVE_CAST_ERROR occurs.

    Syntax rules force you to use casting whenever a static type check is not possible, for example:

     cref1 ?= iref1. 

    Here, an interface reference is assigned to a class reference. For the casting to be successful, the object to which iref1 points must be an object of the same class as the class of the class variable cref1 or one of its subclasses..

    Hope this helps.

    Thanks,

    Balaji

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 19, 2008 at 04:00 AM

    Hi,

    This operator is used in ABAP OOP concept.

    It is used for type casting .

    Thanks,

    Poonam.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi ,

      Please consider a example for widening cast

      You use widening cast to move the view to more details ex. 'Cargo airplane'.

      Data : Airplane type lcl_airplane,

      cargo_airplane type lcl_cargoairplane,

      cargo_airplane2 type lcl_cargoairplane

      Create object cargo_airplane.

      airplane = cargo_airplane . (Narrowing cast)

      cargo_airplane2 ?= airplane. (widening cast)

      Hope this helps.

      Thanks,

      Poonam.

  • author's profile photo Former Member
    Former Member
    Posted on Mar 19, 2008 at 09:06 AM

    hai Abraham,

    Narrowing cast means that the assignment changes from a more specialized view (with visibility to more components) to a more generalized view (with visibility to fewer components).

    Narrowing cast is also referred to as “up cast” . “Up cast” means that the static type of the target variable can only change to higher nodes from the static type of the source variable in the inheritance tree, but not vice versa.

    Reference variable of a class assigned to reference variable of class : object

     Class c1 definition.
    Endclass.
    
    Class c1 implementation.
    Endclass.
    Start-of-selection.
    Data:
    orefc type ref to object,
    oref1 type ref to c1.
    
    Create object :oref1.

    .

    Narrowing Cast : Static type of target more general than Static type of source.

    Orefc = oref1.

    Regards.

    Eshwar.

    Add a comment
    10|10000 characters needed characters exceeded

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.