Using labels
In a macro, you can assign a label to a line by using the LABEL
assignment statement. For example:
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.
| CLIST Statements | REXX Statements |
|---|---|
|
|
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:
The first example stores new data into the line that currently has the label
| CLIST Statements | REXX Statements |
|---|---|
|
|
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:
This example stores the relative line number of the line with label
| CLIST Statements | REXX Statements |
|---|---|
|
|
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:
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.
| CLIST Statements | REXX Statements |
|---|---|
|
|
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:
removes the label from the line.
| CLIST Statement | REXX Statements |
|---|---|
|
|
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).