Use &SYSNEST to obtain the current macro instruction nesting level.
The local-scope system variable symbol &SYSNEST is assigned a read-only value each time a macro definition is called from a source module.
The value assigned to &SYSNEST is a number from 1 to 99999999. No leading zeros are generated as part of the number. When a macro is called from open code, the value assigned to &SYSNEST is the number 1. Each time a macro definition is called by an inner macro instruction, the value assigned to &SYSNEXT is incremented by 1. Each time an inner macro exits, the value is decremented by 1.
The following example shows the values assigned to &SYSNEST:
MACRO
OUTER
DC A(&SYSNEST) Statement 1
INNER1 Statement 2
INNER2 Statement 3
MEND
MACRO
INNER1
DC A(&SYSNEST) Statement 4
INNER2 Statement 5
MEND
MACRO
INNER2
DC A(&SYSNEST) Statement 6
MEND
--------------------------------------------------------------------
OUTER Statement 7
+ DC A(1)
+ DC A(2)
+ DC A(3)
+ DC A(2)
Statement 7 is in open code. It calls the macro OUTER. &SYSNEST is assigned a value of 1 which is substituted in statement 1.
Statement 2, within the macro definition of OUTER, calls macro INNER1. The value assigned to &SYSNEST is incremented by 1. The value 2 is substituted for &SYSNEST in statement 4.
Statement 5, within the macro definition of INNER1, calls macro INNER2. The value assigned to &SYSNEST is incremented by 1. The value 3 is substituted for &SYSNEST in statement 6.
When the macro INNER2 exits, the value assigned to &SYSNEST is decremented by 1. The value of &SYNEST is 2.
When the macro INNER1 exits, the value assigned to &SYSNEST is decremented by 1. The value of &SYSNEST is 1.
Statement 3, within the macro definition of OUTER, calls macro INNER2. The value assigned to &SYSNEST is incremented by 1. The value 2 is substituted for &SYSNEST in statement 6.
[ Top of Page | Previous Page | Next Page | Contents | Index ]