25.01.2015 Views

Using Caché ObjectScript - InterSystems Documentation

Using Caché ObjectScript - InterSystems Documentation

Using Caché ObjectScript - 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.

User-defined Code<br />

Similarly, a reference to a tag within indirection or an Xecute is to a tag outside of the procedure. Hence Goto @A is not<br />

supported within a procedure, since a Goto from within a procedure must be to a tag within the procedure.<br />

Other parts of the documentation contain more detail on indirection and the Xecute command.<br />

Similarly, when you issue a Job command within a procedure, it starts a child process that is outside the method. This<br />

means that for code such as the following:<br />

Kill ^MyVar<br />

Job MyLabel<br />

Quit $$$OK<br />

MyLabel<br />

Set ^MyVar=1<br />

Quit<br />

In order for the child process to be able to see the label, the method or the class cannot be contained in a procedure block.<br />

8.2.8 Error Traps within Procedures<br />

If an error trap gets set from within a procedure, it needs to be directly to a private tag in the procedure. (This is unlike in<br />

legacy code, where it can contain “+offset” or a routine name. This rule is consistent with the idea that executing an error<br />

trap essentially means unwinding the stack back to the error trap and then executing a Goto.)<br />

If an error occurs inside a procedure, $ZERROR gets set to the procedure “ tag+offset”, not to a private “tag+offset”.<br />

To set an error trap, the normal $ZTRAP or $ETRAP is used, but the value must be a literal. For instance:<br />

Set $ZT = "abc"<br />

// sets the error trap to the private tag "abc" within this block<br />

For more information on error traps, see the chapter of this document on Error Processing.<br />

8.3 Legacy User-Defined Code<br />

Before the addition of procedures to <strong>Caché</strong>, there was support for user-defined code in the form of subroutines and functions<br />

(which themselves can now be implemented as procedures). These legacy entities are described here, primarily to help<br />

explicate already-written code; their ongoing use is not recommended.<br />

8.3.1 Subroutines<br />

8.3.1.1 Syntax<br />

Routine syntax:<br />

label [ ( param [ = default ][ , ...] ) ]<br />

/* code */<br />

Quit<br />

Invoking syntax:<br />

Do label [ ( param [ , ...] ) ]<br />

or<br />

Goto label<br />

86 <strong>Using</strong> <strong>Caché</strong> <strong>ObjectScript</strong>

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

Saved successfully!

Ooh no, something went wrong!