12.07.2015 Views

Using Caché Globals - InterSystems Documentation

Using Caché Globals - InterSystems Documentation

Using Caché Globals - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> Multidimensional Storage (<strong>Globals</strong>)3.10 <strong>Using</strong> Indirection with <strong>Globals</strong>By means of indirection, <strong>Caché</strong> ObjectScript provides a way to create global references at runtime.This can be useful in applications where you do not know global structure or names at program compilationtime.Indirection is supported via the indirection operator, @, which de-references a string containing anexpression. There are several types of indirection, based on how the @ operator is used.The following code provides an example of name indirection in which the @ operator is used to dereferencea string containing a global reference:// Erase any existing dataKill ^Data// Set var to an global reference expressionSet var = "^Data(100)"// Now use indirection to set ^Data(100)Set @var = "This data was set indirectly."// Now display the value directly:Write "Value: ",^Data(100)You can also use subscript indirection to mix expressions (variables or literal values) within indirectstatements:// Erase any existing dataKill ^Data// Set var to a subscript valueSet glvn = "^Data"// Now use indirection to set ^Data(1) to ^Data(10)For i = 1:1:10 {Set @glvn@(i) = "This data was set indirectly."}// Now display the values directly:Set key = $Order(^Data(""))While (key '= "") {Write "Value ",key, ": ", ^Data(key),!Set key = $Order(^Data(key))}Indirection is a fundamental feature of <strong>Caché</strong> ObjectScript; it is not limited to global references. Formore information, refer to the “Indirection” section in the “Operators” chapter of <strong>Using</strong> <strong>Caché</strong>ObjectScript. Indirection is less efficient than direct access, so you should use it judiciously.28 <strong>Using</strong> <strong>Caché</strong> <strong>Globals</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!