$Data()
$Data()
Returns an integer code describing the value and descendent status of a local or global variable.
The format for the $DATA function is:
$D[ATA](glvn)- The subscripted or unsubscripted global or local variable name specifies the target node.
- If the variable is undefined, $DATA() returns 0.
- If the variable has a value but no descendants, $DATA() returns 1.
- If the variable has descendants but no value, $DATA() returns 10.
- If the variable has a value and descendants, $DATA() returns 11.
- $ZDATA() extends $DATA() to reflects the current alias state of the lvn or name argument to identify alias and alias container variables. For more information, refer to “$ZDATA()”.
The following table summarizes $DATA() return values.
| $DATA() Results | ||
|---|---|---|
| VALUE | ||
| DESCENDANTS (NO) | DESCENDANTS (YES) | |
| NO | 0 | 10 |
| YES | 1 | 11 |
$DATA() return values can also be understood as a pair of truth-values where the left describes descendants and the right describes data 1 and where M suppresses any leading zero (representing no descendants).
Examples of $DATA()
Example:
GTM>Kill Write $Data(a)
0
GTM>Set a(1)=1 Write $Data(a(1))
1
GTM>Write $Data(a)
10
GTM>Set a=0 Write $Data(a)
11
GTM>This uses $DATA to display all possible $DATA() results.
Example:
lock ^ACCT(0)
if '$data(^ACCT(0)) set ^ACCT(0)=0
set (ACCT,^ACCT(0))=^ACCT(0)+1
lockThis uses $DATA() to determine whether a global node requires initialization.
Example:
for set cus=$O(^cus(cus)) quit:cus="" if $data(^(cus))>1 do WORKThis uses $DATA() to determine whether a global node has descendants and requires additional processing.