Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining What Happens When Matching Events Are Found | Using variables | Using global variables
 
Using global variables
Variables in monitor scope are global variables; you can access a global variable throughout the monitor. You can define global variables anywhere inside a monitor except in actions and event definitions. For example:
monitor SimpleShareSearch {
   // A monitor scope variable to store the stock received:
   //
   StockTick newTick;
This declares a global variable, newTick, that can be used anywhere within the SimpleShareSearch monitor including within any of its actions.
The order does not matter. In the following example, f is a global variable:
monitor Test {
   action onload() {
      print getZ().toString();
   }
   action getZ() returns integer {
      return f.z;
   }
   Foo f;
   event Foo{
      integer z;
   }
}
If you do not explicitly initialize the value of a global variable, the correlator automatically assigns a value to that global variable. See also Default values for types.