Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ABAP Objects Casting error

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.

<i>Code:</i>

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.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question