cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed with Global Container usage

Former Member
0 Kudos

Hi All,

In a scenario, we are using a Global container.

we are using setParameter and getParameter methods to set and get values from the Global Container.

The problem we are facing is that although we are setting the value for a parameter before getting it but it always returns "null".

Please find attached the code:

SetVar:

GlobalContainer myGlobalContainer;

myGlobalContainer = container.getGlobalContainer();

myGlobalContainer.setParameter(b.toUpperCase(), a);

return a;

GetVar:

GlobalContainer myGlobalContainer;

myGlobalContainer = container.getGlobalContainer();

if (myGlobalContainer.getParameter(a) == null) {

return "";

}

else {

return (String)myGlobalContainer.getParameter(a.toUpperCase());

}

We have also tried putting the string value excplicitly in "" but of no use.

We also read the blog by Michael but i think the problem is a little different.

If any body can help us with where to look for Global Container related errors, it would be of great help.

Regards,

Varun Joshi

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks

bhavesh_kantilal
Active Contributor
0 Kudos

Varun,

The Signature of setParameter() is,

void 
setParameter 
(String parName, Object obj);

Taking this into account,


GlobalContainer myGlobalContainer;
myGlobalContainer = container.getGlobalContainer();
myGlobalContainer.setParameter(b.toUpperCase(), a);
return a;

In this method you are settting parameter b with value a.

But, in the get

GlobalContainer myGlobalContainer;
myGlobalContainer = container.getGlobalContainer();
if (myGlobalContainer.getParameter(a) == null) {
return "";
}
else {
return (String)myGlobalContainer.getParameter(a.toUpperCase());
}

You are trying to use get(a) when it should be get(b).

Regards

Bhavesh

former_member189418
Participant
0 Kudos

Hi Varun,

In your declaration change the statement to

myGlobalContainer.setParameter(<b>a,b.toUpperCase()</b>);

Anil

bhavesh_kantilal
Active Contributor
0 Kudos

Varun,

Do not use Global Containers. You have a better option in terms of the JAVA Section in the message mapping that does the same and are simpler to use.

More in this blog,

/people/sap.user72/blog/2005/10/01/xi-new-features-in-sp14

Regards

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

We have read that blog.

yes, that indeed is an option.

But one issue is, that the setParameter method is being called under a Java User defined function. And that function is being used at many places.

If we use a global variable, then we may either have to use lot of them or we may have to use a key value pair type user defined data type.

We do have that option on the back of our minds but we first want to look for a workaround for the present condition.

Regards,

Varun

bhavesh_kantilal
Active Contributor
0 Kudos

Varun,

><i>If we use a global variable, then we may either have to use lot of them or we may have to use a key value pair type user defined data type.</i>

Not sure I understood this. You can define a Array, a vector, a hashmap andything you want in the Global Variables of the Java Section.

><i>We do have that option on the back of our minds but we first want to look for a workaround for the present condition.</i>

Actually using the Global Variables in the Java Section wil provide a better perfromance as you are avoiding multiple calls to the Container Object.

Regards

Bhavesh

Former Member
0 Kudos

Hey Bhavesh,

we tried using global variables and now we have another issue on our hands.

When in a user defined java function we assign the Global Variable another value

and call the global variable in another node mapping below, it takes the initial value

for that Global Variable.

Whereas we need the changed value here.

Any ideas?

Regards,

Varun

bhavesh_kantilal
Active Contributor
0 Kudos

Varun,

Best way to bedug would be to use the Trace Statement in the UDF.

AbstractTrace trace=container.getTrace();
trace.addWarning("give the variablename and avlue here");

This should let you see the value everytime the UDF is called.

Regards

Bhavesh

former_member189418
Participant
0 Kudos

Hi Varun,

The mapping for the node (for which u need the modified Global value) might be getting executed b4 the node where u change the global value. Can u try by changing the sequence of the source fields?

Anil

former_member189418
Participant
0 Kudos

I mean to say in the test tab while testing the mapping, interchange the nodes in the source msg structure.

Anil