Every variable name in Easytrieve points at bytes somewhere in the running program—static working storage, non-static working storage copied for reports, or a record buffer tied to a FILE definition. Memory is not an abstract Java heap you manage manually; the product allocates pools at program start based on your library DEFINE and FILE layouts. What confuses beginners is that two names can reference the same bytes (overlays), two names can look similar but live in different buffers (PERSNL:NAME versus BONUS:NAME), and W versus S working storage diverges at PRINT time when W copies to report work files while S stays live. Misunderstanding memory causes classic bugs: updating an overlay while thinking you have independent storage, using W scratch totals in sequenced reports then wondering why printed averages disagree with post-PRINT assignments, or qualifying FILE names too late after switching active file context. This page explains the physical model behind Easytrieve variables so scope, lifetime, and initialization advice from sibling pages make sense.
| Storage region | Variables using it | Key behavior |
|---|---|---|
| Static working storage (S) | DEFINE ... S fields | One allocation per run; live through report format |
| Non-static working storage (W) | DEFINE ... W fields | Copied to report work file at PRINT when used in reports |
| FILE record buffers | FILE layout field names | Per-FILE buffer; refreshed on READ/PUT |
| Overlay subranges | Fields defined on parent positions | Alias same bytes as parent—no extra allocation |
| Report work files | Snapshot of W at PRINT | Used during spooled report sequencing and format |
S fields allocate in static working storage when the program loads. GRAND-TOT S 9 P 2 occupies packed decimal bytes for the entire step regardless of how many JOB activities execute. Assignments update those bytes in place. Report formatting reads S fields directly from static storage when LINE or SUM references them, so totals that accumulate in S during JOB processing match what the report writer sees at format time—assuming you understand when PRINT fires relative to your assignments. Use S for program totals, control-break accumulators referenced from report PROCs, and values that must stay coherent across spooled report phases.
123456DEFINE GRAND-GROSS S 11 P 2 JOB INPUT PAYROLL GRAND-GROSS = GRAND-GROSS + GROSS PRINT PAY-RPT END-JOB
W fields allocate in non-static working storage. During ordinary batch JOB logic, W behaves like S—you assign and read the same bytes. The divergence appears when variables participate in report processing. Broadcom states W fields copy to report work files when PRINT selects records. Later changes to W in JOB logic may not match bytes already captured for spooled report formatting, while S updates remain visible. Sequenced reports that spool work files before final printing amplify this timing gap. Beginners building scratch calculations on the same PRINT line should prefer S when the report must see live totals, or design JOB order so W assignments complete before PRINT captures them.
12345678910DEFINE SCRATCH-W W 7 P 2 DEFINE SCRATCH-S S 7 P 2 JOB INPUT FILE1 SCRATCH-W = GROSS * 0.10 SCRATCH-S = GROSS * 0.10 PRINT TAX-RPT SCRATCH-W = SCRATCH-W + 1 SCRATCH-S = SCRATCH-S + 1 END-JOB
Understand which field the report writer read at PRINT versus what DISPLAY after PRINT shows—W snapshot timing may differ from S live value depending on report options and sequencing.
Each FILE definition owns a record buffer sized to the file record length in your declaration. Field lines NAME 17 20 A and GROSS 94 4 P 2 are offsets into that buffer—not separate heap objects. READ loads dataset bytes into the buffer; assignment to GROSS changes those buffer bytes before PUT on output files. Multiple FILE definitions mean multiple buffers. When JOB logic activates more than one file, qualify references: PERSNL:GROSS versus BONUS:GROSS. Unqualified GROSS resolves using current file context from the last FILE statement or automatic rules—ambiguous names are compile or runtime errors depending on situation.
1234567891011FILE PERSNL FB(150 1800) NAME 17 20 A GROSS 94 4 P 2 FILE BONUS FB(80 800) NAME 1 20 A AMOUNT 21 5 P 2 JOB INPUT PERSNL DISPLAY PERSNL:NAME PERSNL:GROSS END-JOB
Overlay definitions place a second name on a byte range inside a parent field. DATE-OF-HIRE 45 8 A with HIRE-MM on DATE-OF-HIRE 1 2 A maps HIRE-MM to the first two bytes of the eight-byte parent. Assigning HIRE-MM = 03 changes parent bytes; MOVE SPACE TO DATE-OF-HIRE clears HIRE-MM as well. Overlays do not receive separate W or S allocation. RESET on overlay fields is invalid. Memory planning must treat overlay groups as one unit when initializing or validating content.
12345678DATE-OF-HIRE 45 8 A HIRE-MM ON DATE-OF-HIRE 1 2 A HIRE-DD ON DATE-OF-HIRE 3 2 A HIRE-YY ON DATE-OF-HIRE 5 4 A HIRE-MM = 06 HIRE-DD = 15 HIRE-YY = 2024
OCCURS on W or FILE fields repeats a substructure contiguously in memory. TABLE-ENTRY W 10 A OCCURS 12 allocates twelve consecutive ten-byte elements in working storage order. Subscripts select which element—you are addressing offset math within one allocation block. Changing element 3 affects adjacent layout only within that element bytes, not other variables elsewhere in the dictionary unless your subscript is wrong and stomps adjacent memory through length mistakes—a rare but severe bug when element length declarations disagree with usage.
DEFINE inside JOB adds entries to the same program dictionary and allocates working storage according to W rules. Memory is not stack-scoped like C locals—the bytes persist for the program run unless RESET clears W fields at the next activity boundary. Activity DEFINE is about visibility ordering in source, not a separate memory heap per JOB.
PERFORM CALC-NET does not push a stack frame with private variables. The PROC reads and writes the same S, W, and FILE buffers visible to the caller. Shop convention uses WS-IN and WS-OUT working storage names as implicit parameters. Two concurrent PERFORM paths are not possible in classic batch—sequential PERFORM means no re-entrancy concern—but nested PERFORM must still avoid clobbering the same scratch W names without saving/restoring in disciplined patterns.
Control fields and totals in report processing may reference SUMFILE data—Broadcom uses internal summary file buffers so CONTROL break totals match printed reports. LEVEL and BREAK-LEVEL system fields reflect report writer state, not arbitrary FILE buffer bytes. Memory for report control is managed by the report subsystem; beginners should not assume those names map to DEFINE storage you allocated manually.
All S, W, and FILE buffer allocations last for one execution of the compiled Easytrieve program step. When the step ends, memory is released. The next JCL job step—even the same source re-run—starts fresh unless you persisted values to a dataset or VSAM file. Cross-step memory sharing does not exist. Long-running online regions follow product rules for SCREEN activities but still respect program load boundaries per session documentation for your release.
Type codes affect how many bytes a name covers and how assignment moves data—packed P versus zoned N versus alphabetic A—but do not change which region owns the bytes. Binary B fields occupy two or four bytes typically; floating U and I use longer representations. Assigning a zoned value into a packed field triggers conversion rules that rewrite the same memory location with different encoding. See data type pages for encoding; this page focuses on which pool holds the bytes.
Memory is the actual box where your toy lives. S boxes sit on a shelf that stays until the party ends. W boxes get their picture taken when you print a report page—if you change the toy after the picture, the printed page might still show the old toy. File boxes are delivery crates—each file has its own crate, and reading loads toys from the truck into that crate. Overlay names are sticky labels on one section of a bigger toy—coloring one label area changes the whole toy section underneath.
1. W working storage in reports is copied to work files when:
2. Overlay field HIRE-MM on DATE-OF-HIRE shares memory because:
3. FILE variables for PERSNL and BONUS in one JOB:
4. S static storage persists for:
5. Changing parent DATE field bytes affects overlay HIRE-MM because: