Easytrieve Working Storage

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.

Progress0 of 0 lessons

W and S — Two Storage Classes

Non-static W versus static S working storage
FeatureW (work)S (static)
Report work file spoolingYes, when referenced in REPORT at PRINTNo spool copy per PRINT
Value at report format timeFrom spooled snapshot at PRINTCurrent static storage value
Typical usesPer-record rank, scratch, line-level derivationsGrand totals, constants, BAR-GRAPH
RESET parameterSupported on WSee product docs for S init
Broadcom default recommendationUse when spool behavior understoodPreferred default for reports

Declaring Working Storage

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.

text
1
2
3
4
5
6
7
8
FILE 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

Initialization — VALUE and Defaults

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.

text
1
2
3
DEFINE 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 Lifecycle

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.

WORK Qualifier

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.

text
1
2
3
IF WORK:STATUS EQ DFLT-CODE DISPLAY 'WS STATUS MATCH' END-IF

DEFINE in Library vs Activity

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.

text
1
2
3
4
5
JOB INPUT PERSNL DEFINE TEMP-HOLD W 7 P 2 TEMP-HOLD = GROSS * 2 DISPLAY TEMP-HOLD END-JOB

Working Storage in Arithmetic and IF

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.

Working Storage on Reports

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.

Arrays and Indexes in Working Storage

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.

text
1
2
DEFINE MONTH-TABLE W 108 A OCCURS 12 INDEX MON-IX DEFINE MON-IX W 2 N

Working Storage vs Linkage

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.

Memory and Field Count Practical Limits

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.

Common Mistakes

  1. Using W for grand totals then SORTing spooled report.
  2. Forgetting WORK: qualifier when names collide.
  3. Activity DEFINE after first reference—compile error.
  4. VALUE on FILE field expecting initialization before READ.
  5. RESET expected during report formatting pass.
  6. Unsigned numeric W field holding negative derived values.

Explain It Like I'm Five

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.

Exercises

  1. Define WS-COUNT W with VALUE 0 and RESET; increment in JOB INPUT.
  2. Define GRAND-TOT S; add GROSS each record; print on final break.
  3. Write qualified reference WORK:FLD when FLD exists on FILE.
  4. Define scratch field inside JOB activity before use.
  5. Explain when Broadcom recommends S over W for a new report.

Quiz

Test Your Knowledge

1. DEFINE location W establishes:

  • Non-static working storage
  • Write-only file
  • Wide Unicode
  • Week field

2. S on DEFINE means:

  • Static working storage not spooled per PRINT
  • String type
  • Sort key
  • Screen row

3. Numeric W fields without VALUE initialize to:

  • Zeros
  • Spaces
  • HIGH-VALUES
  • LOW-VALUES

4. RESET on W fields runs when:

  • JOB SCREEN or SORT activity starts
  • Every READ
  • Each PRINT line
  • Compile time

5. Ambiguous field name uses qualifier:

  • WORK:field-name
  • JCL:field-name
  • REPORT:field-name
  • MACRO:field-name
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 DEFINE W S VALUE RESET WORK qualifierSources: Broadcom Easytrieve 11.6 DEFINE Statement, Define Files and Fields, Getting StartedApplies to: Easytrieve W and S working storage