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.

Procedures in Detail<br />

• Any tags in the procedure are private to the procedure and can only be accessed from within the procedure. The PRIVATE<br />

keyword can be used on tags within a procedure, although it is not required. The PUBLIC keyword cannot be used on<br />

tags within a procedure — it yields a syntax error. Even the system function $TEXT cannot access a private tag by<br />

name, although $TEXT does support tag+offset using the procedure tag name.<br />

• Duplicate tags are not permitted within a procedure but, under certain circumstances, are permitted within a routine.<br />

Specifically, duplicate tags are permitted within different procedures. Also, the same tag can appear within a procedure<br />

and elsewhere within the routine in which the procedure is defined. For instance, the following three occurrences of<br />

“TAG1” are permitted:<br />

Rou1 // Rou1 routine<br />

Proc1(X,Y) {<br />

TAG1 // TAG1 within the proc1 procedure within the Rou1 routine<br />

}<br />

Proc2(A,B,C) {<br />

TAG1 // TAG1 within the Proc2 procedure (local, as with previous TAG1)<br />

}<br />

TAG1 // TAG1 that is part of Rou1 and neither procedure<br />

• If the procedure contains a Do or user-defined function without a routine name, it refers to a tag within the procedure,<br />

if one exists. Otherwise, it refers to a tag in the routine but outside of the procedure.<br />

• If the procedure contains a Do or user-defined function with a routine name, it always identifies a line outside of the<br />

procedure. This is true even if that name identifies the routine that contains the procedure. For example:<br />

ROU1 ;<br />

PROC1(X,Y) {<br />

Do TAG1^ROU1<br />

TAG1 ;<br />

}<br />

TAG1 ; The Do calls this tag<br />

• If a procedure contains a Goto, it must be to a private tag within the procedure. You cannot exit a procedure with a<br />

Goto.<br />

• "Tag+offset" syntax is not supported within a procedure, with a few exceptions:<br />

– $TEXT supports tag+offset from the procedure tag.<br />

– Goto tag+offset is supported in direct mode lines from the procedure tag as a means of returning to the procedure<br />

following a Break or error.<br />

– The ZBreak command supports a specification of tag+offset from the procedure tag.<br />

– The $TEST state in effect when the procedure was called is restored upon the Quit for the procedure.<br />

– The “}” that denotes the end of the procedure can be in any character position on the line, including the first<br />

character position. Code can precede the “}” on the line, but cannot follow it on the line.<br />

– An implicit Quit is present just before the closing brace.<br />

– Indirection and Xecute commands behave as if they are outside of a procedure.<br />

8.2.7 Indirection, Xecute Commands, and the Job Commands within Procedures<br />

Name indirection, argument indirection, and Xecute commands that appear within a procedure are not executed within the<br />

scope of the procedure. Thus, Xecute acts like an implied Do of a subroutine that is outside of the procedure.<br />

Indirection and Xecute only access public variables. As a result, if indirection or an Xecute references a variable X, then<br />

it references the public variable X regardless of whether or not there is also a private X in the procedure. For example:<br />

Set x="set a=3" XECUTE x ; sets the public variable a to 3<br />

Set x="tag1" Do @x ; accesses the public subroutine tag1<br />

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

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

Saved successfully!

Ooh no, something went wrong!