Easytrieve Macros Overview

Macros are Easytrieve's compile-time reuse mechanism. Instead of typing the same FILE block, DEFINE fields, or REPORT skeleton in every program, you define the pattern once in a macro library and invoke it with a single percent line. The preprocessor expands the macro body into your source before the compiler sees the program—parameter values replace ampersand references in the model statements. A personnel master file might appear in dozens of batch reports; when HR adds a new column, one macro edit and recompile fixes every dependent program. Beginners often confuse macros with PROC modules or JCL procedures; macros never execute at runtime—they only generate source text. PROC handles runtime PERFORM logic. This section overview maps the macro learning path: syntax and prototype rules, positional and keyword arguments, how expansion appears in compiler listings, and governance for shared libraries in regulated mainframe shops. You will also see when macros beat COPY-style duplication and when PROC or inline code is the better choice.

Progress0 of 0 lessons

What Macros Do in the Compile Pipeline

Easytrieve compilation has a preprocessor phase before language analysis. When the scanner encounters %MACRONAME, it loads the macro definition from your instream source or from a site macro library, substitutes invocation parameters into the body, and inserts the resulting statements in place of the invocation line. The expanded source then flows through DEFINE validation, activity parsing, and code generation as if you had typed every line manually. That means a typo in a shared macro breaks compile for every caller until the library is corrected—powerful for consistency, dangerous without change control.

text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* Before expansion — your program %PERSNL JOB INPUT PERSNL PRINT PAY-RPT * After expansion — preprocessor output (conceptual) FILE PERSNL FB(150 1800) EMPNAME 17 8 A EMP# 9 5 N DEPT 98 3 N GROSS 94 4 P 2 JOB INPUT PERSNL PRINT PAY-RPT

Macro Definition Versus Invocation

Two sides of every macro
ElementPurposeTypical location
MACRO prototypeOpens definition, declares parametersMacro library member or instream MSTART block
Macro bodyModel statements with &PARAMETER substitutionBetween MACRO and MEND
MENDTerminates macro definitionEnd of macro source
% invocationRequests expansion at compile timeLibrary section of invoking program

Section Learning Path

  1. Macro syntax — prototype format, positional-count, MEND, MSTART for instream testing, and naming limits (eight characters default, ten in some libraries).
  2. Macro arguments — positional order, keyword defaults, mixing both types, and ampersand rules in the body.
  3. Macro expansion — what listings show, LIST NOMACROS, debugging substitution errors, nested invocations.
  4. Macro reuse — library governance, Endevor promotion, regression compile, versioning with application releases.

Macros Versus Other Reuse Options

Choose the right reuse tool
ToolWhen to useWhen it takes effect
MACRO / %Identical or parameterized source patterns (FILE, DEFINE, REPORT lines)Compile-time expansion
PROC / PERFORMExecutable logic reused within one activity at runtimeRuntime call and return
CALL external moduleLogic shared across programs as compiled load moduleRuntime LINK or equivalent
Manual copy-pasteOne-off prototype never shared—avoid for production layoutsImmediate but unmaintainable

Classic Personnel File Example

Broadcom tutorials use PERSNL as the teaching file. A macro might encapsulate the FILE statement and field definitions so every filtered report program starts with %PERSNL instead of fifteen lines of offsets. When DEPT moves from column 98 to 100 in the physical record, analysts update the macro once; every program picking up the new library member gets correct offsets on compile. Without macros, teams grep through hundreds of sources and miss one program—producing silent wrong totals in production.

text
1
2
3
4
5
6
7
MACRO FILE PERSNL FB(150 1800) EMPNAME 17 8 A EMP# 9 5 N DEPT 98 3 N GROSS 94 4 P 2 MEND

Stored Libraries Versus Instream Development

Production macros reside in libraries your data center catalogs—Panvalet, Endevor, or the Easytrieve macro facility. Compile JCL or IDE profiles point the preprocessor at those libraries. Developers prototyping new layouts may code macros instream between MSTART and MEND, test expansion locally, then promote the member to the shared library after review. Never leave production programs depending on instream-only macros that never reached the library; the next developer without your test block gets compile errors.

Where Macros Appear in Program Structure

Invocations usually sit in the Library section alongside FILE and DEFINE—before JOB, REPORT, or SCREEN activities. Expanded content becomes part of the library the compiler binds to activities. Some macros generate REPORT TITLE and LINE templates inside the Report section when parameters supply report names. Match macro output to valid Easytrieve syntax for the target section; a macro that emits JOB statements into the library section is valid, one that emits REPORT lines mid-JOB is not.

Benefits for Beginners and Teams

  • Fewer transcription errors when field offsets match the enterprise standard.
  • Faster new program creation—invoke three macros and write only business logic.
  • Audit trail when macro libraries are change-controlled like application source.
  • Parameterized layouts (record length, DD name prefix) without runtime cost.
  • Consistent REPORT headers and column masks across departmental reports.

Risks and Mitigations

Silent layout drift

If one program skips recompile after a macro change, it runs with old offsets baked into the load module. Mitigation: regression-compile representative programs after macro updates; track macro version in release notes.

Over-macroing

Wrapping single-line statements in macros adds indirection without benefit. Reserve macros for blocks repeated at least three times or requiring parameterized variation.

Parameter contract breaks

Adding a required positional parameter without updating every invocation fails compile—good. Changing keyword defaults silently changes generated DEFINE sizes—document defaults in comments.

Relationship to Other Tutorials

You studied FILE and DEFINE in the library section tutorials—macros package those statements. Compile process explains where expansion fits in the full build. Procedures overview covered PERFORM; remember macros are not procedures. Report section tutorials show LINE and TITLE targets macro bodies often generate. When you reach debugging, compiler listings reveal expanded macro text for troubleshooting.

Explain It Like I'm Five

Imagine building with LEGO. A macro is a pre-built wall piece your dad made once. When you need that wall, you snap the piece in—you do not rebuild every brick. %PERSNL is asking for the pre-built wall. PROC is calling your friend to help while you are already playing—that happens later during the game, not when you open the LEGO box.

Exercises

  1. List three statements you would put in a PERSNL layout macro.
  2. Explain compile-time versus runtime reuse in your own words.
  3. Sketch a change-control checklist when editing a shared FILE macro.
  4. Compare when you would use MACRO versus PROC for tax calculation.
  5. Find where % invocations belong in a sample program structure diagram.

Quiz

Test Your Knowledge

1. Easytrieve macros run at:

  • Compile time (preprocessor expansion)
  • Runtime only during JOB INPUT
  • JCL execution
  • Only in CICS

2. Invoke a stored macro named PERSNL with:

  • %PERSNL
  • PERFORM PERSNL
  • MACRO PERSNL
  • COPY PERSNL

3. Macros are best for:

  • Repeated FILE and DEFINE layouts shared across programs
  • Runtime tax calculation logic
  • Dynamic SQL at execution
  • Operator screen navigation

4. PROC modules differ from macros because PROC:

  • Runs at runtime via PERFORM
  • Expands at compile time only
  • Uses percent invocation
  • Cannot accept parameters

5. Production macros typically live in:

  • Site macro libraries (Endevor, Panvalet, or product facility)
  • JCL only
  • SYSPRINT
  • Temporary datasets
Published
Read time18 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 Macro Facility overviewSources: Broadcom Easytrieve 11.6 Define Macros, MACRO Statement, Macro InvocationApplies to: Easytrieve macro facility introduction