&SYSNDX System Variable Symbol
For each macro invocation, a new value of &SYSNDX is assigned. The previous value is incremented by 1. Thus, you can attach &SYSNDX to the end of a symbol inside a macro definition to generate a unique suffix for that symbol each time you call the definition. Although an apparently identical symbol is to be generated by two or more calls to the same definition, the suffix provided by &SYSNDX produces two or more unique symbols. For example, the symbol ABC&SYSNDX might generate ABC0001 on one invocation of a macro, and ABC0002 on the next invocation. Thus you avoid an error being flagged for multiply defined symbols.
The local-scope system variable symbol &SYSNDX is assigned a read-only value each time a macro definition is called from a source module.
The value assigned to &SYSNDX is a number from 1 to 9999999. For the numbers 0001 through 9999, four digits are generated. For the numbers 10000 through 9999999, the value is generated with no zeros to the left. The value 0001 is assigned to the first macro called by a program, and is incremented by one for each subsequent macro call (including nested macro calls).
- &SYSNDX does not generate a valid symbol, and it must:
- Follow the alphabetic character to which it is concatenated
- Be concatenated to a symbol containing 59 characters or fewer
- The value of the type attribute of &SYSNDX (T'&SYSNDX) is always N.
- The value of the count attribute (K'&SYSNDX) is equal to the number of digits generated. If a symbol generated by one macro is to be referenced by code generated by another macro, the two macros must provide means for communicating the necessary information. Their respective values of &SYSNDX cannot be guaranteed to differ by any fixed amount.
OUTER1
,
is the 106th macro instruction processed by the assembler. MACRO
INNER1
GBLC &NDXNUM
A&SYSNDX SR 2,5 Statement 1
CR 2,5
BE B&NDXNUM Statement 2
B A&SYSNDX Statement 3
MEND
MACRO
&NAME OUTER1
GBLC &NDXNUM
&NDXNUM SETC '&SYSNDX' Statement 4
&NAME SR 2,4
AR 2,6
INNER1 Statement 5
B&SYSNDX S 2,=F'1000' Statement 6
MEND
-------------------------------------------------------------------
ALPHA OUTER1 Statement 7
BETA OUTER1 Statement 8
-------------------------------------------------------------------
ALPHA SR 2,4
AR 2,6
A0107 SR 2,5
CR 2,5
BE B0106
B A0107
B0106 S 2,=F'1000'
BETA SR 2,4
AR 2,6
A0109 SR 2,5
CR 2,5
BE B0108
B A0109
B0108 S 2,=F'1000'
Statement 7 is the 106th macro instruction processed. Therefore, &SYSNDX
is assigned the number 0106 for that macro instruction. The number
0106 is substituted for &SYSNDX when it is used in statements
4 and 6. Statement 4 is used to assign the character value 0106
to
the SETC symbol &NDXNUM
Statement 6 is used to
create the unique name B0106
.
Statement 5 is the 107th macro instruction processed. Therefore, &SYSNDX
is assigned the number 0107
for that macro instruction.
The number 0107
is substituted for &SYSNDX when
it is used in statements 1 and 3. The number 0106
is
substituted for the global-scope SETC symbol &NDXNUM
in
statement 2.
Statement 8 is the 108th macro instruction processed. Therefore,
each occurrence of &SYSNDX is replaced by the number 0108
.
For example, statement 6 is used to create the unique name B0108
.
When statement 5 is used to process the 108th macro instruction,
statement 5 becomes the 109th macro instruction processed. Therefore,
each occurrence of &SYSNDX is replaced by the number 0109
.
For example, statement 1 is used to create the unique name A0109
.