Easytrieve MACRO Statement

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.

Progress0 of 0 lessons

MACRO Prototype Format

text
1
2
3
4
MACRO [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.

Macro Structure

Macro definition parts
PartRole
Prototype (MACRO line)Names parameters and opens definition
BodyModel statements expanded on invocation
MEND (optional)Terminates macro definition

Cube Calculation Example

text
1
2
3
4
5
MACRO 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 Versus Keyword Parameters

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.

text
1
2
3
4
5
MACRO 1 POS1 KEY1 VALUE1 * body uses &POS1 and &KEY1 MEND %MYMAC 100 KEY1=OVERRIDE

Percent Invocation

text
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.

Parameter Substitution Rules

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.

Stored Macros Versus Instream Testing

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.

MACRO Versus PROC

MACRO compared to PROC
AspectMACROPROC
When it runsCompile-time expansionRuntime PERFORM
Reuse unitSource text patternsExecutable logic module
Parameters&positional and keywordFields and working storage
ReturnN/A—inlined codeEND-PROC return to caller

Common Macro Use Cases

  • Standard FILE and DEFINE blocks for enterprise master files.
  • Repeated REPORT TITLE and LINE templates for audit layouts.
  • Site-standard working storage counters and flags.
  • SQL INCLUDE field bundles for Db2 tables accessed widely.
  • Compile-time constants parameterized by application ID.

Governance and Change Control

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.

Debugging Macro Expansion

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.

Common MACRO Mistakes

  • MACRO not first statement in definition.
  • Missing positional-count when keyword parameters used.
  • Keyword values before positional values on invocation.
  • Expecting runtime PERFORM behavior from % invocation.
  • Unversioned shared macro change without regression compile.
  • Ampersand typo in body producing invalid field names.

Explain It Like I'm Five

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.

Exercises

  1. Write MACRO with two positional parameters and body assigning &RESULT = &INPUT.
  2. Invoke with %MACRONAME value fieldname.
  3. List three differences between MACRO and PROC.
  4. Design FILE layout macro parameters for record length and DD name.
  5. Document change-control steps when editing a shared PERSNL macro.

Quiz

Test Your Knowledge

1. MACRO prototype statement must be:

  • First statement of the macro definition
  • Last line before MEND
  • Inside JOB only
  • After STOP

2. Invoke stored macro MYFILE in source with:

  • %MYFILE
  • MACRO MYFILE
  • PERFORM MYFILE
  • CALL MYFILE

3. Positional parameters in macro body use prefix:

  • Ampersand & before parameter name
  • Dollar $ only
  • Hash # only
  • At @ only

4. Keyword parameters on MACRO prototype include:

  • Name and default value pairs
  • JCL DD names only
  • REPORT LINE numbers
  • SQL cursors

5. Macro names are limited to:

  • Eight characters (ten in Panvalet/Endevor)
  • 128 characters
  • Three characters
  • One character
Published
Read time17 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 MACRO and macro invocationSources: Broadcom Easytrieve 11.6 MACRO Statement, Define Macros, % InvocationApplies to: Easytrieve MACRO prototype and expansion