cancel
Showing results for 
Search instead for 
Did you mean: 

Access to a Mainwindow class variable....

Former Member
0 Kudos

I know that I get access to variables of the Controller class using controller->variable_name, but if there's a variable which is to accessed by ALL of my controller classes how can I gain access to Mainwindow class variable?.

I would like to access this variable from within my BSP, and also from within my Javascript code which is called via BSP.

Can anyone give examples of this can be done?.

Jon

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

wouldn´t it be better to work with a model object (using class CL_BSP_MODEL), which contains all variables that are visible to all controller classes ??

*     create model object:
      mymodel ?= create_model( class_name = 'ZCL_MYMODEL'
                               model_id   = 'mymodel' ).

      set_model( model_id = 'mymodel'
                 model_instance = mymodel ).

Of course, it´ll depend how you structure your objects, especially your controller classes, so that the model object is visible to the classes. I always declare my MAIN class and a second level classes, which inherit from the Main class. I could have a 3rd. level of controller classes which inherit from the 2nd. level. In the child classes I get the model object like this:

mymodel ?= parent->get_model( 'mymodel' ).

This saves me much work for not transfering data from 1 class to another or for reading data with RESPONSE, RUNTIME, etc. The topic model object is also very helpful when working with data binding, because you can save much work and time writting a small code.

StefanRoesch
Active Participant
0 Kudos

another way would be to use a application class. Attributes of your application class object can be accessed from all controllers and views.

if you really want to access the attributes of your main-controller you can e.g. store a reference of your main controller in your application class and access the values this way.

regards,

stefan.

0 Kudos

Dear Stefan,

how to access application class from the controller?

I can acces attributes and methods of my application object in the views with application->my_attribute but I cannot access my attributes with object "application" within the controller (sintax checks tells me that attribute "my_attribute" does not exist?

Does not obect "application" within controller refers to the instance of application class?

Do I have to always create the object in the controler like this?

Data: co_application type ref to YMM_MONITOR_APL_CL.

CREATE OBJECT co_application TYPE YMM_MONITOR_APL_CL.

Thanks in advance.

Dmitry

StefanRoesch
Active Participant
0 Kudos

Hey Dmitry,

no, you don't have to create your application object. You just need the Data declaration and to do a cast like this:

data: app type ref to zclmyapplicationclass.
      app ?= application.

now you can access all your methods and attributes without creating the object and you keep your data applicationwide. just use the referece app->...

hope that help.

stefan

Former Member
0 Kudos

Stephan,

I am a little confused due the word 'Application' in the above thread.

I am attempting to gain access to an attribute of the Component controller.

I have BSP code within a View controller and need to access this attribute value.

In my case, this attribute contains the height of a grid which I use across multiple views.

Any idea how I might gain access to this attribute?.

Jon

StefanRoesch
Active Participant
0 Kudos

Hi Jon,

"Main-Window", "Component controller" are terms from Webdynpro...you don't mix up something here?

In every controller you can find the reference to the parent controller in attribute m_parent. maybe this helps.

do you use a model in your application?