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.
1234MACRO [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.
| Scenario | positional-count | Reason |
|---|---|---|
| Positional parameters only, no keywords | Optional (implicit from names) | Preprocessor counts names on prototype line |
| Keyword parameters present | Required | Separates positional values from keyword=value pairs on invocation |
| Keyword parameters only | Zero | Invocation supplies only keyword pairs, no leading positional values |
12345MACRO 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.
123456MACRO 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.
123456MACRO 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 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.
123456789MSTART 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.
| Rule | Detail |
|---|---|
| Macro name length | Eight characters default; ten in some libraries |
| Invocation statement | Percent sign immediately followed by macro name |
| Continuation | Long invocation lines follow site continuation columns |
| Case | Follow site standards; mainframe sources often uppercase |
1%PERSNL
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.
Reordering positional names on the prototype reorders required invocation values—treat the prototype as a public API contract documented in comments.
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.
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.
1. The first word on a macro prototype line must be:
2. When a macro uses only keyword parameters, positional-count is:
3. MEND marks:
4. Default macro name length limit is:
5. MSTART is used for: