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

Get class Instance, and then get hers attributes

former_member998879
Participant
0 Likes
2,759

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

1 ACCEPTED SOLUTION
Read only

Pawan_Kesari
Active Contributor
0 Likes
1,457

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

7 REPLIES 7
Read only

Pawan_Kesari
Active Contributor
0 Likes
1,458

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

Read only

0 Likes
1,457

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

Read only

0 Likes
1,457

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 .

Read only

0 Likes
1,457

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

Read only

0 Likes
1,457

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

Read only

0 Likes
1,457

Thanks Uwe,

but does not work.

Compiler say everything ok, but error occured when executing the instruction


  lo_left_controller ?= parent.

Davide

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,457

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