cancel
Showing results for 
Search instead for 
Did you mean: 

global variable

former_member193376
Active Contributor
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

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

former_member193376
Active Contributor
0 Kudos

Jayson,

Can you please elaborate more on how to create that class?

Thanks

Former Member
0 Kudos

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

SudhirT
Active Contributor
0 Kudos

There is new concept of graphical variable for global variable. check blog no 8638 in sdn.

thanks.

Former Member
0 Kudos

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