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: 

How to get the parent of cl_gui_html_viewer object?

Former Member
0 Kudos

Hey all,

I want to get the parent of my  cl_gui_html_viewer object. When I debug it I can clearly see that its parent type is a reference to   cl_gui_simple_container but when I write the following code:



DATA: lo_simple_container TYPE REF TO cl_gui_simple_container.

lo_simple_container = lo_html_header->parent.

and want to active it. It gives me the following error:


The type of ''LO_HTML_HEADER->PARENT'' cannot be converted to the type of ''LO_SIMPLE_CONTAINER''

but why if I am using the right reference type? Can somebody tell me how can I get the parent of my object lo_html_header?
Thank you.

Regards,
RB

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

This is a question of up and down casting (or widening/narrowing cast respectively).

You must use one of the two variants :

  • up casting : more_general = less_general.
  • down casting : less_general ?= more_general

In your case, you have:

  • <ref to cl_gui_simple_container> = <ref to cl_gui_container>, i.e. it's down casting

So you must use:

  • lo_simple_container ?= lo_html_header->parent.

ABAP documentation : http://help.sap.com/abapdocu_702/en/?url=ABENCAST_CASTING_GLOSRY.htm

1 REPLY 1

Sandra_Rossi
Active Contributor
0 Kudos

This is a question of up and down casting (or widening/narrowing cast respectively).

You must use one of the two variants :

  • up casting : more_general = less_general.
  • down casting : less_general ?= more_general

In your case, you have:

  • <ref to cl_gui_simple_container> = <ref to cl_gui_container>, i.e. it's down casting

So you must use:

  • lo_simple_container ?= lo_html_header->parent.

ABAP documentation : http://help.sap.com/abapdocu_702/en/?url=ABENCAST_CASTING_GLOSRY.htm