on 06-13-2012 4:19 AM
HI, In my outbound ORDERS map I've a situation that i've to use java HashMAp. I tried hard but didn't work so to track down the issue I tried like this. And this is what i need also.
I declared the hasmap in the functions tab(ie.,global variable)
HasMap Test = new HasMap();
I created an UDF and i've the below code:
_________________________________
String Temp = "PI ";
for(int i=0; i<2;i++)
{
Test.put(i,temp+i);
}
importantTrace.addWarning.("SIZE = " + Test.size());
for(int j=0; j<2;j++)
{
Test.get(j);
importantTrace.addWarning(Test.get(j));
}
________________________________________
at the start of the map in one of the link i've used this UDF and seeing the result as expected in the printf(addWarning) statement.
Result : SIZE = 2
PI 0
PI 1
My situation is whatever i stored in my HashMap i must use in someother link/area down in the map.
so i created another UDF and added the below code
________________________________________________
importantTrace.addWarning.("SIZE :: " + Test.size());
for(int j=0; j<2;j++)
{
Test.get(j,temp+j);
importantTrace.addWarning(Test.get(j));
}
________________________________________________
Result: SIZE :: 0
Since the size if zero i'm not getting the value which i stored in the HashMap.
Can you please help me on this issue ?
FYI: I've used simple global variable like this it works fine.
Thanks,
Everything is correct but small parallax error
Mistake with "HashMap" spelling
you used "HasMap" without "h"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajkumar,
This would appear to be an order of operations issue in your mapping. You stated that you have defined a global HashMap object in your mapping that is constructed with the statement:
HashMap Test = new HashMap();
Since the object Test most certainly has global scope (otherwise you'd get a NullPointerException) then the only other possibility is that in your mapping the second UDF is executing before the first UDF. In that scenario the size of Test will still be zero and you'd get the result that you are seeing. You need to focus on the order in which the items are executing at runtime.
Regards,
Ryan Crosby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajkumar,
I feel in your second UDF I feel the code should be
________________________________________________
importantTrace.addWarning.("SIZE :: " + Test.size());
for(int j=0; j<2;j++)
{
Test.get(j);
importantTrace.addWarning(Test.get(j));
}
________________________________________________
instead of
________________________________________________
importantTrace.addWarning.("SIZE :: " + Test.size());
for(int j=0; j<2;j++)
{
Test.get(j,temp+j);
importantTrace.addWarning(Test.get(j));
}
________________________________________________
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajkumar,
Please try using simple global variable in UDF1 and access the variable in UDF 2.
If you are able to do so then similar method of storage has be applied for hashmap objects too.
Please look into this thread , this shows separete treatment for hashmap http://scn.sap.com/thread/1860541
I have not this myself, but the thread shows that type cast to string object might be necessary.
Regards
Anupam
Hi.
You can try with these UDFs to set and get a HashMap in GlobalContainer.
public static void registerMap(String mapName[], String mapKeys[], String mapValues[], ResultList result, Container container) {
GlobalContainer gc = container.getGlobalContainer();
HashMap hm = new HashMap();
for(int i = 0; i < mapKeys.length; i++)
if(!hm.containsKey(mapKeys[i]))
hm.put(mapKeys[i], mapValues[i]);
gc.setParameter(mapName[0], hm);
}
public static String getFromMap(String mapName, String key, Container container) {
GlobalContainer gc = container.getGlobalContainer();
Object hm = gc.getParameter(mapName);
Object value = null;
if(hm != null)
value = ((HashMap)hm).get(key);
if(value != null)
return value.toString();
else
return "";
}
Regards
Lucho
Hi,
>>>I declared the hasmap in the functions tab(ie.,global variable)
in Attributes and Methods ? (just checking)
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi.
How do you store the HashMap in Global Variable?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.