cancel
Showing results for 
Search instead for 
Did you mean: 

Model Instance scope

Former Member
0 Kudos

Hi,

I have 2 sub componentes and one main component.I used a function module in both the sub components.I created the component by manual as

wdThis.wdGetTestAddComponentUsage().createComponent();

i Added a record using add componet and i executed the same to dispaly the size of output node for total no-of records.

But the problem here is it is not showing the latest no-of records in the front end.But if we log on to SAP and check for the total no-of records it is showing the latest no-of records.

So i kept the scope of the model instance as WDModelScopeType.COMPONENT

as given below

com.sap.tc.webdynpro.progmodel.model.api.WDModelScopeType;

Z<MODEL NAME> input = new Z<MODEL NAME>(WDModelScopeType.COMPONENT);

wdContext.nodeZ<MODEL NAME>().bind(input);

But while running the applcaition it is giving run time error as given below

com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: No Scope Maintainer was found for WDModelScopeType: COMPONENT_SCOPE.

Can any please tell me why i am getting this error and more information regarding this type of scope setting??

Regards

Padma N

Accepted Solutions (1)

Accepted Solutions (1)

lokesh_kamana
Active Contributor
0 Kudos

Hi,

There are 2 cases with

1.If you getting the connection from a pool

f you are using JCo connection yourself explicitly (i.e. gte them from pool yourself), then you must call JCO.releaseClient(jcoClient)

2.If you are using Default JCO connection.

If you are using JCo connection implicitly via Adaptive RFC Model, then you should not close it yourself, but rather call disconnectIfAlive on model.

For open connections, by default your models are set to Application scope and because of this it will retain connections. If you want to close this connections you have to write following one line code after executing your model.

wdcontext.current<node name>element().modelObject().modelInstance().disconnectIfAlive();

it will close your connection to the SAP R/3.

Thanks & Regards,

Lokesh

Former Member
0 Kudos

disconnectIfAlive - checks if the connection is alive (connected) and disconnects it

But below links says disconnectIfAlive is not required for TASK_SCOPE,

TASK_SCOPE force model object to be disconnected from model (and garbage collected later) right after request/response phase is ended

Edited by: Raghu v on Dec 17, 2008 12:44 PM

Answers (2)

Answers (2)

former_member192434
Active Contributor
0 Kudos

Hi Padma,

APPLICATION_SCOPE is the default scope used by model instances. This makes all the components in application share the same MODEL instance and thus reduces overhead of creating many model instances when one would suffice. Furthermore, with this SCOPE, you can make more than one model share the same JCO connection pool easily by using setConnectionProvider method of your model instance which is a good practice to avoid potential lock conflicts in ABAP side by avoiding allocation of multiple Roll areas for a single user.

Besides APPLICATION_SCOPE and TASK_SCOPE, there are COMPONENT_SCOPE (One instance of model will be shared by all controllers within a single component) and NO_SCOPE (Multiple applications can share the same model instance) also available.

I hope it will help u

Thanks

Former Member
0 Kudos

Hi Anup,

When ever a BAPI is called NEW Model Class is created as below.

So, a new instance of Model class is created when ever BAPI is called.

If user is calling same Bapi 5 times ,does this mean a new Model class object is created for each Call for a given web portal user

In That case Model instance should for request scope to get the latest data for each BAPI call.

So below code says a new function model class object is bound to the Model Node.

And This object should be only in Request scope...TASK_SCOPE

Z<MODEL NAME> input = new Z<MODEL NAME>(WDModelScopeType.TASK_SCOPE);

wdContext.nodeZ<MODEL NAME>().bind(input);

As a web user it is required to get latest data for each action.But Default model classes uses Application scope...Why is this ?

com.sap.tc.webdynpro.progmodel.model.api.WDModelScopeType DEFAULT_MODELSCOPE =

com.sap.tc.webdynpro.progmodel.model.api.WDModelScopeType.APPLICATION_SCOPE;

Please provide your comments on my understanding.

Former Member
0 Kudos

Anup,

>APPLICATION_SCOPE is the default scope used by model instances. This makes all the >components in application share the same MODEL instance and thus reduces overhead of creating >many model instances when one would suffice.

But with APPLICATION_SCOPE latest data is not retrived second time.

Any BAPI is returning correct data first time only.

If TASK_SCOPE is used latest data is retrived for every BAPI call.

It is Understood each Connection Pool will be created for each User/Destination for every Model Class.

Here User means Login Portal User or defined SAP user used during Model class creation.?

As New Model class is created and BIND with Model Node for BAPI Output ,is there way to make the Model class object to null or CLOSE after execute() method ?.

Former Member
0 Kudos

hi,

by changing the scope to component scope u are reducing its scope

even more.

i think u have to continu with the default Applicatiion scope.

Regards,

Satya.

Former Member
0 Kudos

Hi,

If i continue to defaullt scope APPLICATION i am not getting the latest data when using in multiple component scenario.Thats why i reduced my scope to application.

Can you please provide the soultion for my scenario

Regrads

Padma N