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.

The DO command has a postconditional expression; if F is not greater than 0, no part of theDO is executed. The DO command's arguments also have postconditional expressions. DOuses these argument postconditionals to select which subroutine(s) (A, B, or C) to execute.All subroutines that fulfill the truth condition are executed, in the order presented. Thus, inthe above example, C, with no postconditional, is always executed: if F=1 both A and C areexecuted; if F=2, B and C are executed; if F=3 (or any other number) C is executed. Toestablish C as a true default, do the following:DO:F>0 A:F=1,B:F=2,C:((F'=1)&&(F'=2))In this example, one and only one subroutine is executed.For more information on how postconditional expressions are evaluated, see CommandPostconditional Expressions in Using <strong>Caché</strong> <strong>ObjectScript</strong>.When using argument postconditionals, make sure there are no unwanted side effects. Forexample, consider the following command:DO @^Control(i):z=1In this case, ^Control(i) contains the name of the subroutine to be called if the postconditionalz=1 tests TRUE. Whether or not z=1, <strong>Caché</strong> evaluates the value of ^Control(i) and resets thecurrent global naked indicator accordingly. If z=1 is FALSE, <strong>Caché</strong> does not execute the DO.However, it does reset the global naked indicator just as if it had executed the DO. For moredetails on the naked indicator, see Naked Global <strong>Reference</strong> in Using <strong>Caché</strong> Multi-DimensionalStorage.$TEST Behavior with DOWhen you use DO to call a subroutine (either with or without parameter passing), <strong>Caché</strong> doesnot preserve the value of the $TEST special variable across the call. The argumentless DOis the only standard form that preserves the value of $TEST.To save the $TEST value across a DO call, you can explicitly assign it to a variable prior tothe call. You can then reference the variable in code that follows the call.The following code illustrates some unexpected $TEST behavior that can result when usingDO with the legacy IF command (which sets $TEST). This behavior does not occur withthe standard (code block) IF command, because the standard IF does not set $TEST.DO<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 31

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

Saved successfully!

Ooh no, something went wrong!