HLASM Language Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Nesting macro instruction definitions

HLASM Language Reference
SC26-4940-06

A nested macro instruction definition is a macro instruction definition you can specify as a set of model statements in the body of an enclosing macro definition. This lets you create a macro definition by expanding the outer macro that contains the nested definition.

All nested inner macro definitions are effectively "black boxes": there is no visibility to the outermost macro definition of any variable symbol or sequence symbol within any of the nested macro definitions. This means that you cannot use an enclosing macro definition to tailor or parameterize the contents of a nested inner macro definition.

High Level Assembler allows both inner macro instructions and inner macro definitions. The inner macro definition is not edited until the outer macro is generated as the result of a macro instruction calling it, and then only if the inner macro definition is encountered during the generation of the outer macro. If the outer macro is not called, or if the inner macro is not encountered in the generation of the outer macro, the inner macro definition is never edited. Figure 1 shows the editing of inner macro definitions.
Figure 1. Editing inner macro definitions
┌─────────────┐
│    MACRO    │
│    MAC1     ├─────────────────────────────────────┐
│     •       │                                     │
└─────────────┘                                     │
┌─────────────┐                                     │
│    MACRO    │                                     │
│    MAC2     ├──────────────────┐                  │
│     •       │                  │                  │
└─────────────┘                  │                  │
┌─────────────┐                  │                  │
│    MACRO    │                  │                  │
│    MAC3     │                  │                  │
│     •       │   Edited when    │   Edited when    │   Edited when
│     •       ├── MAC2 is called ├── MAC1 is called ├── definition first
│     •       │   and generated  │   and generated  │   encountered
│     •       │                  │                  │
│    MEND     │                  │                  │
└─────────────┘                  │                  │
┌─────────────┐                  │                  │
│     •       ├──────────────────┘                  │
│    MEND     │                                     │
└─────────────┘                                     │
┌─────────────┐                                     │
│     •       ├─────────────────────────────────────┘
│    MEND     │
└─────────────┘

First MAC1 is edited, and MAC2 and MAC3 are not. When MAC1 is called, MAC2 is edited (unless its definition is bypassed by an AIF or AGO branch); when MAC2 is called, MAC3 is edited. No macro can be called until it has been edited.

There is no limit to the number of nestings allowed for inner macro definitions.

The lack of parameterization can be overcome in some cases by using the AINSERT statement. This lets you generate a macro definition from within another macro generation. A simple example is shown at Where to define a macro in a source module. In Figure 2, macro ainsert_test_macro generates the macro mac1 using a combination of AINSERT and AREAD instructions. The mac1 macro is then called with a list of seven parameters.
Figure 2. Expanding nested macro definitions
       1          macro
       2 &name    ainsert_test_macro
       3          ainsert   '         Macro',back
       4          ainsert   '         mac1',back
       5          ainsert   'Blah blah blah',front
       6 &aread   aread
       7 &aread   setc   '&aread'(1,10)
       8          ainsert   '&&n      seta n''&&syslist ',back
       9          ainsert   '         dc a(&&n)',back
      10          ainsert   '         dc c''&aread'' ',back
      11          ainsert   '         mend',back
      12          mend
      13 *
      14 testains csect 0
      15 *
      16          ainsert_test_macro
      17+         ainsert   '         Macro',back
      18+         ainsert   '         mac1',back
      19+         ainsert   'Blah blah blah',front
      20-Blah blah blah
      21+         ainsert   '&&n       seta n''&&syslist ',back
      22+         ainsert   '         dc a(&&n)',back
      23+         ainsert   '         dc c''Blah blah '' ',back
      24+         ainsert   '         mend',back
      25>         Macro
      26>         mac1
      27>&n       seta n'&syslist
      28>         dc a(&n)
      29>         dc c'Blah blah '
      30>         mend
      31 *
      32          mac1  a,b,c,d,e,f,g
      33+         dc a(7)
      34+         dc c'Blah blah '
      35 *
      36          end

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014