Skip to main content

Globals

Globals

A global is a special kind of variable that is automatically stored within the InterSystems IRIS database. It is mapped to a specific namespace, and can only be accessed within that namespace, unless an extended reference is used. A global can be accessed by any process. A global persists after the termination of the process that created it. It persists until explicitly deleted.

Within ObjectScript code, you can use a global in the same way as any other variable. Syntactically, a global name is distinguished by an initial caret (^) character:

 SET mylocal = "This is a local variable"
 SET ^myglobal = "This is a global stored in the current namespace"

For complete information on names, see Rules and Guidelines for Identifiers. Briefly:

  • The first character after the caret must be either a letter or the percent (%) character.

    Global names starting with ^% are known as “percent variables” and are available in all namespaces. In your code, for these variables, start the name with ^%Z or ^%z; other names are reserved for system use.

  • The second and subsequent characters of a global name may be letters, numbers, or the period character. A period cannot be used as the first or last character of the name.

  • Unlike local variables, no global name can contain Unicode letters — letter characters above ASCII 255. Attempting to include a Unicode letter in a global name results in a <WIDE CHAR> error.

  • Global names are case-sensitive.

  • A global name must be unique within its namespace.

  • Global names are limited to 31 characters, exclusive of the prefix characters. You may specify a name longer than 31 characters, but only the first 31 characters are used. Therefore, a global name must be unique within its first 31 characters.

  • Like other variables, globals can take subscripts. See Rules About Subscripts.

  • Some global names are reserved for InterSystems use. See Global Variable Names to Avoid.

It is possible to use an extended reference to refer to a global in another namespace. The syntax uses a pair of vertical bars or square brackets immediately after the caret characters (for example: ^|"samples"|myglobal or ^|""|myglobal). These syntaxes should not be confused with process-private globals.

For more information on globals, refer to Using Globals.

FeedbackOpens in a new tab