09.02.2015 Views

Using the Caché ^%R Routine - InterSystems Documentation

Using the Caché ^%R Routine - InterSystems Documentation

Using the Caché ^%R Routine - 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.

LENGTH<strong>^%R</strong><br />

This example makes use of o<strong>the</strong>r entry points in <strong>^%R</strong> that are described elsewhere in this<br />

document.<br />

WARNING!<br />

This example creates a routine in <strong>the</strong> SAMPLES namespace called<br />

AnExample.INT. If <strong>the</strong>re is already a routine by that name in that namespace,<br />

it will be overridden.<br />

; Change <strong>the</strong> namespace we will use<br />

Znspace "SAMPLES"<br />

; fill in <strong>the</strong> source code array<br />

Set N = 0<br />

Set code($INCREMENT(N)) = "AnExample ; An example routine"<br />

; Note leading spaces on <strong>the</strong> following entries"<br />

Set code($INCREMENT(N)) = " Write ""Starting AnExample"", !"<br />

Set code($INCREMENT(N)) = ""<br />

Set code($INCREMENT(N)) = " Write ""Some text"", !"<br />

Set code($INCREMENT(N)) = ""<br />

Set code($INCREMENT(N)) = " Write ""Finished AnExample"", !"<br />

Set code($INCREMENT(N)) = " Quit"<br />

Set code(0) = N<br />

Set routine = "AnExample.INT"<br />

Set options = "S"<br />

Set errors = ""<br />

; Save<br />

; empty list<br />

; do it<br />

Set return = $$ROUTINE<strong>^%R</strong>(routine, .code, .errors, options)<br />

; show <strong>the</strong> simple result<br />

Write "Save result: ", return, !<br />

If (+return = "")<br />

{<br />

; format and display <strong>the</strong> errors<br />

Write $$FMTERR<strong>^%R</strong>(.errors, .code), !<br />

}<br />

Else<br />

{<br />

; remove local info<br />

Kill code<br />

; find out about it<br />

Write "Lines in ", routine, ": ", $$LENGTH<strong>^%R</strong>(routine), !<br />

}<br />

; remove <strong>the</strong> saved source<br />

Write "Removing ", routine, ": ", $$DEL<strong>^%R</strong>(routine), !<br />

<strong>Using</strong> <strong>the</strong> <strong>Caché</strong> <strong>^%R</strong> <strong>Routine</strong> 21

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

Saved successfully!

Ooh no, something went wrong!