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. (Note that the correlator does not automatically initialize local variables.) The following table shows the values that the correlator assigns to uninitialized global variables.
Values the correlator assigns to uninitialized global variables
Global Variable Type
Value Correlator Assigns to Uninitialized Global Variable
action
A null value that causes the monitor instance to die if you try to execute the action. In the correlator log file, the error message is Called uninitialized action value.
boolean
false
chunk
Contains no state. Each plug-in must define what to do upon receiving a default-initialized chunk as an argument.
context
A null context that cannot be used in any meaningful way. To use this variable, you must explicitly assign a context that was created with a name.
decimal
0.0d
dictionary
Empty dictionary
event
Instance of the event where each of its fields has the standard default values as per this table.
float
0.0
integer
0
listener
A null listener that cannot be used in any meaningful way. To use this variable, you must assign a listener to it from within an on statement, from another listener variable, or from a stream listener in a from statement.
location
(0.0, 0.0, 0.0, 0.0)
sequence
Empty sequence
stream
A null stream that cannot be used in any meaningful way. To use the variable you must assign a non-null stream to it.
string
"" (empty string)
Copyright © Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its Subsidiaries and or/its Affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.