Although the above description says $ORDER scans "down" a multidimensional global, other programers might say it scans "sideways". There are many different structures for databases. E.g., there are network databases (sometimes called CODASYL databases); there are hierarchical databases (like ObjectScript multidimensional arrays/globals); there are relational databases (often accessed by the SQL language); ...
ObjectScript is based on the ANSI M language standard. I believe that the name of the ANSI M hierarchical function $QUERY has always been $QUERY but the original name of the ANSI M hierarchical function $ORDER was formerly $NEXT. $NEXT is very similar to $ORDER but $NEXT had problems with its starting/ending subscript values. IRIS ObjectScript no longer documents the obsolete $NEXT function but the ObjectScript compiler still accepts programs using $NEXT for backwards compatibility.
Consider the following ObjectScript global array:
USER>ZWRITE ^g
^g("a")="a"
^g("a",1)="a1"
^g("b",1)="b1"
^g("b",1,"c")="b1c"
^g("c")="c"
^g("c","b10")="cb10"
^g("c","b2")="cb2"
^g("d",2)="d2"
^g("d",10)="d10"
Consider the following walk sideways by $ORDER along the first subscript of ^g"
USER>set s=""
USER>for { SET s=$ORDER(^g(s)) QUIT:s="" WRITE $NAME(^g(s)),! }
^g("a")
^g("b")
^g("c")
^g("d")
Although these 4 globals contain values below them, the $ORDER walks did not walk down to deeper subscripts. As it walked sideways, it returned the subscripts "b" and "d" even though ^g("b") and ^g("d") did not have values of their own but only values underneath them.
Now consider the walk down deeper by $QUERY through all the subscripts of ^g(...) at all subscript levels:
USER>set s="^g"
USER>for { WRITE s,! SET s=$QUERY(@s) QUIT:s="" }
^g
^g("a")
^g("a",1)
^g("b",1)
^g("b",1,"c")
^g("c")
^g("c","b10")
^g("c","b2")
^g("d",2)
^g("d",10)
This walk by $QUERY was told to start at ^g and every call on $QUERY went through every subscripted node of ^g(...) that contained a value regardless of the number of subscripts needed. However, elements ^g("b") and ^g("d") that did not contain values of their own were skipped by the $QUERY walk as it continued on to nodes with deeper subscripts that did contain values.
Also note that each $ORDER evaluation returned only a single subscript value as it walked sideways while each $QUERY evaluation returned a string containing the variable name along with all the subscript values of that particular multidimensional array node.
- Log in to post comments