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

Hi

Former Member
0 Likes
268

Hi,

I have declared two classes with names, ZCL_ONE, ZCL_TWO.

ZCL_TWO is inhering ZCL_ONE.

Now i am using them in the se38 program.

While i use it, Narrow casting is working fine, But widening casting is not working.

It is throwing an exception or a dump if i do not catch an exception.

Code:


DATA: OBJ1 TYPE REF TO ZCL_ONE,
           OBJ2 TYPE REF TO ZCL_TWO.

CREATE OBJECT OBJ1.

OBJ2 ?= OBJ1.

The above code is giving me dump. Any guesses about how to solve it.

I am able to work with the Narrow casting.. which is below code.. It is working fine.


DATA: OBJ1 TYPE REF TO ZCL_ONE,
          OBJ2 TYPE REF TO ZCL_TWO.

CREATE OBJECT OBJ2.

OBJ1 = OBJ2.

How to resolve the error.

Thanks in Advance.

1 REPLY 1
Read only

Former Member
0 Likes
249

Try the Below code it was working

"This  peice  i changed  for widening casting 
DATA: OBJ1 TYPE REF TO ZCL_ONE,
           OBJ2 TYPE REF TO ZCL_TWO,
            OBJ  LIKE  OBJ2.

CREATE OBJECT OBJ2.
OBJ1 =  OB2 .
OBJ ?= OBJ1.

"This is your code which  is correct  for Narrow casting

DATA: OBJ1 TYPE REF TO ZCL_ONE,
           OBJ2 TYPE REF TO ZCL_TWO.

CREATE OBJECT OBJ2.
OBJ1 =  OB2 .

Reward points if it is usefull...

Girish