on 01-30-2009 3:07 PM
Hi
i think in Pi 7.1, we cannot declare a global variable. does anyone know the substitute of it.
Cos i need to increament a counter and pass it a target field for more than 1 line item. so every on my target side i wil have an incremented value for every line item.
Thanks in advance
Hi all,
I have created the following sample class Test.java and imported it as an archive:
public class Test{
public static String myStringData = null;
}
In one of the mappings, I have a UDF that sets the "myStringData" using the foll:
Test.myStringData = "Amit";
I am trying to access this variable in another mapping using a UDF with foll statements:
String test = Test.myStringData;
result.addValue(test);
However, on testing the second mapping I get the value of the variable as null. I have activated all objects.
Not sure what exactly I am missing here...Kindly provide your inputs.
Thanks..
Amit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jayson,
Can you please elaborate more on how to create that class?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Saiyog,
it's very simple. Let's say we have a java class GlobalDataContainer.java
public class GlobalDataContainer{
public static String myStringData = null;
}
Zip it and import it into PI as Imported archive.
in you UDF, use this static data like:
GlobalDataContainer.myStringData = "my test string";
you can then retrieve the data from any other message mapping UDF like
String getMyString = GlobalDataContainer.myStringData;
To make the GlobalDataContainer more fancy, you can define it as single instance java class, and define the data as private to be better protected, then define setter and getter to access it.
Hope that's clear to you.
Jayson
There is new concept of graphical variable for global variable. check blog no 8638 in sdn.
thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
graphical variable only works within the mapping session. It's similiar like global container.
However if you want to have real global variable that is valid across mapping session, (like it's valid from message to message), you can define static data member in a java class, then use the java class in your UDF by using the static data memeber as real global variable.
Jayson
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
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.