‎2009 Jul 03 9:47 AM
Hi Gurus,
i'm new to ABAP Object,
creating an a BSP whit MVC controller i've try to implement the class controller,
but on a method of it i want to get instance of the class parents:
the class that i implement is an extension of CL_BSP_CONTROLLER2.
In this class in the method DO_REQUEST ( for example ) i try to get the instance of the class
parent ( and i got it! ) using this syntax:
data: Parent type ref to IF_BSP_DISPATCHER, " type take from attribute M_PARENT of the class
Parent = ME->M_PARENT.
In debug i see that 'Parent' get rightly the class parent instance but than i want do this:
(i want get the sub controller of the main contoller 'parent', in debug i can see everything fine)
SubController = Parent->GET_ATTRIBUTE(LEFT_CONTROLLER).
But the compiler say that the class instance 'Parent' has no methods and no attribute.
i've try other syntax like:
call METHOD Parent_>GET_ATTRIBUTE
IMPORTING
LEFT_CONTROLLER)
call METHOD ME->M_PARENT->GET_CONTROLLER
EXPORTING
CONTROLLER_ID = 'search'
IMPORTING
CONTROLLER_INSTANCE = Parent2
No one work!
How can i do?
Here screnshot of that i see in debug mode, and that i want get:
http://img190.imageshack.us/i/1debugscreen.jpg/
http://img10.imageshack.us/i/2debugscreen.jpg/
Thanks in advance,
Davide
‎2009 Jul 03 11:26 AM
The parent of CL_BSP_CONTROLLER2 is of type IF_BSP_DISPATCHER.
And IF_BSP_DISPATCHER definitely doesn't have any property LEFT_CONTROLLER. So I think you are looking at the wrong place.
Access LEFT_CONTROLLER attribute of class ZGEO_CONTROLLER_MAIN. I think instance of ZGEO_CONTROLLER_MAIN is available in program.
Edited by: Pawan Kesari on Jul 3, 2009 4:03 PM
‎2009 Jul 03 11:26 AM
The parent of CL_BSP_CONTROLLER2 is of type IF_BSP_DISPATCHER.
And IF_BSP_DISPATCHER definitely doesn't have any property LEFT_CONTROLLER. So I think you are looking at the wrong place.
Access LEFT_CONTROLLER attribute of class ZGEO_CONTROLLER_MAIN. I think instance of ZGEO_CONTROLLER_MAIN is available in program.
Edited by: Pawan Kesari on Jul 3, 2009 4:03 PM
‎2009 Jul 03 11:47 AM
Hi Pawan,
classes ref to CL_BSP_CONTROLLER2 like my controller class, have an attribute
M_PARENT type IF_BSP_DISPATCHER.
If the class is a subclass of an main class it has the M_PARENT attribute containing the instance of the parent class,
i can see in debug mode ( here example: http://img40.imageshack.us/img40/1648/3debugscreen.jpg )
i can get this attribute:
data: Parent type ref to IF_BSP_DISPATCHER, " type take from attribute M_PARENT of the class
Parent = ME->M_PARENT.
but the interface IF_BSP_DISPATCHER has no attribute and no method defined, and if i declare 'Parent' as type ref to
CL_BSP_CONTROLLER2 the compiler return error
<=> "The type of "PARENT" cannot be converted to the type of "ME->M_PARENT". "
Davide
‎2009 Jul 03 12:00 PM
From screen it appear that M_PARENT attribute has instance of class ZGEO_CONTROLLER_MAIN.
I wonder if you could just do it this way
data: Parent type ref to ZGEO_CONTROLLER_MAIN.
Parent = ME->M_PARENT .
‎2009 Jul 03 12:02 PM
Hello Davide
Without knowing the relation between the classes (hierarchy, interfaces) it is difficult to understand your problem.
Assuming that your left controller always is an instance of class ZGEO_CONTROLLER_SEARCH (assumption: implements interface IF_BSP_DISPATCHER) you could try the following:
data:
Parent type ref to IF_BSP_DISPATCHER, " type take from attribute M_PARENT of the class
lo_left_controller TYPE REF TO zgeo_controller_search.
Parent = ME->M_PARENT.
lo_left_controller ?= parent.
CALL METHOD lo_left_controller->...
Regards
Uwe
‎2009 Jul 03 12:06 PM
type ZGEO_CONTROLLER_MAIN is a type ref to CL_BSP_CONTROLLER2, and just i say above do:
data: Parent type ref to ZGEO_CONTROLLER_MAIN.
Parent = ME->M_PARENT .
doesn't work. "The type of "PARENT" cannot be converted to the type of "ME->M_PARENT"."
Thanks however for you help!
Davide
‎2009 Jul 03 12:07 PM
Thanks Uwe,
but does not work.
Compiler say everything ok, but error occured when executing the instruction
lo_left_controller ?= parent.
Davide
‎2009 Jul 03 8:41 PM
Hello Davide
There must be a simple way using casting but - as I said already - without knowing the relations and interfaces of the classes it is difficult to find the solution.
Alternatively, you may call the method dynamically.
data:
Parent type ref to IF_BSP_DISPATCHER, " type take from attribute M_PARENT of the class
lo_obj TYPE REF TO object, " root class
ld_method TYPE string.
Parent = ME->M_PARENT.
lo_obj ?= parent.
ld_method = '<name of public method>'.
CALL METHOD lo_obj->(ld_method)...
Regards
Uwe