Easytrieve Variable Initialization

A variable in Easytrieve is only useful after it holds a trustworthy value. Initialization is the umbrella term for every way that happens: product defaults when working storage allocates, explicit VALUE literals on DEFINE, RESET that snaps W fields back at JOB boundaries, bytes loaded from datasets into FILE buffers, and runtime assignment you code in PROCs or JOB logic. Beginners often treat all variables the same and wonder why WS-COUNT starts at zero while GROSS on the input file contains garbage on the first READ. That difference is initialization by variable family. W and S working storage variables get predictable compile-time defaults. FILE variables inherit whatever upstream systems wrote to the tape or DASD. S variables persist unless you clear them. W variables with RESET restart each JOB. This page teaches initialization from the variables chapter perspective so you pick the right starting strategy for counters, flags, extract records, SQL host variables, and multi-JOB programs in one source deck.

Progress0 of 0 lessons

Initialization by Variable Family

Starting values depend on where the variable lives
Variable familyDefault at allocationCommon overrides
W working storageNumeric zero, alphabetic blanksVALUE, RESET, MOVE in JOB
S static storageSame as W at program startVALUE at DEFINE; manual clear between JOBs
FILE record fieldUndefined until READ or PUT contextAssignment before PUT; validation after READ
Overlay subfieldFollows parent buffer contentInitialize parent or subfield together
SQL host variableDepends on prior fetch or assignmentIndicator pair; NULL test after SELECT
Activity DEFINESame W rules after DEFINE lineMust appear before first reference

W Variable Initialization

W is non-static working storage—the workbench where counters, scratch totals, and per-record flags live during JOB processing. When you code DEFINE WS-RECS W 6 N without VALUE, the product allocates six numeric bytes initialized to zero before the first JOB line runs. Alphabetic W fields such as DEFINE WS-FLAG W 1 A start as a single blank. These defaults are reliable for loop counters and empty-string tests. When the business needs a different starting point—echo switch defaulting to Y, tax rate seeded at 8.25—add VALUE on the DEFINE line. VALUE becomes the baseline that RESET restores when you also code RESET and want each JOB to restart from that literal instead of carrying forward accumulated totals from a prior JOB in the same run.

text
1
2
3
4
5
6
7
DEFINE WS-RECS W 6 N DEFINE ECHO-SW W 1 A VALUE 'Y' RESET DEFINE TAX-RATE W 3 P 2 VALUE 8.25 JOB INPUT PAYROLL WS-RECS = WS-RECS + 1 END-JOB

WS-RECS accumulates across the JOB because no RESET is coded. ECHO-SW returns to Y at each JOB, SCREEN, or SORT start because RESET is present. TAX-RATE holds 8.25 until assignment changes it; RESET would restore 8.25 at the next activity boundary if you added RESET to that DEFINE.

S Variable Initialization

S static storage variables initialize with the same default rules at program start—zeros for numeric, blanks for alphabetic. The critical difference is lifetime: S fields do not participate in RESET the way W fields do unless you explicitly assign zero or use a pattern that clears them in JOB logic. Library DEFINE GRAND-TOT S 9 P 2 starts at zero once per program execution and keeps whatever value your JOB activities accumulate until you overwrite it. That makes S ideal for cross-JOB program totals and report accumulators that must survive from one JOB INPUT block to the next. It also makes S dangerous when you expected a fresh counter each JOB but forgot to clear it manually.

text
1
2
3
4
5
6
7
8
9
10
11
12
13
DEFINE GRAND-TOT S 9 P 2 DEFINE JOB-TOT W 9 P 2 VALUE 0 RESET JOB INPUT FILE-A JOB-TOT = JOB-TOT + AMOUNT GRAND-TOT = GRAND-TOT + AMOUNT END-JOB JOB INPUT FILE-B * JOB-TOT back to 0; GRAND-TOT still holds FILE-A sum JOB-TOT = JOB-TOT + AMOUNT GRAND-TOT = GRAND-TOT + AMOUNT END-JOB

FILE Variable Initialization

FILE variables are not initialized by DEFINE defaults. They are views into the current input or output record buffer at the byte positions you declared in the library section. When JOB INPUT PERSNL reads a record, every FILE field on PERSNL receives the bytes from that physical record. If upstream ETL left LOW-VALUES in a packed amount field, your GROSS variable reflects those bytes immediately—there is no automatic zeroing step. Output FILE variables behave similarly: before PUT, you must assign or MOVE values into the buffer fields you want written. Seeding a new VSAM control file uses an initialization JOB that assigns CUST-ID = 0, NEXT-ID = 1, then PUT CUST—not VALUE on the FILE definition.

text
1
2
3
4
5
6
7
8
9
10
FILE CUST VS CUST-ID 1 4 P 0 NEXT-ID 5 4 P 0 JOB INPUT NULL CUST-ID = 0 NEXT-ID = 1 PUT CUST STOP END-JOB

RESET as Initialization Trigger

RESET is not a separate variable type—it is a DEFINE attribute on W fields that turns activity boundaries into re-initialization events. When JOB INPUT FILE2 starts, every W field with RESET returns to its initial state: VALUE literal if present, otherwise type default. Broadcom documents that RESET does not run during printing of spooled reports for W fields referenced in report processing, which matters when you build sequenced reports with scratch W totals. For batch beginners, the practical rule is simple: put RESET on W counters and flags that must restart each JOB; omit RESET on W fields that should accumulate across JOBs in the same run; use S when accumulators must survive report spooling semantics.

Activity DEFINE Initialization

DEFINE inside a JOB activity creates a variable that must be declared before first reference in source order. Once declared, TEMP-HOLD W 7 P 2 receives the same default zero as a library W field at the moment the DEFINE is processed—typically at JOB start before executable statements run. Activity DEFINE does not create a separate initialization universe; it extends the working storage dictionary under stricter ordering rules. Beginners who define TEMP after the IF that references it get compile errors, not uninitialized variables.

text
1
2
3
4
5
6
7
JOB INPUT SALES DEFINE HOLD-AMT W 7 P 2 HOLD-AMT = GROSS * 1.10 IF HOLD-AMT GT LIMIT DISPLAY ACCT HOLD-AMT END-IF END-JOB

Runtime Assignment Initialization

VALUE and defaults handle program-start and RESET boundaries. Runtime assignment handles per-record and per-iteration initialization inside PROCs. Before building an output trailer, a PROC might MOVE SPACE TO alpha name fields and set numeric totals to zero so leftover bytes from a prior PUT do not leak into the next record. This runs every time the PROC executes—not once at compile time. Contrast with VALUE: VALUE sets the baseline once at allocation; MOVE SPACE in INIT-RECORD. PROC clears the buffer on every call. Both are initialization, but at different lifecycles.

SQL Host Variable Initialization

SQL INCLUDE brings host variables into the same program dictionary as DEFINE fields. Before SELECT INTO, indicators and host fields should be in a known state. After fetch, test the NULL indicator before arithmetic on nullable columns. Uninitialized indicator bytes treated as valid data cause subtle production bugs that compile cleanly. Pair each nullable host variable with its indicator in the INTO list and branch on NULL before assigning to working storage totals.

VARYING and OCCURS Initial State

Varying alphanumeric fields default to zero-length until VALUE supplies content and length. OCCURS array W fields with RESET restore every element to initial VALUE or default when the activity starts. RESET is allowed on OCCURS W arrays but not on overlay redefined fields—attempting RESET on an overlay is a documentation violation beginners hit when copying COBOL REDEFINES patterns too literally.

Initialization vs Validation

Initialization sets a starting value you trust for logic. Validation confirms FILE data after READ is acceptable—IF ACCT NUMERIC, IF DATEVAL YES on DATEVAL-FLAG. A FILE numeric field can be initialized in the sense that READ loaded bytes, yet still fail validation because upstream sent non-numeric content. Enable FLDCHK in PARM DEBUG during test to surface field content problems. Do not assume initialized working storage implies clean file variables.

Choosing an Initialization Strategy

  1. Counter starting at zero each JOB—DEFINE W with VALUE 0 RESET.
  2. Program-wide total across JOBs—DEFINE S without RESET; clear manually if needed.
  3. Business default flag at compile—VALUE Y on W or S.
  4. Output record blank slate each iteration—PROC with MOVE SPACE and zero assignment.
  5. New dataset seed record—init JOB with assignment and PUT.
  6. FILE input—validate after READ; never rely on VALUE for FILE layout fields.

Common Initialization Mistakes

  • Expecting FILE GROSS to be zero before first READ.
  • Using W accumulator with RESET in sequenced report without reading spool timing notes.
  • Forgetting RESET when second JOB should restart a W counter.
  • Assuming activity DEFINE can appear after first use.
  • Using S for per-JOB scratch without clearing—value leaks to next JOB.
  • Arithmetic on SQL host variable before NULL indicator test.

Explain It Like I'm Five

Variables are boxes with name stickers. W boxes for quick games start empty with zero marbles or blank paper. You can put a note on the box saying start with five marbles—that is VALUE. RESET cleans the box back to the note when a new game round starts. S boxes remember totals for the whole party unless you empty them yourself. File boxes arrive full from the delivery truck—you open them and see what someone else packed. You do not get to pick the starting marbles for file boxes from your own sticker notes.

Exercises

  1. Define WS-COUNT W 4 N with VALUE 0 and RESET; trace value through two JOB activities.
  2. Write init JOB seeding a control file with two numeric fields.
  3. Explain why GRAND-TOT S persists but JOB-TOT W RESET does not across JOBs.
  4. Add PROC that clears output alpha fields before each PUT.
  5. List default starting values for W 10 A and W 5 N without VALUE.

Quiz

Test Your Knowledge

1. Numeric W variable without VALUE initializes to:

  • Zero
  • Spaces
  • HIGH-VALUES
  • Random bytes

2. FILE variable GROSS gets its first value when:

  • A READ or automatic JOB INPUT loads record bytes into the buffer
  • VALUE on DEFINE runs at compile time
  • RESET fires at JOB start
  • The linker runs

3. RESET on a W field restores value when:

  • JOB, SCREEN, or SORT activity starts
  • Every PRINT line
  • Only at compile
  • END-PROC only

4. Activity DEFINE TEMP W 5 N before first use:

  • Gets default zero like library W fields
  • Stays HIGH-VALUES until MOVE
  • Inherits FILE buffer
  • Requires JCL PARM

5. S static field without RESET across JOBs:

  • Keeps accumulated value from prior JOB unless explicitly cleared
  • Always returns to zero at each JOB
  • Exists only during compile
  • Cannot be assigned
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 VALUE RESET default initialization for W and S variablesSources: Broadcom Easytrieve 11.6 DEFINE Statement, Define Files and Fields, Getting StartedApplies to: Easytrieve variable initialization across W S and FILE families