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: 

type problems

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

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.

3 REPLIES 3

former_member181962
Active Contributor
0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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