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.

NEWNEW and KILLVariables created by NEW do not require explicit and corresponding KILL commands.When a called subroutine or a user-defined function terminates, <strong>Caché</strong> executes an implicitKILL for each variable initialized by a NEW command within that subroutine or function.Inclusive NEWAn inclusive NEW — NEW variable — retains the existing local variable environment andadds the specified variables to it. If an existing variable is named, the "new" variable replacesthe existing variable, which is saved on the stack and then restored when the subroutine orfunction terminates.In the following example, assume that the local variable environment of the calling routine(Start) consists of variables a, b, and c. When the DO calls Subr1, the NEW command redefinesSubr1's local variable environment to add variables c and d. After the NEW, the subroutine'senvironment consists of the existing variables a and b plus the new variables c and d.The variables a and b are inherited and retain their existing values. The new variables c andd are created undefined. Since c is the name of an existing local variable, <strong>Caché</strong> saves theexisting value on the stack and restores it when Subr1 QUITs. Note that the first SET commandin Subr1 references a and b to assign a value to d. If c were referenced at this point,<strong>Caché</strong> would issue an error.Start SET a=2,b=4,c=6DO Subr1WRITE !,"c in Start: ",cQUITSubr1 NEW c,dSET d=a*bSET c=d*2WRITE !,"c in Subr1: ",cQUITWhen executed, this code produces the following results:c in Subr1: 16c in Start: 6Exclusive NEWAn exclusive NEW — NEW (variable) — replaces the entire existing local variable environmentexcept the specified variables. If an existing variable is named, it is retained and can bereferenced in the new environment. However, any changes made to such a variable arereflected in the existing variable when the function or subroutine terminates.<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 97

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

Saved successfully!

Ooh no, something went wrong!