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

Statement in ABAP.

Former Member
0 Likes
691

Hi Gurus,

Can someone tell me what does this statement signify ?

os_ps ?= cl_xx_system=>get_xxxx_yyyy( ).

Please reply me in detail.

Regards,

Binay.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
675

hai binay sankar,

This ?= operator is called dynamic cast operator. This is espesicaially used in the following case.

When you don't want to perform the static type check and checks when the object reference in the source variable points to the object referenced in the target variable or not at run time by the system.

if the assignment is not possible, it gives

MOVE_CAST_ERROR error at runtime.

This casting is normally done as

objref1 ?= objref2 or MOVE objref1 ?= objref2.

This type of casting is needed in downward casting in inheritance hierarchy.

if it is useful , rewards points.

thank you,

prasad g.v.k

In the inheritance scenario,

when an object reference of specialized interface referenced to a more generalized object reference , then this casting should be required to not getting any error from static checking.

Hi Gurus,

Can someone tell me what does this statement signify ?

os_ps ?= cl_xx_system=>get_xxxx_yyyy( ).

Please reply me in detail.

Regards,

Binay.

4 REPLIES 4
Read only

Former Member
0 Likes
675

hi,


CLASS lcl_airplane DEFINITION.
PUBLIC SECTION.
METHODS: estimated_fuel_consumption
IMPORTING im_distance TYPE ty_distance
RETURNING VALUE(re_fuel) TYPE ty_fuel,
CLASS-METHODS: get_count RETURNING VALUE(re_count) TYPE i.
ENDCLASS.


DATA: plane1 TYPE REF TO lcl_airplane,
plane2 TYPE REF TO lcl_airplane,
fuel_consumption TYPE ty_fuel,
count_planes TYPE i.

* Instantiation omitted
* CALL METHOD plane1->get_count RECEIVING re_count = *count_planes.
count_planes = lcl_airplane=>get_count( ).
fuel_consumption = plane1->estimated_fuel_consumption( 1000 ) + plane2->estimated_fuel_consumption( im_distance = 1500 ).

The syntax for instance methods (analogous to static methods) is as follows, depending on the number of

IMPORTING parameters :

no IMPORTING parameters: ref->func_method( )

exactly 1 IMPORTING parameter : ref->func_method( p1 ) oder

ref->func_method( im_1 = p1 )

several IMPORTING parameters : ref->func_method( im_1 = p1 im_2 = p2 )

Hope this helps, Do reward.

Edited by: Runal Singh on Mar 27, 2008 4:54 PM

Read only

0 Likes
675

Hi,

Thans for your reply but my concern is the operator ?= in the statement.

what does ?= signify ?

Regards,

Binay.

Read only

0 Likes
675

Hi,

If a static type check cannot take place when you make an assignment between two reference variables, you must use the casting assignment MOVE ... ?TO ... . If you are using the equivalent of this statement, the assignment operator '=', you must change this to '?='. The'?=' expression is not an ABAP Objects operator, but simply a way of writing the casting assignment.

Reward if helpful.

Regards.

Read only

Former Member
0 Likes
676

hai binay sankar,

This ?= operator is called dynamic cast operator. This is espesicaially used in the following case.

When you don't want to perform the static type check and checks when the object reference in the source variable points to the object referenced in the target variable or not at run time by the system.

if the assignment is not possible, it gives

MOVE_CAST_ERROR error at runtime.

This casting is normally done as

objref1 ?= objref2 or MOVE objref1 ?= objref2.

This type of casting is needed in downward casting in inheritance hierarchy.

if it is useful , rewards points.

thank you,

prasad g.v.k

In the inheritance scenario,

when an object reference of specialized interface referenced to a more generalized object reference , then this casting should be required to not getting any error from static checking.