Previous Topic: User Variables

Next Topic: Persistent Global Variables

Global Variables

Global variables operate in a similar manner to user variables. The difference is that global variables, as the name implies, are global to the entire system and once created can be referenced or modified by any procedure. Thus, global variables can be used to perform cross-talk between procedures.

Global variables commence with a 1- to 4-character prefix that you can set for your site using the SYSPARMS NCLGLBL command. Unless otherwise defined this prefix defaults to GLBL. The remaining characters must conform to standard variable naming conventions.

The &000 system variable is set to the current value of the global variable prefix. Thus, if the SYSPARMS NCLGLBL=#@ command was used to set the global variable prefix to #@ then &000 returns that value. This facility is provided to allow the procedure designer to develop procedures that execute correctly regardless of the global variable prefix. For example, &&000SYS1 is resolved to &GLBLSYS1 using the default value for the global variable prefix, or &#@SYS1 if the prefix is set as mentioned previously.

A global variable can be created explicitly by an assignment statement, for example:

&&000SHIFTLDR = &STR SHIFT LEADER IS BILL SMITH

It can also be created implicitly by specifying a global variable name as the target of a verb that creates or modifies variables as part of its function.

Once created, a global variable remains in existence until it is explicitly deleted by an assignment statement. For example:

&&000SHIFTLDR =

Note: The uncontrolled creation of large numbers of global variables can consume a large amount of storage. You should ensure that global variables are deleted as soon as they are no longer needed. Care should be taken when designing procedures to ensure that they do not end without deleting any redundant global variables created.

CA recommends that you observe a standard naming convention for global variables to avoid the inadvertent destruction of variables where, for example, one procedure creates a global variable with an identical name as that created by another.

The SHOW NCLGLBL command provides a display of the global variables that exist in the system. For more information, see the Online Help.