12.07.2015 Views

Using Caché Globals - InterSystems Documentation

Using Caché Globals - InterSystems Documentation

Using Caché Globals - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The $QUERY function takes a global reference and returns a string containing the global referenceof the next node in the global (or "" if there are no following nodes). To use the value returned by$QUERY, you must use the <strong>Caché</strong> ObjectScript indirection operator (@).For example, suppose you define the following global:Set ^Data(1) = ""Set ^Data(1,1) = ""Set ^Data(1,2) = ""Set ^Data(2) = ""Set ^Data(2,1) = ""Set ^Data(2,2) = ""Set ^Data(5,1,2) = ""The following call to $QUERY:SET node = $QUERY(^Data(""))sets node to the string “^Data(1)” , the address of the first node within the global. Then, to get thenext node in the global, call $QUERY again and use the indirection operator on node:SET node = $QUERY(@node)At this point, node contains the string “^Data(1,1)” .The following example defines a set of global nodes and then walks over them using $QUERY,writing the address of each node as it does:Kill ^Data // make sure ^Data is empty// place some data into ^DataSet ^Data(1) = ""Set ^Data(1,1) = ""Set ^Data(1,2) = ""Set ^Data(2) = ""Set ^Data(2,1) = ""Set ^Data(2,2) = ""Set ^Data(5,1,2) = ""// now walk over ^Data// find first nodeSet node = $Query(^Data(""))While (node '= "") {Write node,!// get next nodeSet node = $Query(@node)}Copying Data within <strong>Globals</strong>3.6 Copying Data within <strong>Globals</strong>To copy the contents of a global (entire or partial) into another global (or a local array), use the <strong>Caché</strong>ObjectScript MERGE command.<strong>Using</strong> <strong>Caché</strong> <strong>Globals</strong> 23

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

Saved successfully!

Ooh no, something went wrong!