If you are using multiple ESL programs in your ESL application, you can define global variables that can be set and referenced by all the ESL programs to be executed; for example:
global variable MessageCount
Suppose that two programs each define a global variable named MessageCount. When one of the programs transfers to the other program, the value of MessageCount is retained and is available for use by the new program.
All programs that want to use the same global variable must define it as a global variable, specifying the same name and the same type. If any subsequent program initializes the global variable, the initialization is ignored. (See change to program Action Statement in the Reference Guide.) Ordinarily, initialization is specified only in the first program.
If the variable is not defined as global, the variable defaults to an application variable. For application variables, values assigned will be retained only while the current program is executing. An application variable ceases to exist when ESL leaves the program in which the variable is defined. If the program is re-entered, the value is reinitialized.
If you want to retain the value of a variable between invocations when changing between many ESL programs, you must define the variable as a global variable, even if none of the other programs use that variable.
You can save the current value of the application variables in a program by saving the program with a save program as statement.
Local variables are declared within a subroutine definition, prior to the first action statement. Local variables may share the same name as other local variables declared within other subroutines, but cannot have the same name as any global or application variable. The scope of a local variable is confined to the subroutine in which it is the declared, although local variables can be passed by reference to other subroutines via the parameters. Once a subroutine has completed, all its local variables are lost. It is not possible to save the values of local variables, as the statement save program as cannot be used while a subroutine is active.
Only string, integer, float and boolean variables can be declared as a local subroutine variable.
Variables declared within a subroutine, but not before the first action statement, default to being application variables.