An Easytrieve shop can have fifty reports that define the same customer layout, title lines, and total fields. A macro keeps that repeated source in one member and expands it into each program at compile time. That makes the report code shorter, but it also means a shared macro must be tested like shared production code.
What is an Easytrieve macro?
An Easytrieve macro is reusable source text. It can define file fields, report headings, common calculations, selection rules, or repeated report code. The macro is expanded before the Easytrieve program runs, so it is not the same as a runtime CALL.
Broadcom notes that Easytrieve macros are invoked with a percent sign, such as %MACRONAME. A CALL statement is used for COBOL or assembler subprograms, not for invoking Easytrieve macros.
Macro, copybook, and CALL at a glance
| Item | When it is used | Typical purpose |
|---|---|---|
| Easytrieve macro | Compile time | Expands reusable Easytrieve source with optional parameters. |
| Copy/include member | Compile time | Brings in shared source text without macro substitution logic. |
CALL |
Run time | Runs a COBOL, assembler, or other external subprogram. |
Basic macro structure
A macro usually starts with a prototype statement. The body contains the source lines that will be expanded. Parameter names in the body use an ampersand prefix. The exact coding style can vary by site and product release, but the idea is the same: pass values into reusable source text.
MACRO FNAME PREFIX
FILE &FNAME
&PREFIX-ID 1 8 N
&PREFIX-NAME 9 20 A
&PREFIX-AMT 29 7 P 2
When the macro is invoked, Easytrieve substitutes the values from the invocation line into the macro body.
%CUSTLAY CUSTIN CUST
After expansion, the generated source acts as if the field definitions had been typed directly into the program.
How ampersand substitution works
Within the body of a macro, an ampersand marks a parameter substitution word. Broadcom notes that parameter substitution words must match their prototype names, except for the leading ampersand. If the prototype has PREFIX, the macro body uses &PREFIX.
This is where many small compile errors start. A misspelled parameter name, a missing delimiter, or an ampersand placed in the wrong part of the macro can make the expanded source invalid.
How to invoke a macro
Invoke a macro with the percent sign followed by the macro name. Broadcom is explicit on this point: macros use %macroname, while CALL is for subprograms.
FILE CUSTOMER-FILE FB(80 0)
%CUSTLAY CUSTOMER-FILE CUST
JOB INPUT CUSTOMER-FILE
IF CUST-AMT > 0
DISPLAY CUST-ID CUST-NAME CUST-AMT
END-IF
The macro expansion happens before the report runs. If the generated field name or file name is wrong, fix the macro invocation or the macro body, then recompile.
Where PANDD and MACDDN fit
Stored macros usually live in a macro library. Broadcom documents PANDD as the default DD name used to point to the PDS where macros reside when MACDDN is set to PANDD. Your site may use a different DD name, so check the Easytrieve option file and compile JCL.
//PANDD DD DISP=SHR,DSN=SITE.EASYTRIEVE.MACLIB
//SYSIN DD DISP=SHR,DSN=SITE.EASYTRIEVE.SOURCE(REPT001)
If the macro member cannot be found, verify the macro library DD statement, member name, and option-table setting before changing the program logic.
Good uses for Easytrieve macros
- Shared file layouts used by several reports.
- Standard report title and heading blocks.
- Common date, amount, and code-description formatting.
- Reusable selection code that is stable and well tested.
- Report skeletons used by a team with consistent naming rules.
When not to use a macro
Do not hide business rules inside a macro just to make the program shorter. If the rule changes often or needs runtime decisions, keep it visible in the program or move it to a callable routine where that fits the design.
Also avoid one large macro that builds most of the report. That makes compile errors harder to trace and turns a small library change into a risky shared-code release.
Common mistakes
Calling a macro with CALL
CALL is for subprograms. Use the percent-sign form to invoke a macro.
Changing a shared macro without impact review
A macro can be used by many jobs. Search the source library for every %MACRONAME reference before changing a shared member.
Forgetting the macro library DD
If the compile cannot resolve the macro, check PANDD, MACDDN, and the macro member name first.
Review checklist
- Confirm the macro name and invocation line use the percent sign.
- Check that every ampersand parameter has a matching prototype name.
- Verify
PANDDor the site macro DD points to the correct library. - Review the expanded compile listing when debugging macro-generated code.
- Search for all users before changing a shared macro.
- Keep comments near the macro prototype so users know the expected parameters.
Related Mainframe Forum guides
For connected Easytrieve topics, read Easytrieve Macro Sample Program, Creating Easytrieve Macros, Easytrieve Library, Easytrieve Basic Reporting, Easytrieve Basic Conditions, and Easytrieve Basic Report Calculation.
External references
Broadcom documents how to invoke Easytrieve macros, ampersand substitution in macro bodies, and PANDD and MACDDN library setup.
FAQ
How do you invoke an Easytrieve macro?
Use the percent sign followed by the macro name, such as %CUSTLAY. Do not use CALL for an Easytrieve macro.
What does an ampersand mean in an Easytrieve macro?
An ampersand marks a parameter substitution word in the macro body. The name must match a parameter on the macro prototype.
What is PANDD in Easytrieve?
PANDD is commonly used as the DD name for the macro library when the option-table MACDDN value points to it.
Are Easytrieve macros runtime routines?
No. Macros expand into source before the report runs. Runtime routines are called with statements such as CALL.
