‎2009 Feb 19 1:14 PM
What is the difference between following statements:
descr_ref ?= cl_abap_typedescr=>describe_by_data( i_stock ).
descr_ref = cl_abap_typedescr=>describe_by_data( i_stock ).
When do I have to use ?=
‎2009 Feb 19 1:18 PM
If descr_ref is of type ref to cl_abap_typedescr you can use =
If descr_ref is of type ref to <a parent class of cl_abap_typedescr> you have to use ?=
because the method is maybe introduced in the subclass and don't exist in the upper class.
‎2009 Feb 20 5:00 AM
Hi,
Assignments between interface references whose interfaces are not related to each other cannot be checked statically and must therefore be formulated using the cast operator u201C?=u201D.
For this type of assignment, a check must be carried out at runtime to see whether the class of the instance that the source reference points to also supports the interface that the target reference refers to. If this is the case, the cast is carried out, otherwise the catchable runtime MOVE_CAST_ERROR occurs.
This type of cast is neither a widening nor a narrowing cast, rather a switch from one view of an object to another.
Note: For detailed information please refer the below links,
http://www.abapprogramming.net/search?q=casting
http://www.scribd.com/doc/7203248/Abap-Objects
Thank U,
Jay....
‎2009 Feb 20 6:37 AM
Hi;
these are widen and narrow casting respectively.
Regardfs
shashi
‎2009 Feb 20 6:54 AM
Hi,
Consider Class superclass whose subclass is Class subclass.
Let, superobject be an instance of superclass and subobject be an instance of subclass.
Use "=" when you want to assign subclass object to superclass object. As the superclass Object can be assigned to any of it's child class objects.
superobject = subobject.
Use "?=" when you want to assign superclass object to it's subclass object only if the superclass object is pointing to the same subclass object.
If superobject is pointing to subobject. Say superobject = subobject has been already done.
Now you want to access the exclusive members of subclass object. Which can not be accessed by superobject though it is pointing to subclass object (subobject). In this case you need to use "?=" to cast from superclass to subclass as the superobject is pointing to the same subobject.
subobject ?= superobject. "{ Superobject is pointing to an instance of subclass. Else it will throw MOVE_CAST_ERROR }
In short, use ?= when you want to assign a superclass reference to a subclass reference if the superclass reference is pointing to the same subclass reference else run time exception occurs.
Hope this helps you.
Let me know if you need more clarification on this.
‎2009 Feb 23 1:51 PM