Easytrieve Macro Syntax

Macro syntax is the grammar of compile-time reuse in Easytrieve. Every macro begins with a MACRO prototype statement—the first word on that line must be MACRO—and ends with MEND in typical definitions. Between those boundaries sit model statements: ordinary Easytrieve source with ampersand-prefixed parameter names where callers supply values at invocation. The prototype optionally declares positional-count (how many positional parameters exist), positional parameter names in order, and keyword parameters paired with default values. Invocation uses percent sign and macro name on a separate line in the invoking program. Beginners fail compile when MACRO is not first, when positional-count disagrees with the prototype, or when MEND is missing in instream tests. This page walks prototype formats, naming limits, MSTART development bounds, body content rules, and syntax comparisons across positional-only, keyword-only, and mixed parameter macros.

Progress0 of 0 lessons

Canonical Prototype Format

text
1
2
3
4
MACRO [positional-count] positional-name ... keyword-name default-value ... * model statements — valid Easytrieve source with &PARAMETER references MEND

Brackets show optional positional-count when you mix keyword parameters or need to document positional arity explicitly. Positional parameter names are identifiers without ampersands on the prototype; the body references them with ampersand prefix (&EMPNAME). Keyword parameters on the prototype appear as name followed by default value—the default expands when invocation omits that keyword.

Positional-Count Rules

When positional-count is required
Scenariopositional-countReason
Positional parameters only, no keywordsOptional (implicit from names)Preprocessor counts names on prototype line
Keyword parameters presentRequiredSeparates positional values from keyword=value pairs on invocation
Keyword parameters onlyZeroInvocation supplies only keyword pairs, no leading positional values

Syntax Variant Examples

Positional-only macro

text
1
2
3
4
5
MACRO 2 NUMBER RESULT DEFINE CUBE_WORK S 6 N VALUE 000000 CUBE_WORK = &NUMBER * &NUMBER * &NUMBER &RESULT = CUBE_WORK MEND

Broadcom cube example uses two positional parameters. Invocation %CUBE 5 CUBE-OUT binds NUMBER to 5 and RESULT to CUBE-OUT. The body assigns into the field name passed as RESULT because &RESULT substitutes the actual parameter text.

Keyword-only macro

text
1
2
3
4
5
6
MACRO 0 RECLEN 150 BLKSIZE 1800 FILE PERSNL FB(&RECLEN &BLKSIZE) EMPNAME 17 8 A MEND %PERSNL-FILE RECLEN=200 BLKSIZE=2400

Positional-count zero signals no positional values on invocation. RECLEN defaults to 150 and BLKSIZE to 1800 unless the caller overrides with RECLEN=200 style pairs.

Mixed positional and keyword

text
1
2
3
4
5
6
MACRO 1 FILENAME DDNAME PERSNL FILE &FILENAME FB(150 1800) * fields follow MEND %OPEN-FILE PAYROLL DDNAME=PAYROLL

One positional (FILENAME) must appear first on invocation; DDNAME keyword overrides default PERSNL when supplied.

MEND Termination

MEND closes the macro definition. The preprocessor returns to normal source processing after MEND. Nested macros each require their own MACRO/MEND pair. Placing executable JOB logic between MACRO and MEND by mistake ships that logic into every expansion—usually a compile error if JOB appears inside a library macro meant for FILE only.

MSTART for Instream Development

text
1
2
3
4
5
6
7
8
9
MSTART MACRO FILE TESTFILE FB(80 800) REC-DATA 1 80 A MEND MEND %TESTFILE JOB INPUT TESTFILE

MSTART/MEND pairs bound instream macro facility testing in development programs. Production programs should invoke macros from libraries instead of embedding definitions. Your installation may configure whether double MEND is required—follow local Macro Facility chapter guidance.

Macro Naming and Invocation Syntax

Naming and invocation
RuleDetail
Macro name lengthEight characters default; ten in some libraries
Invocation statementPercent sign immediately followed by macro name
ContinuationLong invocation lines follow site continuation columns
CaseFollow site standards; mainframe sources often uppercase
text
1
%PERSNL

Model Statement Syntax in the Body

Model statements obey Easytrieve language rules after substitution. If &FIELD expands to an invalid identifier, compile fails on the generated line. Ampersand attaches to parameter name without spaces (&NUMBER not & NUMBER). When parameter value must concatenate with literal text, place literals adjacent in the model: FILE &PREFIX DATA expands FILE PAY DATA when PREFIX is PAY.

Prototype Line Ordering

  1. Word MACRO must lead the line.
  2. Positional-count number when keywords exist or clarity demands it.
  3. Positional parameter names in invocation order.
  4. Keyword name and default value pairs.

Reordering positional names on the prototype reorders required invocation values—treat the prototype as a public API contract documented in comments.

Invalid Syntax Patterns

  • PROC or END-PROC inside macro body when generating library definitions—valid only if you intend runtime procedures in expanded source.
  • MACRO not first on prototype line due to leading spaces or comment placement errors.
  • Missing positional-count when keyword parameters exist—preprocessor cannot split invocation tokens.
  • Percent invocation inside macro body without nested macro support—verify Macro Facility rules before chaining.
  • Parameter names exceeding identifier rules after substitution.

Syntax Compared to MACRO Statement Reference Page

The statements/macro page documents the MACRO keyword as a language statement. This page focuses on full macro definition syntax including MEND, MSTART, and invocation relationship. Both pages align with Broadcom 11.6 Define Macros and Macro Invocation topics.

Explain It Like I'm Five

MACRO is the title on a recipe card that lists blank spaces for ingredients. MEND is the bottom of the card where the recipe stops. When you cook, you write %RECIPE and fill in sugar and flour in the blanks—the card turns into real steps. If you forget MEND, the cookbook thinks everything after your recipe is still part of the same card and gets confused.

Exercises

  1. Write a keyword-only macro with positional-count zero and two keyword defaults.
  2. Fix a prototype missing positional-count when a keyword parameter is present.
  3. Document invocation syntax for a mixed macro with one positional and one keyword.
  4. List five valid statement types for a FILE layout macro body.
  5. Explain why MACRO must be the first word on the prototype line.

Quiz

Test Your Knowledge

1. The first word on a macro prototype line must be:

  • MACRO
  • MEND
  • PROC
  • FILE

2. When a macro uses only keyword parameters, positional-count is:

  • Zero
  • Always two
  • Omitted entirely
  • Equal to body line count

3. MEND marks:

  • End of macro definition
  • End of JOB activity
  • End of compile
  • End of JCL

4. Default macro name length limit is:

  • Eight characters
  • Sixteen characters
  • Thirty-two characters
  • Unlimited

5. MSTART is used for:

  • Instream macro testing during development
  • Runtime screen start
  • JCL job initiation
  • SORT input
Published
Read time17 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 MACRO prototype and MEND syntaxSources: Broadcom Easytrieve 11.6 Define Macros, MACRO Statement, Macro FacilityApplies to: Easytrieve macro definition syntax