Scope answers two questions: which storage does this name bind to, and from where in the source can I reference it? Easytrieve does not offer COBOL-style nested scopes or local PROC parameters in classic batch programs. Instead, scope comes from where DEFINE appears—library section versus activity—and from qualifiers that pick FILE versus WORK when names collide. Library FILE fields are visible program-wide. Activity DEFINE must precede use in source order. Report procedures see active files and working storage under special SUMFILE rules for control fields. Beginners who ignore scope assign to the wrong STATUS buffer, define TEMP fields too late in a JOB, or reference LEVEL outside report context. This page explains visibility rules, qualification, PROC reach, multi-file programs, and practical patterns for clean name boundaries.
The library section is the default global dictionary. FILE statements and following field lines define input and output record variables visible to every JOB, SORT, SCREEN, and PROC unless a more specific rule overrides behavior. DEFINE WS-TOTAL W 9 P 2 in the library is visible in all activities. This is the closest Easytrieve comes to global scope—one name, one allocation for the run.
12345678910111213FILE PERSNL FB(150 1800) NAME 17 20 A GROSS 94 4 P 2 DEFINE GRAND-TOT S 9 P 2 JOB INPUT PERSNL GRAND-TOT = GRAND-TOT + GROSS END-JOB JOB INPUT BONUS-FILE GRAND-TOT = GRAND-TOT + BONUS-AMT END-JOB
GRAND-TOT persists across both JOB activities because library working storage scope spans the program. Confirm that is intended—sometimes a RESET W field per JOB is safer.
DEFINE inside a JOB, SORT, or SCREEN activity creates variables whose declarations must appear before first reference in that activity source. The DEFINE keyword is mandatory. These fields still live in the program dictionary but teach beginners to treat them as local intent—used only in that activity block. Defining TEMP-HOLD after first use causes compile errors.
1234567JOB INPUT PERSNL DEFINE TEMP-HOLD W 7 P 2 TEMP-HOLD = GROSS * 1.5 IF TEMP-HOLD GT LIMIT DISPLAY NAME TEMP-HOLD END-IF END-JOB
Each FILE has its own field namespace. NAME on PERSNL and NAME on BONUS-FILE are different variables unless you synchronize them intentionally. When both files are active in one JOB, qualify: PERSNL:NAME versus BONUS:NAME. Unqualified NAME resolves using library search rules—current FILE context and WORK—and errors if ambiguous.
| Reference | Resolves to | When |
|---|---|---|
| GROSS | Field on current FILE after last FILE stmt | Unique name in context |
| PERSNL:GROSS | GROSS on PERSNL always | Multiple files active |
| WORK:COUNT | Working storage COUNT | COUNT also on a FILE |
| GRAND-TOT | Library S or W field | Defined in library DEFINE |
WORK: limits the name to working storage explicitly. Use it in maintenance-sensitive code even when the compiler could infer the reference—auditors see intent immediately. Spacing around the colon is flexible per Broadcom syntax examples.
123456789101112FILE PERSNL FB(150 1800) STATUS 120 1 A DEFINE STATUS W 1 A VALUE 'N' RESET JOB INPUT PERSNL IF WORK:STATUS EQ 'Y' DISPLAY 'PROCESS FLAG ON' END-IF IF PERSNL:STATUS EQ 'A' DISPLAY 'ACTIVE EMPLOYEE ON FILE' END-IF
Overlay variables share parent scope. HIRE-MM on DATE-OF-HIRE is visible wherever the parent file buffer is active. Overlays do not create a separate WORK allocation—they are alternate names for byte ranges inside FILE or parent DEFINE storage.
PROCs do not declare separate variable dictionaries. PERFORM CALC-NET sees library fields and any activity DEFINE already processed above the PERFORM call. Classic Easytrieve PROCs lack formal parameters—use working storage fields as implicit inputs and outputs. Scope discipline means naming WS-IN and WS-OUT clearly and documenting which PROC mutates which globals.
Report procedures reference fields in active files and working storage. When referencing CONTROL or total fields, Broadcom uses SUMFILE data automatically so totals match printed reports. LEVEL and BREAK-LEVEL are meaningful in report PROC scope during control report formatting—not generic batch JOB scope. DISPLAY in report PROC writes only to the associated report.
12345BEFORE-BREAK. PROC IF DEPT HIGHEST-BREAK DISPLAY 'BREAKING ON DEPT' END-IF END-PROC
SQL INCLUDE brings host variables into program scope. NULLABLE generates indicator variables tied to nullable columns—IF PHONE NULL tests indicator scope, not random bytes. Manual indicators must be paired in scope with their host variables in every SELECT INTO list they accompany.
Macros expand at compile time, injecting DEFINE and logic into the including program. Expanded fields obey the same scope rules as handwritten source. Macro parameters using & names are compile-time text substitution—not runtime variables. Beginners should not confuse &MACVAR with W fields.
Scope is which box a label points to and which rooms can see that label. Library labels are on the main hallway—everyone can use them. Activity labels must be put on the box before you use them in that room. If two boxes have the same sticker, you write the room name on the sticker too: PERSNL:NAME or WORK:NAME.
1. Library section DEFINE for working storage is visible:
2. DEFINE inside a JOB activity requires:
3. WORK: qualifier scope means:
4. Field names must be unique:
5. Report procedures can reference: