Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between call method

Former Member
0 Likes
731

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 ?=

5 REPLIES 5
Read only

h_senden2
Active Contributor
0 Likes
704

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.

Read only

Former Member
0 Likes
704

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....

Read only

Former Member
0 Likes
704

Hi;

these are widen and narrow casting respectively.

Regardfs

shashi

Read only

former_member189420
Active Participant
0 Likes
704

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.

Read only

Former Member
0 Likes
704

thanks