11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - 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.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsNotesUses for $ORDER$ORDER is typically used with loop processing to traverse the nodes in a sparse array. Asparse array is an array that may contain undefined nodes on any given level. Unlike the$DATA function, $ORDER simply skips over undefined nodes to return the subscript of thenext existing node. For example:SET struct=""FOR {SET struct=$ORDER(^client(struct))QUIT:struct=""WRITE !,^client(struct)}The above routine writes the values for all the top-level nodes in the ^client global array.$ORDER skips over undefined nodes, but not nodes that contain no data. Such nodes includeboth pointer nodes and terminal nodes. If you use $ORDER in a loop to feed a command(such as WRITE) that expects data, you must include a $DATA check for dataless nodes.For example, you could specify the WRITE command in the previous example with a postconditionaltest, as follows:WRITE:(1=$DATA(^client(struct)))!(11=$DATA(^client(struct))) !,^client(struct)This test covers the case of both a dataless pointer node and a dataless terminal node. If yourcode becomes too cumbersome for a simple FOR loop, you can relegate part of it to a blockstructuredDO.Start and End for a SearchTo start a search from the beginning of the current level, specify a null string ("") for thesubscript. This technique is required if the level may contain negative as well as positivesubscripts. The following example returns the first subscript on the array level:SET s=$ORDER(^client(""))WRITE sWhen $ORDER reaches the end of the subscripts for the given level, it returns a null string(""). If you use $ORDER in a loop, your code should always include a test for this value. Ina previous example, QUIT:struct="" is used to detect the end of the level and terminate theloop.278 <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!