Caché ObjectScript Reference
ZLOAD
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Loads a routine into the current routine buffer.
Synopsis
ZLOAD:pc routine
ZL:pc routine
Arguments
pc Optional — A postconditional expression.
routine Optional — The routine to be loaded. If omitted, Caché loads a routine from the current device.
Description
The ZLOAD command loads a ObjectScript routine into the routine buffer. ZLOAD has two forms:
ZLOAD without an Argument
The ZLOAD command without an argument loads a ObjectScript routine from the current device into the routine buffer. To load a routine from a device, execute the following:
  1. An OPEN command to open the device.
  2. A USE command to make the device the current device.
  3. A ZLOAD command without arguments.
Line loading will continue until Caché reads a null string line (""). This loaded routine has no name until you file it with the ZSAVE command.
ZLOAD with an Argument
ZLOAD routine loads the specified (existing) routine into the routine buffer from the current namespace.
ZLOAD does an implicit argumentless ZREMOVE when it loads the routine. That is, ZLOAD deletes any routine previously loaded as it writes the loaded routine. You can use the $ZNAME special variable to determine the currently loaded routine. When ZLOAD loads a routine, it positions the line pointer at the beginning of the routine.
Once loaded, a routine remains the current one for the process until you load another routine explicitly, with a ZLOAD command, or implicitly, with a DO or a GOTO command.
As long as the routine is current, you can edit the routine (with ZINSERT and ZREMOVE commands), display one or more lines with the ZPRINT command, or return a single line with the $TEXT function.
You can only use the ZLOAD command when you enter it from the programmer prompt or when you call it using an XECUTE command or a $XECUTE function. It should not be coded into the body of a routine because its operation would affect the execution of that routine. Specifying ZLOAD in a routine results in a compile error. Any attempt to execute ZLOAD from within a routine also generates an error.
Arguments
pc
An optional postconditional expression. Caché executes the command if the postconditional expression is true (evaluates to a nonzero numeric value). Caché does not execute the command if the postconditional expression is false (evaluates to zero). For further details, refer to Command Postconditional Expressions in Using Caché ObjectScript.
routine
The name of the routine to be loaded. Routine names are case-sensitive. If the specified routine does not exist, the system generates a <NOROUTINE> error.
You must have execute permission for routine to be able to ZLOAD it. If you do not have this permission, Cache generates a <PROTECT> error.
If ZLOAD successfully loads routine, all subsequent errors append the name of the currently loaded routine. This occurs whether or not the error has any connection to the routine, and occurs across namespaces. For further details, refer to the $ZERROR special variable.
Examples
The following Terminal example loads the routine ROUT, saved on disk:
USER>ZLOAD ROUT
The following Terminal example loads the first routine from the device dev:
USER>OPEN dev
USER>USE dev
USER>ZLOAD
Notes
Routine Behavior with ZLOAD
If you specify routine, Caché looks for the routine in the pool of routine buffers in memory. If the routine is not there, Caché loads the ObjectScript object code version of the routine into one of the buffers. The ObjectScript source (intermediate) code remains in the ^ROUTINE global of the current namespace, but is updated if you make edits and save the changes.
For example, ZLOAD Test loads the object code version of the routine Test (if it is not already loaded). You can view and edit the contents of the ^ROUTINE global using the Management Portal. Select [Home] > [Globals], then select the current namespace from the list of namespaces in the left-hand column.
If you omit routine, Caché loads new lines of code that you enter from the current device, usually the keyboard until you terminate the code by entering a null line (that is, just press <Return>). This routine has no name until you save it with a subsequent ZSAVE command.
ZLOAD and Language Modes
When a routine is loaded, the current language mode changes to the loaded routine’s language mode. At the conclusion of called routines, the language mode is restored to the language mode of the calling routine. However, at the conclusion of a routine loaded with ZLOAD the language mode is not restored to the previous language mode. For further details on checking and setting language modes, refer to the LanguageMode() method of the %SYSTEM.Process class.
See Also