03-19-2008 3:36 AM
go_employee ?= cl_pt_employee=>get_employee( p_pernr ).
What does this statement mean. In normal abap there is no ? operator.
Pls advice
03-19-2008 4: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
03-19-2008 4:00 AM
Hi,
This operator is used in ABAP OOP concept.
It is used for type casting .
Thanks,
Poonam.
03-19-2008 4:11 AM
03-19-2008 4:36 AM
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.
03-19-2008 4: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
03-19-2008 9: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.