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

Casting from reference to data -> class

marcin_cholewczuk
Active Contributor
0 Likes
2,743

Hi all,

how can I cast object that was declared as REF TO DATA on REF TO cl_some_class?

DATA: lr_source TYPE REF TO data.
FIELD-SYMBOLS<lr_dest> TYPE REF TO CL_WDR_CONTEXT_ELEMENT.


I've tried:

ASSIGN lr_source->* TO <lr_dest> CASTING.

but it's leading to error. Any ideas?

Best Regards

Marcin Cholewczuk

1 ACCEPTED SOLUTION
Read only

iftah_peretz
Active Contributor
0 Likes
1,638

Hi,

Whats the error you are getting when using

ASSIGN lr_source->* TO <lr_dest> CASTING. 

Best,

Iftah

6 REPLIES 6
Read only

Former Member
0 Likes
1,638

You have to use "Create data" statement before de-referencing data reference variable.

CREATE DATA lr_source TYPE REF TO cl_wdr_context_element

Regards,Vinod

Read only

0 Likes
1,638

Data was already created by SAP (as you can see in screenshot). I need only to cast it to other type.

Best regards

Marcin Cholewczuk

Read only

iftah_peretz
Active Contributor
0 Likes
1,639

Hi,

Whats the error you are getting when using

ASSIGN lr_source->* TO <lr_dest> CASTING. 

Best,

Iftah

Read only

0 Likes
1,638

Hi,

it's webdynpro application and on www I'm getting

500 SAP Internal Server Error

ERROR: Type conflict with ASSIGN in program /1BCWDY/H1UTWYPFI3KEUNC5NTTT==CP . (termination: RABAX_STATE)

Best regards

Marcin Cholewczuk

Read only

0 Likes
1,638

Hi,

I know it's a webdynpro.

Ok, so I can help you, I need the code in the method where you are using it (for example in

WDDOINIT,WDDOMODIFYVIEW) because it is not clear how did you created the reference lr_source. Meanwhile try (with out the casting):

ASSIGN lr_source->* TO <lr_dest>.

Best,

Iftah.

Read only

0 Likes
1,638

Ok, i did it.

DATA: lr_source TYPE REF TO data,

           lr_dest TYPE REF TO CL_WDR_CONTEXT_ELEMENT.
FIELD-SYMBOLS<lr_any> TYPE ANY.

   ASSIGN
lr_source->* TO <lr_any>.
   lv_dest ?= <lr_any>.

Best Regards

Marcin Cholewczuk