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> Commandssaves the current values of all variables on the program stack and restores them after thesubroutine or function terminates.ExamplesThe following example illustrates an inclusive NEW, which keeps the existing local variablesa, b, and c, and adds variables d and e, in this case, overlaying the prior value of d.MainSET a=7,b=8,c=9,d=10WRITE !,"Before NEW:",!,"a=",a,!,"b=",b,!,"c=",c,!,"d=",dDO Sub1WRITE !,"Returned to prior context:"WRITE !,"a=",a,!,"b=",b,!,"c=",c,!,"d=",dQUITSub1NEW d,eSET d="big number"WRITE !,"After NEW:",!,"a=",a,!,"b=",b,!,"c=",c,!,"d=",dQUITThe following example illustrates an exclusive NEW, which removes all existing local variablesexcept the specified variables a and c.SET a=7,b=8,c=9,d=10NEW (a,c)WRITENotesWhere to Use NEWNEW allows you to insulate the current process's local variable environment from changesmade by a subroutine, user-defined function, or XECUTE string. NEW is most frequentlyused within a subroutine called by the DO command.The basic purpose of the NEW command is to redefine the local variable environment withina called subroutine or user-defined function. A subroutine or user-defined function calledwithout parameter passing inherits its local variable environment from the calling routine.To redefine this environment for a subroutine or function, you can use NEW for all localvariables (argumentless NEW), for named local variables (inclusive NEW) or for all localvariables except the named variables (exclusive NEW).Special considerations apply in the case of a subroutine called by the DO command withparameter passing. These considerations are described under "Subroutines with ParameterPassing".96 <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!