‎2006 Jul 19 6:22 PM
Hello,
Im reading the documentation on =? operator, and dont really understand how it works, can any body tell me its functionality?
Thanks
Rajesh Thomas.
‎2006 Jul 19 6:30 PM
This is used in ABAP objects. It is uses when moving an object refernce from one to another. For example. Lets say tht you have an object vehicle and and object car. Car is a vehicle, so the casting would be successful.
vehicle ?= car.
If it was reverse the casting would fail, because vehicle is not car.
car ?= vehicle.
Regards,
Rich Heilman
PS.
Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
Spread the wor(l)d!
‎2006 Jul 19 6:30 PM
This is used in ABAP objects. It is uses when moving an object refernce from one to another. For example. Lets say tht you have an object vehicle and and object car. Car is a vehicle, so the casting would be successful.
vehicle ?= car.
If it was reverse the casting would fail, because vehicle is not car.
car ?= vehicle.
Regards,
Rich Heilman
PS.
Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
Spread the wor(l)d!
‎2006 Jul 20 7:15 AM
This operator is used when ur widening the cast. i.e., assigning a reference of a superclass to a subclass.
for eg:
u have 3 classes airplane, cargo_airplane1, cargo_airplane2; airplane being the superclass and the other 2 being its subclasses.
create object cargo_airplane1.
airplane = cargo_airplane1.
cargo_airplane2 ?= airplane.
The type of case described above is known as a widening cast because it changes the view to one with more details. The instance assigned (a cargo plane in the above example) must correspond to the object reference (cargo_airplane1 in the above example), that is, the instance must have the details implied by the reference
The widening cast in this case does not cause an error because the reference airplane actually points to an instance in the subclass lcl_cargo_airplane. The dynamic type is therefore REF TO lcl_cargo_airplane.
But if u try creating an object of airplane and assign it to cargo_airplane1 directly -
cargo_airplane ?= airplane
this would result in runtime error.
Here the widening cast produces the MOVE_CAST_ERROR runtime error that can be caught with CATCH ... ENDCATCH, because the airplane reference does not point to an instance in the subclass lcl_cargo_airplane, but to a general airplane object. Its dynamic type is therefore REF TO lcl_airplane and does not correspond to the reference type cargo_airplane.
Hope it is clear now.
-Aarthi.