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

runtime error while casting.

Former Member
0 Likes
424

Hi,

When i assign a superclass reference to subclass instance it raises runtime error message which i hav mentioned below.

the statement which i used in the program is

subclass_instance ?= superclass_ref. " (DOWNCASTING)

" It was tried to assign a reference to a rereference variable using the

'CAST' operation ('?=' or 'MOVE ?TO').

However, the current content of the source variable does not fit into

the target variable."

can anyone tell me how to rectify this error. Thanks...

Regards,

Joseph.

1 REPLY 1
Read only

matt
Active Contributor
0 Likes
341

My guess is you've something like this:

data: superclass_ref type ref to superclass,

subclass_instance type ref to subclass.

create object superclass_ref.

subclass_instance ?= superclass_ref.

The problem is that the object superclass_ref is of type superclass. When you try to downcast, you can't because superclass doesn't have, for example, all the attributes of subclass. In order to use down casting, the receiving object reference MUST be of the type of the subclass. So you need something like this:

create object superclass_ref TYPE subclass.

subclass_instance ?= superclass_ref.

Matt