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

Erases a line or range of lines from the current routine.
Synopsis
ZREMOVE:pc lineref1:lineref2
ZR:pc lineref1:lineref2
Arguments
pc Optional — A postconditional expression.
lineref1 Optional — The single line, or first line in a range of lines to be removed. If you omit lineref1, ZREMOVE deletes the entire current routine.
:lineref2 Optional — The last in a range of lines to be removed.
Description
The ZREMOVE command erases routine lines from the current routine. ZREMOVE has two forms:
You can only use the ZREMOVE command when you enter it at the programmer prompt or when you call it using an XECUTE command. It should not be coded into the body of a routine because its operation would effect the execution of that routine.
Only the local copy of the routine is affected, not the routine as stored on disk. To store the modified code, you must use the ZSAVE command to save the routine.
Without an Argument
ZREMOVE without an argument erases the entire current routine. The following Terminal session shows this operation:
USER>DO ^myroutine

USER>ZLOAD myroutine

USER>WRITE $ZNAME
myroutine
USER>ZREMOVE

USER>WRITE $ZNAME

USER>
With Arguments
ZREMOVE with arguments erases code lines in the current routine. ZREMOVE lineref1 erases the specified line. ZREMOVE lineref1:lineref2 erases the range for lines starting with the first line reference and ending with the second line reference, inclusive.
The following Terminal session shows this operation. This example uses a dummy routine (^myroutine) in which each line sets a variable to a string naming that line:
USER>DO ^myroutine

USER>ZLOAD myroutine

USER>PRINT +8
SET x="this is line 8"
USER>ZREMOVE +8

USER>PRINT +8
SET x="this is line 9"
USER>
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.
lineref1
The line to be removed, or the first in a range of lines to be removed. It can take any of the following formats:
+offset Specifies a line number within the routine. A positive integer, counting from 1.
label Specifies a label within the routine. ZREMOVE erases only the label line itself. This includes any code that follows the label on that line.
label+offset Specifies a label and the number of line to offset within the labeled section, counting the label line as line 1.
A label may be longer than 31 characters, but must be unique within the first 31 characters. ZREMOVE matches only the first 31 characters of a specified label. Label names are case-sensitive, and may contain Unicode characters.
You can use lineref1 to specify a single line of code to remove. You specify the code line either as an offset from the beginning of the routine (+lineref1) or as an offset from a specified label (module2+lineref1).
Labels are counted as code lines in a line offset. Whitespace lines are not counted as code lines in line offset. Comments are not counted as code lines in a line offset, with one exception. A single-line comment delimited by ;; is counted as a code line for the purposes of line offset.
lineref2
The last line in a range of lines to be removed. Specify lineref2 in any of the formats used for lineref1. The colon prefix (:) is mandatory.
You specify a range of lines as +lineref1:+lineref2. ZREMOVE removes the range of lines, inclusive of lineref1 and lineref2. If lineref1 and lineref2 refer to the same line, ZREMOVE removes a that single line.
If lineref2 appears earlier in the routine code than lineref1, no operation is performed and no error is generated. For example: ZREMOVE +7:+2, ZREMOVE Test1+1:Test1, ZREMOVE Test2:Test1 would perform no operation.
Examples
This command erases the fourth line within the current routine.
   ZREMOVE +4
This command erases the sixth line after the label Test1.
   ZREMOVE Test1+6
This command erases lines three through ten, inclusive, within the current routine.
   ZREMOVE +3:+10
This command erases the label line Test1 through the line that immediately follows it, within the current routine.
   ZREMOVE Test1:Test1+1
This command erases all of the line from label Test1 through label Test2, inclusive of both labels, within the current routine.
   ZREMOVE Test1:Test2
See Also