Contains the current global reference.
contains the name and subscript(s) of the last global
reference. This is known as the naked indicator.
The last global reference is the most recently accessed global node. Usually, this is the most recent explicit reference to a global. However, certain commands may internally use the $ORDER
function to traverse global subscripts (the ZWRITE
command is an example of this), or they may refer internally to some other global. When this occurs, $ZREFERENCE
contains the last accessed global node, which may not be the global node specified to the command.
The last global reference can be either a global (^myglob) or a process-private global
returns the process-private global prefix in the form that was initially used for that variable, regardless of which process-private global prefix is used subsequently for that variable. In the description of $ZREFERENCE
that follows, the word global refers to both types of variables.
The last global reference is the global most recently referred to by a command or a function. Because ObjectScript performs operations in left-to-right order, the last global reference is always the rightmost global. When a command or function takes multiple arguments, the global specified in the rightmost argument is the last global reference. When an argument contains multiple global references, the rightmost specified global is the last global reference. This strict left-to-right order holds true even if parentheses are used to define the order of operations.
InterSystems IRIS updates $ZREFERENCE
when an explicit global reference is issued. Invoking an expression (such as a local variable) that evaluates to a global reference does not update $ZREFERENCE
contains the most recent global reference, even if this global reference was not successful. When a command references an undefined global, issuing an <UNDEFINED> error, InterSystems IRIS updates $ZREFERENCE
to that global reference, just as if the global were defined. This behavior is unaffected by setting the %SYSTEM.Process.Undefined()
often contains the most recent global reference, even if the command execution was not successful. InterSystems IRIS updates $ZREFERENCE
as each global is referenced. For example, a command issuing a <DIVIDE> error (attempting to divide a number by 0) updates $ZREFERENCE
to the last global referenced in the command before the error occurred. However, a <SYNTAX> error does not update $ZREFERENCE
If the last global reference was a naked global reference
contains the external, readable, full form of the current naked global reference. This is demonstrated in the following example:
SET ^MyData(1,1)="apples" ; Full global reference
SET ^(2)="oranges" ; Naked global reference,
; implicitly ^MyData(1,2)
WRITE !,$ZREFERENCE ; Returns "^MyData(1,2)"
Extended Global Reference
Extended global reference is used to reference a global that is in a namespace other than the current namespace. If a command references a global variable using an extended global reference, the $ZREFERENCE
value contains that extended global reference. InterSystems IRIS returns an extended global reference in the following circumstances:
If the last global reference uses an extended reference to refer to a global in another namespace.
If the last global reference uses an extended reference to refer to a global in the current namespace.
If the last global reference is a remote reference (a global on a remote system).
In all cases, $ZREFERENCE
returns the namespace name in all capital letters, regardless of how it was specified in the global reference.
Operations that Update $ZREFERENCE
special variable is initialized to the null string (""). Changing the current namespace resets $ZREFERENCE
to the null string.
The following operations set $ZREFERENCE
to the most recently referenced global:
A command or function that uses a global as an argument. If it uses multiple globals, $ZREFERENCE
is set to the rightmost occurrence of a global. (Note, however, the exception of $ORDER
A command that uses a global as a postconditional expression.
Following a ZWRITE
, InterSystems IRIS sets $ZREFERENCE
to the last accessed subscript node of the specified global reference.
A command or function that references an undefined global, and either generates an <UNDEFINED> error, or, in the case of $INCREMENT
, defines the global.
You can set this special variable using the SET
command, as follows:
Set to the null string (""). Doing so deletes the naked indicator. If the next global reference is a naked global reference
, InterSystems IRIS issues a <NAKED> error.
Set to a valid global reference (defined or undefined). This causes subsequent naked references to use the value you set as if it were the last actual global reference.
cannot be otherwise modified using the SET
command. Attempting to do so results in a <SYNTAX> error.
The following example returns the last global reference:
SET ^a(1,1)="Hello" ; Full global reference
SET ^(2)=" world!" ; Naked global reference
The following example returns global references from several different commands. Note that WRITE
set different representations of the same global reference.
^fred ; last of several globals set in left-to-right order
^flies ; KILL sets global indicator, though no global to kill
flintstone ; WRITE global
^fred ; global from WRITE
^fred="flintstone" ; ZWRITE global
^fred("") ; global from ZWRITE
The following example returns an extended global reference. Note that the namespace name is always returned in uppercase letters:
SET ^(2)=" world!"
The following example returns the last global reference. In this case, it is ^a(1), used as an argument to the $LENGTH
The following example returns the value set for $ZREFERENCE
as if it were the last global reference. In this case, it is ^a(1,1).
; Naked reference uses last global
; Naked reference uses $ZREFERENCE
; value, rather than last global.
The following example sets an extended global reference. Note the doubled quotation marks:
Content Date/Time: 2019-02-16 22:40:03