In a macro, you can assign a label to a line by using the LABEL
assignment statement. For example:
CLIST Statements |
REXX Statements |
---|
SET &LNUM = 10
ISREDIT LABEL &LNUM = .HERE
|
ADDRESS ISPEXEC
lnum = 10
'ISREDIT LABEL' lnum '= .HERE'
|
This
assigns the label .HERE to the line whose relative line number is
contained in variable LNUM (line 10 here). The .HERE label allows
the macro to keep track of a line whose relative line number may change.
When the macro finishes running, the .HERE label is removed.
Labels can be used as part of a keyphrase instead of a line number.
For example:
CLIST Statements |
REXX Statements |
---|
ISREDIT LINE .NEXT = (DATAVAR)
ISREDIT LINE_AFTER .XYZ = (DATAVAR)
|
ADDRESS ISPEXEC
'ISREDIT LINE .NEXT = (DATAVAR)'
'ISREDIT LINE_AFTER .XYZ = (DATAVAR)'
|
The first example stores new data into the line that currently
has the label
.NEXT. The second example creates a
new line after the line whose label is
.XYZ, and
stores data into the new line.
A macro can determine if a label exists. Using the LINENUM assignment
statement, you can obtain the current relative line number of a labeled
line. If the label does not exist, the return code (&LASTCC for
CLIST or RC for REXX) is 8. For example:
CLIST Statements |
REXX Statements |
---|
ISREDIT (LNUM2) = LINENUM .ABC
IF &LASTCC = 8 THEN WRITE NO .ABC LABEL
|
ADDRESS ISPEXEC
'ISREDIT (LNUM2) = LINENUM .ABC'
IF RC = 8 THEN SAY 'No .ABC label'
|
This example stores the relative line number of the line
with label
.ABC into variable LNUM2 and tests to
see if that label did exist.
Labels have a variety of uses. For example, because both the FIND
and SEEK commands position the cursor at the search string after the
macro has been started, you may want to assign the data from the line
on which the cursor is positioned to the variable CSRDATA. To do so,
use this statement:
CLIST Statements |
REXX Statements |
---|
ISREDIT FIND 'IT'
ISREDIT (CSRDATA) = LINE .ZCSR
|
ADDRESS ISPEXEC
'ISREDIT FIND IT'
'ISREDIT (CSRDATA) = LINE .ZCSR'
|
The label .ZCSR names the line in which the cursor is positioned.
The .ZCSR label is moved to a new line when one of these commands
moves the cursor: FIND, CHANGE, SEEK, EXCLUDE, TSPLIT or CURSOR. The
labels .ZFIRST and .ZLAST can also move when data is added or deleted.
If you assign a labeled line a new label that is blank, the previous
label becomes unassigned (if both labels are at the same level). For
example:
CLIST Statement |
REXX Statements |
---|
ISREDIT LABEL .HERE = ' '
|
ADDRESS ISPEXEC
"ISREDIT LABEL .HERE = ' '"
|
removes the label from the line.
If a label in use is assigned to another line, the label is moved
from the original line to the new line (if the new assignment is at
the same level as the original).