FILE fields describe bytes on datasets. Working storage describes bytes your program owns in memory—counters, tax scratch pads, echo switches, grand totals, and derived NET-PAY values. Easytrieve codes working storage on DEFINE with W for non-static fields or S for static fields. That single letter changes report behavior more than beginners expect: W fields spool onto report work files when PRINT runs; S fields stay put until the report formatter reads them. Initialization defaults numeric working storage to zero and alphabetic to blanks unless VALUE says otherwise. RESET reloads W fields at JOB, SCREEN, or SORT boundaries. Qualify with WORK: when names collide with FILE fields. This page is the comprehensive guide to declaring, initializing, referencing, and choosing between W and S for maintainable Easytrieve programs.
| Feature | W (work) | S (static) |
|---|---|---|
| Report work file spooling | Yes, when referenced in REPORT at PRINT | No spool copy per PRINT |
| Value at report format time | From spooled snapshot at PRINT | Current static storage value |
| Typical uses | Per-record rank, scratch, line-level derivations | Grand totals, constants, BAR-GRAPH |
| RESET parameter | Supported on W | See product docs for S init |
| Broadcom default recommendation | Use when spool behavior understood | Preferred default for reports |
Use DEFINE with W or S as start location instead of numeric file position. Follow with length, type, optional decimals, MASK, VALUE, HEADING, RESET, OCCURS, and VARYING as needed. In Library section after any FILE, DEFINE keyword may be omitted for working storage following FILE definitions. Inside JOB activities, DEFINE is mandatory before reference.
12345678FILE PERSNL FB(150 1800) NAME 17 20 A GROSS 94 4 P 2 DEFINE WS-COUNT W 5 N RESET VALUE 0 DEFINE GRAND-TOT S 9 P 2 DEFINE ECHO-SW W 1 A VALUE 'Y' RESET DEFINE NET-SCRATCH W 7 P 2
Without VALUE, numeric W and S fields start at zero; alphabetic A and M start at blanks. VALUE sets explicit initial content at allocation—tax rates, default flags, month names. VARYING fields default to zero length unless VALUE specifies otherwise. FILE fields are not initialized by VALUE—they receive dataset bytes on READ.
123DEFINE TAX-RATE W 3 P 4 VALUE 0.0825 DEFINE DFLT-MON W 10 A VALUE 'JANUARY' DEFINE WS-FLAGS W 2 B VALUE X'0000'
RESET on W working storage returns the field to its initial state—including VALUE—when a JOB, SCREEN, or SORT activity begins. Multiple RESET fields reset in definition order. RESET does not run on overlay redefinitions. Exception: RESET is not performed during spooled report printing—only at activity boundaries. Pair RESET with counters and echo switches that must restart each job pass.
Working storage field names must be unique within working storage. File field names must be unique within each FILE. The same name on FILE and working storage requires qualification: WORK:COUNT versus PERSNL:COUNT. Spaces around colon are flexible per Broadcom syntax.
123IF WORK:STATUS EQ DFLT-CODE DISPLAY 'WS STATUS MATCH' END-IF
Library section definitions are global to the program—standard for production layouts. Activity definitions suit one-off scratch fields used only in that JOB—late-defined TEMP-TOT before a special pass. Activity DEFINE must precede reference in source order.
12345JOB INPUT PERSNL DEFINE TEMP-HOLD W 7 P 2 TEMP-HOLD = GROSS * 2 DISPLAY TEMP-HOLD END-JOB
Working storage participates fully in expressions, IF conditions, MOVE, DISPLAY, and SORT keys when referenced. Quantitative fields need decimal positions for signed math and automatic SUM on reports. Use packed P for money; binary B for counters when shop standards allow.
LINE and TITLE statements may list W or S fields alongside FILE fields. MASK and HEADING on DEFINE apply at print. Remember W spooling: compute before PRINT. S grand totals accumulate across JOB INPUT loop then appear on control break LINE statements.
OCCURS and INDEX on DEFINE create working storage arrays—month name tables, rate tiers. Subscripts and INDEX displacement select elements. RESET with OCCURS has byte limit rules per Broadcom—see array processing documentation.
12DEFINE MONTH-TABLE W 108 A OCCURS 12 INDEX MON-IX DEFINE MON-IX W 2 N
Easytrieve programs call subprograms with parameters per shop linker conventions; working storage remains private to this program unless passed explicitly. Do not confuse W fields with COBOL LINKAGE SECTION—different language, similar naming confusion for migrants.
Working storage consumes region below the line. Extremely large OCCURS arrays or thousands of W fields can pressure small region JCL. Shops monitor GETMAIN failures in compile and run listings. Keep working storage lean—define only fields you reference.
Working storage is your desk while you read homework papers from a FILE folder. W notes get photocopied onto each report card when you decide that card goes in the report pile. S notes stay on your desk until the report is finally printed—you look at the latest number then. VALUE is what you write on a fresh sticky note before starting. RESET clears sticky notes back to what VALUE said when a new homework session starts.
1. DEFINE location W establishes:
2. S on DEFINE means:
3. Numeric W fields without VALUE initialize to:
4. RESET on W fields runs when:
5. Ambiguous field name uses qualifier: