cancel
Showing results for 
Search instead for 
Did you mean: 

How can i create an instance of the application class via code????

Former Member
0 Kudos

hello, i want to know...if anybody knows...the way via code to create another instance of the application class or create an object of the application class and the bsp application work with it instead of the initial object.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Maria,

Once you give the application class name in the properties page of your bsp application then automatically

all the layout pages will have an object named application which will be assigned to your application class.

You can use this object application to access your class variables or objects.

But in order to access the application class object in the Event Handler section you need to create an application class object...

The code for that is...

Data: application type ref to <Application Class Name>.
CREATE OBJECT application TYPE <Application Class Name>.

If you are creating 2 objects/instances of an application class say for example application1 and application2 respectively, then

You can use both the objects simultaneously...

Only thing is that when you are modifying the static attributes of the application it affects both the instances.

Hope it helps you.

Regards,

Maheswaran.B

Message was edited by: Maheswaran B

Former Member
0 Kudos

Hi,

I don't agree with Maheswaran. The variable application is reserved in bsp context and refers to the application object of your bsp app. It is accesible in event-handler, controller, and bsp-coding - I think everywhere you'll need it. You simply have to cast it into the correct type.

Maheswaran's suggestion simply creates a local instance of the same type of you application object. It will not be known at the following request-processing but instantiatet again.

By the way, why do you want to overwrite you application object with another instance? I would always change its attributes and your are safe.

Regards,

Sebastian

Former Member
0 Kudos

Hi,

First of all i admit my mistake. (It's a spelling mistake)

Sorry! guys.

1.For Page with flow logic you can access the application object in the Event Handler.

2.When you are using MVC's you need to create the application object in the corresponding controller of the view.

Am i correct. I thought it is a MVC's and during my reply i wrote EventHandler instead of Controller.

Thanks & Regards,

Maheswaran.B

Former Member
0 Kudos

Also in controller you don't have to instantiate a new application object it is already known in your controller but not typed correctly. You have to cast it:

Data: co_application type ref to <Application class name>.

co_application ?= application.

Now you have full access to your application object.

Regards,

Sebastian

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I agree with Sebastian - you should never have to recreate the application object instance. It is available (sometimes via casting) in all aspects of BSP.

Furthermore I'm not sure it ever be wise to try and recreate the application class as was asked in the original question:

>the way via code to create another instance of the >application class or create an object of the application >class and the bsp application work with it instead of >the initial object.

The application class instance is created and managed by the BSP Framework. I don't think it would be wise to try and monkey around with it in the way described. This would seem to violate the model of the use of the application class.

You should have one class definition that serves as the single application class throughout the entire lifetime of the application. If you are needing a different class definition then you are probably using the application class for something it wasn't designed for.

If you are writting a lot of business logic in the application class and that is the reason you need to change it out - you would be better off placing this code somewhere else. Personally I really dislike placing any business logic in the application class. I only use it hold application variables needed across the entire application (like references to model instances or interator instances) for easy access.

Ideally you would use MVC and this coding would be in your model class. You can have muliple model classes in an application and you can control your initialization if you wish.

Perhaps a better description of why you feel that you need to change out the application class would be helpful.

Former Member
0 Kudos

Hi,

Don't you need to use ?=

Cheers,

Rich

guillaume-hrc
Active Contributor
0 Kudos

Hi Mariana,

Well, the first part is quite easy :

DATA: w_appl TYPE REF TO CL_BSP_APP_IT00.

CREATE OBJECT w_appl.

But the second is a problem. Indeed, something like this :

application = w_appl.

makes the compiler a bit angry, for it seems not possible to change the application.

Another possibility, although I have not tested it, would simply to have some kind of 'reset' method... instead of instanciating a new object ?

Best regards,

Guillaume