Caché MultiValue Basic Reference
EXISTS
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Returns the existence status of variables and their dimensioned array subnodes.
Synopsis
EXISTS(varname)
Arguments
varname Name of a variable to test for existence, and/or the presence of dimensioned array subnodes.
Description
The EXISTS function returns an integer code indicating whether a variable is defined (1) or not defined (0). It can also indicate that the specified variable is not defined, but that the variable has defined subscripts. The varname parameter can be the name of any variable (local variable, process-private global, or global), and can include a subscript (an array element).
EXISTS returns an integer code indicating that the specified variable is:
Similar information can be returned using the $DATA function.
Note:
EXISTS should not be used on system variables (@ variables). It always returns 0 for all @ variables, whether or not the @ variable currently has a value.
Example
The following example shows the four possible EXISTS return values. The specified variables are all process-private globals:
^||a="salt"
^||b(1)="carrot"
^||c="fruit"
^||c(1)="apple"
PRINT EXISTS(^||a); ! returns 1
PRINT EXISTS(^||b); ! returns 2
PRINT EXISTS(^||c); ! returns 3
PRINT EXISTS(^||z); ! returns 0
See Also