2008 Mar 27 11:15 AM
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.
2008 Mar 27 2:04 PM
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.
2008 Mar 27 11:20 AM
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
2008 Mar 27 12:57 PM
Hi,
Thans for your reply but my concern is the operator ?= in the statement.
what does ?= signify ?
Regards,
Binay.
2008 Mar 27 1:02 PM
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.
2008 Mar 27 2:04 PM
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.
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |