Skip to Content
author's profile photo Former Member
Former Member

HashMap(global variable) is not working in Message mapping

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,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 13, 2012 at 03:45 AM

    Hi.

    How do you store the HashMap in Global Variable?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 13, 2012 at 06:26 AM

    Hi,

    >>>I declared the hasmap in the functions tab(ie.,global variable)

    in Attributes and Methods ? (just checking)

    Regards,

    Michal Krawczyk

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 13, 2012 at 01:51 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 13, 2012 at 04:53 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.