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> FunctionsParameterstarget$CASE evaluates this expression once, then matches the result to each case in left-to-rightorder.caseA case can be a literal or an expression; matching of literals is substantially more efficientthan matching expressions, because literals can be evaluated at compile time. Each case mustbe paired with a value. An unlimited number of case and value pairs may be specified.valueA value can be a literal or an expression. Using $CASE as an argument of a GOTO commandor a DO command restricts value as follows:• When using a $CASE statement with a GOTO command, each value must be a validtag. It cannot be an expression.• When using a $CASE statement with a DO command, each value must be a valid DOargument. These DO arguments can include parameters.defaultThe default is specified like a case:value pair, except that there is no case specified betweenthe comma (used to separate pairs) and the colon (used to pair items). The default is alwaysthe final parameter specified in a $CASE function. The default value follows the same GOTOand DO restrictions as the value parameter.If there is no matching case and no default is specified, <strong>Caché</strong> issues an error.ExampleThe following example takes a number and returns corresponding name for a day of the week.Note that a default value “entry error” is provided:SET daynum=3WRITE $CASE(daynum,1:"Sunday",2:"Monday",3:"Tuesday",4:"Wednesday",5:"Thursday",6:"Friday",7:"Saturday",:"entry error")The following example takes a numeric input and writes out the appropriate explanatorystring:192 <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!