Macros save maintenance teams from retyping identical FILE layouts, standard field blocks, or report skeletons across dozens of batch programs. The MACRO prototype statement opens a macro definition stored in your site macro library or coded instream for testing. Parameters on the prototype—positional and keyword—map to ampersand references in the macro body. At compile time, a percent invocation statement expands the body into your program with substitutions applied. Beginners confuse macros with COPY books or PROC modules; macros are preprocessor text generation, not runtime calls. This page teaches MACRO syntax, positional-count rules, keyword defaults, MEND termination, invocation with %, LIST NOMACROS listing control, and governance practices for shared macro libraries in regulated mainframe shops.
1234MACRO [positional-count] positional-parameters... keyword-parameters... * macro body statements with &PARAMETER substitution MEND
MACRO must be the first word on the prototype line. Positional-count is required when you mix keyword parameters—it tells the preprocessor how many positional values to expect on invocation. When only keyword parameters appear, positional-count is zero.
| Part | Role |
|---|---|
| Prototype (MACRO line) | Names parameters and opens definition |
| Body | Model statements expanded on invocation |
| MEND (optional) | Terminates macro definition |
12345MACRO 2 NUMBER RESULT DEFINE CUBE_NUMBER_ S 6 N VALUE 000000 CUBE_NUMBER_ = &NUMBER * &NUMBER * &NUMBER &RESULT = CUBE_NUMBER_ MEND
Broadcom Define Macros example declares two positional parameters NUMBER and RESULT. The body computes cube into working storage then assigns to the field name passed as RESULT. Invocation %CUBE 5 CUBE-OUT expands with NUMBER=5 and RESULT=CUBE-OUT.
Positional parameters appear in fixed order on both prototype and invocation—frequently used values belong here because callers pass only values without names. Keyword parameters use name default-value pairs on the prototype; invocation supplies KEYWORD=value to override default. When both types exist, invocations must list all positional values before any keyword pair. Positional-count on MACRO documents how many positionals the invocation must supply.
12345MACRO 1 POS1 KEY1 VALUE1 * body uses &POS1 and &KEY1 MEND %MYMAC 100 KEY1=OVERRIDE
1%PERSNL
A single line invokes macro PERSNL expanding stored FILE and DEFINE layout into the program. Classic tutorials place personnel file definitions in %PERSNL so every payroll program shares one maintained copy. Panvalet and Endevor libraries may allow macro names up to ten characters; default limit is eight.
Ampersand before parameter name in the body marks substitution points. The preprocessor replaces &NUMBER with invocation text before compile continues. Nested macros and quoting follow Macro Facility chapter rules—special characters in actual parameters may require continuation or escape per release. LIST NOMACROS on PARM suppresses macro expansion listing when listings grow large.
Production macros reside in libraries your data center maintains—changes propagate to all invoking programs on next compile. Developers testing new macro bodies may use MSTART and MEND bounds for instream definitions before promoting to the shared library. Version macro libraries with application releases; breaking a shared FILE macro breaks every dependent program at compile.
| Aspect | MACRO | PROC |
|---|---|---|
| When it runs | Compile-time expansion | Runtime PERFORM |
| Reuse unit | Source text patterns | Executable logic module |
| Parameters | &positional and keyword | Fields and working storage |
| Return | N/A—inlined code | END-PROC return to caller |
Treat macro libraries as production source. Require code review for macro edits affecting field offsets—silent layout changes corrupt every invoking program. Document parameter contracts on the prototype comment block. Regression-compile representative programs after macro updates. Endevor or equivalent change packages should include macro elements alongside application sources.
Compile listings with macro expansion show generated statements—use when invocation parameters produce invalid DEFINE syntax. Compare expanded FILE against working program when offsets drift. NOMACROS listings hide expansion; enable full list when diagnosing parameter substitution errors.
A macro is a cookie cutter. You press it into dough once and get the same shape every time. MACRO draws the cutter shape with holes labeled NUMBER and RESULT. %CUBE is pressing the cutter—your numbers fill the holes and the full cookie appears in the program. PROC is a helper you call during baking; MACRO happens when you make the recipe card before baking starts.
1. MACRO prototype statement must be:
2. Invoke stored macro MYFILE in source with:
3. Positional parameters in macro body use prefix:
4. Keyword parameters on MACRO prototype include:
5. Macro names are limited to: