cancel
Showing results for 
Search instead for 
Did you mean: 

model class instance in all controller

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello.

There is a model class containing the business logic.

In my component controller I instantiated the model class 'CL_IRM' in the init method:

data: lo_irm type ref to cl_irm.
CREATE object LO_IRM.

I also have an attribute in the compController:

lo_irm type ref to cl_irm

.

How can I get and set data of the same instance lo_irm from the other controllers (views).

What's the right syntax?

Do i have to set an attribute type ref to cl_irm also in the other controllers to work with the same instance.

Is there a general recommendation for data transport between model class and different controllers.

Kind regards.

Carola

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Carloa,

Have an instance attribute in your component controller. This attribute can be accessed from all the views using wd_comp_controller->attribute_name. In the init method, after creating the object, assign it to the comp controllers attribute. When you want to access it in the component controller itself, use prefix wd_this. And when accessing from the views, use wd_comp_controller.

The class methods can be called directly as wd_comp_controller->attribute_name->method_name( ).

Regards

Nithya

mohammed_anzys
Contributor
0 Kudos

Hi carola,

You could access the component controller attributes in the view using

wd_comp_controller->lo_irm .

data:lo_myclas type ref to cl_irm.

lo_myclass = wd_comp_controller->lo_irm .

And in the view you could use lo_myclass and access all you methods in the class.

Thanks

Anzy

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Anzy.

why do I need

data:lo_myclas type ref to cl_irm.
lo_myclass = wd_comp_controller->lo_irm .

Could'nt I acess the methods also directly via

wd_comp_controller->lo_irm->method( ) ?

Is it just a shorter way to write it down?

Kind regards.

Carola

Former Member
0 Kudos

Yeah you can. You can directly do

if wd_comp_controller->lo_irm is initial.

create object wd_comp_controller->lo_irm.

endif.

And you can access the methods directly.

Answers (5)

Answers (5)

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thanks, to you Anzy and Nithya.

Carola

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

just one more question to Anzy's response

mohammed_anzys
Contributor
0 Kudos

Hi Carola,

You can directly access..Just for simplicity and understand teh concept ..i wrote it that way.

Tahnks

Anzy

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thanks.

Because the model class does already exist whereas the assistance class must have a certain inheritance, the assist class does not help in this case.

Former Member
0 Kudos

Hi,

maybe it's better to use an assistance class,

which you set in the component overview,

this class can automatically be reached by attribute wd_assist,

grtz

Koen

S-H
Active Participant
0 Kudos

Hi Carola,

if we want to use the used component we instantiate the component, use the code wizard and it will generate the code.

If we want to transfer the data between the components, we can create the interface methods or using the context. If you want to call the methods then use the reference of the interface.

Best regards,

Suresh