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.

with a naked reference to return the number of the first subscript (whether negative or positive)at the current level.The WRITE command in the FOR loop uses $NAME with a naked global reference andargument indirection to output the value of the current element. The SET command uses$ORDER with a naked global reference to return the subscript of the next existing elementthat contains data. Finally, the postconditional QUIT checks the value returned by $ORDERto detect the end of the current level and terminate the loop processing.You can use the returned $NAME string value for name or subscript indirection or pass it asa parameter to a routine or user-defined function. For more information, refer to Indirectionin Using <strong>Caché</strong> <strong>ObjectScript</strong>. Consider the routine ^DESCEND that lists descendant nodesof the specified node.DESCEND(ROOT) ;List descendant nodesNEW REFSET REF=ROOTIF ROOT'["(" {FOR {SET REF=$QUERY(@REF)QUIT:REF=""WRITE REF,! }}ELSE {SET $EXTRACT(ROOT,$LENGTH(ROOT))=","FOR {SET REF=$QUERY(@REF)QUIT:REF'[ROOTWRITE REF,! }}The following example demonstrates how you can use $NAME to pass a parameter to the^DESCEND routine defined in the previous example.FOR var1="ONE","TWO","THREE" {DO ^DESCEND($NAME(^X(var1))) }^X("ONE",2,3)NotesUses for $NAMEYou typically use $NAME to return the name values of array elements for use with the$DATA and $ORDER functions.If a reference to an array element contains expressions, $NAME evaluates the expressionsbefore returning the canonical form of the name. For example:SET x=1+2SET y=$NAME(^client(4,1,x))WRITE y$NAME<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 265

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

Saved successfully!

Ooh no, something went wrong!