Application Development 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: 

doubt in Abap code

Former Member
0 Kudos

What is the meaning of the below statement

lo_desc ?= <ls_descriptor>-descriptor.

5 REPLIES 5

Former Member
0 Kudos

Hi Sumithra,

Please refer the below thread,

Best Regards.

Former Member
0 Kudos

?= is called casting operator. Please refer to definition below.

Special assignment operator ( ?=) for assignments between reference variables, whose assignability is checked as early as the runtime starts. Necessary for Widening Cast.

(Ref: SAP Documentation)

Former Member
0 Kudos

?= is called Casting Operator. It is used to instruct ABAP to skip type checking at compile time and do the check at runtime.

For example, the following code would issue a syntax check because at compile time it is not possible to verify if oref1 actually points to an object of the class cl_myclass.

DATA: aref1 TYPE REF TO object,

bref2 TYPE REF TO cl_someclass.

...

bref2 = aref1.

So instead we use the casting operator like so.

aref1 ?= bref1 or

MOVE aref1 ?to bref2.

This shifts the verification to the runtime.

Former Member
0 Kudos

Hi

cref1 ?= iref1.

it's a casting operation, in this way the object cref1 is poiting to the same object iref1, so they aren't the same object, but they are two different objects pointing to the same instance.

It uses =? instead of = when the class of IREF1 is a subclass of class of CREF1.

Max

Former Member
0 Kudos

Hi,

Like class references, you can assign interface references to different reference variables. You can also make assignments between class reference variables and interface reference variables. When you use the MOVE statement or the assignment operator (=) to assign reference variables, the system must be able to recognize in the syntax check whether an assignment is possible.

Suppose we have a class reference <cref> and interface references <iref>, <iref1>, and <iref2>. The following assignments with interface references can be checked statically:

<iref1> = <iref2>

Both interface references must refer to the same interface, or the interface of <iref1> must contain the interface <iref2> as a component.

<iref> = <cref>

The class of the class reference <cref> must implement the interface of the interface reference <iref>.

<cref> = <iref>

The class of <cref> must be the predefined empty class OBJECT.

In all other cases, you would have to work with the statement MOVE ...? TO or the casting operator (?=). The casting operator replaces the assignment operator (=). In the MOVE... ? TO statement, or when you use the casting operator, 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.

You must always use casting for assigning an interface reference to a class reference if <cref> does not refer to the predefined empty class OBJECT:

<cref> ?= <iref>

For the casting to be successful, the object to which <iref> points must be an object of the same class as the type of the class variable <cref>.