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> Special Variables1. Saves the old copy of $ESTACK.2. Creates a new copy of $ESTACK with a value of zero (0).In this way, you can establish a particular context as the $ESTACK level 0 context. As youcreate new contexts with DO, XECUTE, or user-defined functions, <strong>Caché</strong> increments this$ESTACK value. However, when you exit the context in which the new $ESTACK wascreated ($ESTACK at level 0), <strong>Caché</strong> restores the value of the previous copy of $ESTACK.ExamplesThe following example shows the effect of a NEW command on $ESTACK. In this example,the MainRoutine displays the initial values of $STACK and $ESTACK (which are the samevalue). It then calls Sub1. This call increments $STACK and $ESTACK. The NEW commandcreates an $ESTACK with a value of 0. Sub1 calls Sub2, incrementing $STACK and$ESTACK. Returning to MainRoutine restores the initial values of $STACK and $ESTACK:MainWRITE !,"Initial: $STACK=",$STACK," $ESTACK=",$ESTACKDO Sub1WRITE !,"Return: $STACK=",$STACK," $ESTACK=",$ESTACKQUITSub1WRITE !,"Sub1Call: $STACK=",$STACK," $ESTACK=",$ESTACKNEW $ESTACKWRITE !,"Sub1NEW: $STACK=",$STACK," $ESTACK=",$ESTACKDO Sub2QUITSub2WRITE !,"Sub2Call: $STACK=",$STACK," $ESTACK=",$ESTACKQUITThe following example demonstrates how the value of $ESTACK is incremented as newcontexts are created by issuing DO and XECUTE commands, and decremented as thesecontexts are exited. It also shows that a GOTO command does not create a new context orincrement $ESTACK:MainNEW $ESTACKWRITE !,"Inital Main: $ESTACK=",$ESTACK // 0DO Sub1WRITE !,"Return Main: $ESTACK=",$ESTACK // 0QUITSub1WRITE !,"Sub1 via DO: $ESTACK=",$ESTACK // 1XECUTE "WRITE !,""Sub1 XECUTE: $ESTACK="",$ESTACK" // 2WRITE !,"Sub1 post-XECUTE: $ESTACK=",$ESTACK // 1GOTO Sub2Sub1ReturnWRITE !,"Sub1 after GOTO: $ESTACK=",$ESTACK // 1QUITSub2WRITE !,"Sub2 via GOTO: $ESTACK=",$ESTACK // 1GOTO Sub1Return424 <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!