Easytrieve Macro Expansion

Macro expansion is the preprocessor step that turns a single % invocation into many lines of Easytrieve source. Understanding expansion separates developers who debug compile errors in minutes from those who stare at a one-line %PERSNL wondering why DEPT offset is wrong. The preprocessor loads the macro definition, binds positional and keyword actuals to prototype parameters, walks each model statement replacing & tokens, and inserts the result inline. The compiler never sees the percent line—it sees generated FILE, DEFINE, and REPORT statements exactly as if typed by hand. Listings document this transformation unless LIST NOMACROS suppresses it. Nested invocations expand inner macros before outer bodies complete. This page covers the expansion pipeline, reading listings, controlling list volume, diagnosing substitution failures, verifying layouts after library updates, and relating expansion to the broader compile process you studied earlier.

Progress0 of 0 lessons

Expansion Pipeline Step by Step

  1. Scanner reads invoking program source until it finds %MACRONAME.
  2. Preprocessor resolves macro from instream MSTART block or cataloged library member.
  3. Invocation tokens parse into positional and keyword actuals using positional-count.
  4. Each model statement copies to output buffer with &PARAMETER replacements applied.
  5. Expanded text replaces the invocation line (or inserts at correct section boundary).
  6. Compiler parses combined source—library plus generated statements plus activities.

Before and After Example

text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
* Source you maintain %PERSNL JOB INPUT PERSNL IF DEPT = 911 PRINT PAY-RPT END-IF * Conceptual post-expansion fragment 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 IF DEPT = 911 PRINT PAY-RPT END-IF

Compiler Listings and Macro Sections

Compile listings vary by installation, but macro-aware listings show which invocations expanded, sometimes repeating generated lines with sequence numbers for error correlation. When error messages cite statement 000045, scroll the listing to that line in the post-expansion view—often the bug is a substituted token producing invalid syntax, not your original JOB logic.

Listing controls
Option / practiceEffect on expansion visibility
Default macro listingShows expanded statements for debugging
LIST NOMACROSOmits expansion detail—smaller listings
Full list during macro developmentVerify every & substitution
Compare before/after library changeDiff expansion output in change review

LIST NOMACROS

Large programs invoking many layout macros generate listings thousands of lines long. Production compile procedures often specify LIST NOMACROS on the compile PARM to archive slimmer output. Turn NOMACROS off when diagnosing parameter errors—without expansion text you only see the percent line and cryptic downstream syntax errors.

text
1
PARM='LIST NOMACROS'

Nested Macro Expansion

A macro body may contain %OTHERMAC invocations. Preprocessor typically expands inner macros first so outer & substitutions see resolved text or inner-generated lines depending on facility rules. Deep nesting increases compile cost; flatten occasionally by merging stable inner macros into outer bodies after review.

text
1
2
3
4
MACRO %STD-HEADER LINE 01 DEPT EMPNAME MEND

Diagnosing Substitution Errors

Invalid field name after expansion

Actual parameter included special character illegal in identifiers—listing shows DEFINE with bad name. Fix invocation quoting or macro body literal placement.

Wrong offset in FILE

Keyword default changed or wrong RECLEN passed—compare expansion listing to data dictionary. Not a runtime bug; regenerated source carries wrong numbers until recompile with corrected invocation or macro default.

Missing positional value

Preprocessor error before compile—positional-count expects three values, invocation supplied two. Error references macro invocation line in pre-expansion source.

Expansion Versus Runtime Behavior

Expanded code is fixed in the load module until next compile. Changing a macro library member does not affect already-linked programs. Operations teams must track which load modules were built against which macro library level—parallel to copybook level tracking in COBOL shops.

Performance and Size Considerations

  • Many expansions increase compile CPU and listing storage.
  • Identical % invocations in one program expand separately—duplicate generated text unless optimizer merges (do not rely on merge).
  • Very large macro bodies approach copybook size limits—split into composable macros.
  • NOMACROS reduces I/O archiving listings in mass nightly compiles.

Verification Checklist After Macro Library Change

  1. Recompile pilot program with full macro listing enabled.
  2. Verify FILE offsets against enterprise data dictionary PDF.
  3. Confirm DEFINE names match activity references (JOB, REPORT).
  4. Run regression test job comparing output to baseline.
  5. Promote library member only after sign-off; document in release notes.

Relationship to Compile Process Tutorial

The compile process page places preprocessor expansion before syntactic and semantic analysis. Macro expansion errors surface in preprocessor or compiler phases depending on failure type. Debugging overview in the next section covers broader listing interpretation including non-macro errors.

Explain It Like I'm Five

Expansion is like a printer copying a stencil. You hold up the stencil (%MACRO), the printer sprays ink through the holes (arguments), and a full picture appears on the paper (your program). NOMACROS is telling the printer not to show the stencil outline in the instruction manual—fine when you trust the stencil, bad when the picture looks wrong and you need to see which hole was blocked.

Exercises

  1. Sketch the six expansion pipeline steps from memory.
  2. Explain when you would enable versus disable NOMACROS.
  3. Describe how you would find a bad DEPT offset after macro change using listings.
  4. Write a nested macro example and predict expansion order.
  5. List three differences between expansion-time and runtime errors.

Quiz

Test Your Knowledge

1. Macro expansion happens during:

  • Preprocessor phase before language compile
  • JOB INPUT loop
  • Report PRINT
  • JCL execution only

2. LIST NOMACROS on compile PARM:

  • Suppresses macro expansion detail in listing
  • Forces double expansion
  • Disables macros entirely
  • Prints JCL

3. When expansion produces invalid DEFINE syntax, compile fails on:

  • Generated lines as if you typed them manually
  • Original % line only
  • JCL
  • Runtime abend

4. To debug wrong field offsets after macro change, compare:

  • Expansion listing against known good layout
  • Only JCL
  • Runtime dump only
  • PF keys

5. Nested macro means:

  • Macro body contains % invocation of another macro
  • Two PROC modules
  • Duplicate JOB names
  • SORT merge
Published
Read time17 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 macro expansion and listingsSources: Broadcom Easytrieve 11.6 Macro Facility, LIST NOMACROS, Define MacrosApplies to: Easytrieve macro preprocessor expansion