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> Functions• Multiple uses of a string variable in a single $INCREMENT statement should be avoided.For example, avoid concatenating a string variable to the increment of that variable:strvar_$INCREMENT(strvar). This returns unpredictable results.ExamplesThe following example increments the value of myvar by n. Note that myvar does not haveto be a prior defined variable:SET n=4KILL myvarSET VAL=$INCREMENT(myvar,n) ; returns 4WRITE !,myvarSET VAL=$INCREMENT(myvar,n) ; returns 8WRITE !,myvarSET VAL=$INCREMENT(myvar,n) ; returns 12WRITE !,myvarThe following example adds incremental values to the process private variable ^||xyz using$INCREMENT. The one-argument form of $INCREMENT increments by 1; the twoargumentform increments by the value specified in the second argument. In this case, thesecond argument is a floating point number.KILL ^||xyzWRITE !,$INCREMENT(^||xyz) ; returns 1WRITE !,$INCREMENT(^||xyz) ; returns 2WRITE !,$INCREMENT(^||xyz) ; returns 3WRITE !,$INCREMENT(^||xyz,3.14) ; returns 6.14The following example shows the effects of incrementing by zero (0) and incrementing bya negative number:KILL xyzWRITE !,$INCREMENT(xyz,0) ; initialized as zeroWRITE !,$INCREMENT(xyz,0) ; still zeroWRITE !,$INCREMENT(xyz) ; increments by 1 (default)WRITE !,$INCREMENT(xyz) ; increments by 1 (=2)WRITE !,$INCREMENT(xyz,-1) ; decrements by -1 (=1)WRITE !,$INCREMENT(xyz,-1) ; decrements by -1 (=0)WRITE !,$INCREMENT(xyz,-1) ; decrements by -1 (=-1)The following example shows the effects of incrementing using mixed (numeric and nonnumeric)num strings and the null string:222 <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!