11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - 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>Caché</strong> <strong>ObjectScript</strong> FunctionsUsing Mode -5If the current block in the view buffer contains part of a global, specifying -5 for mode returnsthe global references and the values contained in the block. The length parameter is not validfor a mode of -5.With a mode of -5, the offset value specifies the number of global nodes in the block, ratherthan a byte offset from the base address. Odd values return full global references and evenvalues return pointers or data.For example, to return the full global reference of the nth node in the view buffer, specifyn*2-1 for offset. To return the value of the nth node, specify n*2. To return the global referenceof the last node in the block, specify -1 for the offset value.$VIEW returns the nodes in collating sequence (that is, numeric). This is the same sequencethat the $ORDER function uses. By writing code that expects this sequence, you can quicklyperform a sequential scan through a global in the view buffer. (Several of the <strong>Caché</strong> utilitiesuse this technique.) $VIEW returns a null string ("") if the offset specifies a location beyondthe last node in the view buffer. Be sure to include a test for this value in your code.If the current block is a pointer block, the values returned are <strong>Caché</strong> block numbers, whichare pointers. If the block is a data block, the values returned are the data values associatedwith the nodes.If $VIEW issues a or error, it means that the information inthe block is neither a valid global reference nor valid data.The following example shows generalized code for examining the contents of the view buffer.The code first opens the view buffer and prompts for the number of the block to be read in.The FOR loop then cycles through all the offsets in the current block. The $VIEW functionuses a mode of -5 to return the value at each offset. The WRITE commands output theresulting offset-value pairs.When the end of the block is reached, $VIEW returns a null string (""). The IF commandtests for this value and writes out the “End of block” message. The QUIT command thenterminates the loop and control returns to the prompt so the user can read in another block.312 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

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

Saved successfully!

Ooh no, something went wrong!