$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 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
lock

This uses $DATA() to determine whether a global node requires initialization.

Example:

for  set cus=$O(^cus(cus)) quit:cus=""  if $data(^(cus))>1 do WORK

This uses $DATA() to determine whether a global node has descendants and requires additional processing.