03-09-2007 10:46 AM
Hi
My issues is: pls look into following simple code to understand my problem.
call method l_obj1->method1
importing
i_para1 = a_para1.
call method l_obj2->method2
exporting
e_para1 = a_para1.
l_obj1 and l_obj2 are two objects of their respective classes.
from my first method i am importing parameter from method1 to variable a_para1 and passing the same to method2 of class for which l_obj2 is the instance.
the issue is: i_para1 and a_para1 are type compatible
but e_para1 and a_para1 are not type compatible.
but still i have to pass the variable a_para1 to e_para1.
How to do that: i am new to type casting.
pls help.
Deepak
03-09-2007 10:48 AM
declare another variable
b_para1 which is of type e_para1.
then do this
call method l_obj1->method1
importing
i_para1 = a_para1.
b_para1 = a_para1.
call method l_obj2->method2
exporting
e_para1 = b_para1.
03-09-2007 10:48 AM
declare another variable
b_para1 which is of type e_para1.
then do this
call method l_obj1->method1
importing
i_para1 = a_para1.
b_para1 = a_para1.
call method l_obj2->method2
exporting
e_para1 = b_para1.
03-09-2007 12:02 PM
What kind of TYPE are these parameters? Just to understand better your problem.
You have two types of Cast, narrowing cast and widening cast
<b>Narrowing Cast:</b> there is a switch from a view of several components (or generic type) to a view of a few components (upcast)
<b>Widening Cast:</b> switch from a view of a few components to a view of more components (downcast) and you have to use the operator "?=".
This is very usefull to cast assignment of Data Reference and Subclass x Superclass.
Ex:
DATA: int TYPE i VALUE 15,
Ref_int TYPE REF TO i,
Ref_gen TYPE REF TO data. <i>generic type</i>
GET REFERENCE OF int INTO ref_int.
<i>* narrowing cast:</i>
ref_gen = ref_int.
<i>* widening cast:</i>
Ref_int ?= ref_gen.
I hope this example help you with cast, anyway you always can use Interface or Inheritance
03-13-2007 2:55 PM
hi,
You Dont need narrowing or widening casting inthis case, as this is only for objects. As the parameter that you are using are of simple typess,, you can simply move the contents to a_para1 to a variable that is compatiable with the exporting paramter of method2.
declare m_para1 with same type as e_para1.
call method l_obj1->method1
importing
i_para1 = a_para1.
m_para1 = a_para1.
call method l_obj2->method2
exporting
e_para1 = m_para1
Regards,
Richa