Using Caché ObjectScript - InterSystems Documentation
Using Caché ObjectScript - InterSystems Documentation
Using Caché ObjectScript - InterSystems Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Categories of Variables<br />
• A global name must be unique within its namespace.<br />
• Global names are limited to 31 characters, exclusive of the prefix characters. You may specify a name longer than 31<br />
characters, but only the first 31 characters are used. Therefore, a global name must be unique within its first 31 characters.<br />
• Globals can take subscripts. By using subscripts, you can define a global as an array of values. For naming conventions,<br />
limitations on the number of subscript levels, and other information about use of subscripts, refer to Global Structure<br />
in <strong>Using</strong> <strong>Caché</strong> Globals.<br />
Optionally, a global may specify an extended reference that defines its namespace or directory using a pair of vertical bars<br />
or square brackets immediately after the caret characters (for example: ^|"samples"|myglobal or ^|""|myglobal).<br />
These extended global references should not be confused with process-private globals.<br />
You can use the $ZREFERENCE special variable to determine the name of the most recently used global. You can use the<br />
$QSUBSCRIPT function to return the components of a specified global, or the $QLENGTH function to return the number<br />
of subscript layers.<br />
For much more information on globals, refer to <strong>Using</strong> <strong>Caché</strong> Globals.<br />
4.1.4 Array Variables<br />
An array variable is simply a variable with one or more subscript levels. Subscripts are enclosed in parentheses. Subscript<br />
levels are separated by commas. Any variable (with the exception of special variables) can be used as an array, as shown<br />
in the following example:<br />
SET a(1) = "A local variable array"<br />
SET a(1,1,1) = "Another local variable array"<br />
SET ^||a(1) = "A process-private global array"<br />
SET ^a(1) = "A global array"<br />
SET obj.a(1) = "A multidimensional array property"<br />
For local variables, the maximum number of subscript levels is 255. For global variables, the maximum number of subscript<br />
levels depends on the length of the subscript names. For subscript naming conventions and limits, refer to the Global<br />
Structure chapter in <strong>Using</strong> <strong>Caché</strong> Globals.<br />
4.1.5 Special Variables<br />
<strong>Caché</strong> <strong>ObjectScript</strong> includes a number of built-in special variables (also referred to as system variables) that are used to<br />
make certain system information available to applications. All special variables are supplied with <strong>Caché</strong> and are named<br />
with a “$” character prefix. Users cannot define additional special variables. The set of special variables is mapped to be<br />
accessible from all namespaces.<br />
The value of a special variable is set to the current state of some aspect of your operating environment. Some special variables<br />
are initially set to the null string (""); referencing a special variable should never generate an error. The<br />
value of a special variable is specific to the current process and cannot be accessed from another process.<br />
Users can set some special variables with the SET command; other special variables are not user-modifiable. Refer to the<br />
individual special variables for further details.<br />
The following example uses the special variable $HOROLOG:<br />
SET starttime = $HOROLOG<br />
HANG 5<br />
WRITE !,$ZDATETIME(starttime)<br />
WRITE !,$ZDATETIME($HOROLOG)<br />
The special variable $HOROLOG stores the current system date and time. The SET command uses this special variable<br />
to set the user-defined local variable starttime to this value. The HANG command then suspends the program for 5 seconds.<br />
Finally, the two $ZDATETIME functions return starttime and the current system date and time in a user-readable format.<br />
<strong>Using</strong> <strong>Caché</strong> <strong>ObjectScript</strong> 27