Initialization is what a field contains before your logic trusts it—and what it returns to when a new processing phase begins. Easytrieve does not use a separate INITIAL keyword on DEFINE like some languages use INITIAL IS. Instead, initialization comes from product defaults: numeric working storage to zero, alphabetic to blanks; from VALUE on DEFINE for explicit starting literals; from RESET on W fields that restore initial state when JOB, SCREEN, or SORT starts; and from runtime MOVE or assignment in activity logic that clears buffers before PUT or loops. FILE fields initialize from whatever bytes the dataset contains on READ—garbage in means garbage out until validated. Beginners confuse compile-time VALUE with per-record clearing inside JOB—they are different lifecycles. This page unifies initialization concepts so you choose the right mechanism for counters, flags, new VSAM files, and multi-job programs in one source deck.
| Mechanism | Applies to | When it runs |
|---|---|---|
| Default zeros/blanks | W S numeric and A | Field allocation |
| VALUE on DEFINE | Working storage | Allocation with explicit literal |
| RESET on DEFINE | W fields only | Each JOB SCREEN SORT start |
| READ from file | FILE fields | Each record read |
| MOVE / assignment in JOB | Any defined field | When statement executes |
Without VALUE, numeric working storage fields contain zero at start. Alphabetic W and S fields contain spaces. Predictable for counters WS-COUNT W 4 N starting at zero before loop increments. Do not assume FILE fields are zero on first READ—uninitialized file data may hold LOW-VALUES or prior run residue until validated with IF NUMERIC or FLDCHK debug.
123DEFINE WS-COUNT W 4 N DEFINE WS-NAME W 16 A * At start: WS-COUNT = 0, WS-NAME = spaces
VALUE sets initial state at allocation—DEFINE ECHO-SW W 1 A VALUE 'Y' in online examples, DEFINE YEAR W 4 N VALUE 1999 in training manual. Becomes baseline RESET restores. See VALUE page for literal forms and length rules. Use when default zero or blank is wrong for business default flag or constant rate.
RESET on W field definition tells product to restore field to initial value—including VALUE if present—whenever JOB, SCREEN, or SORT activity executes. Useful for counters and flags that must start fresh each job pass in multi-activity programs. RESET with OCCURS allowed on array W fields. RESET not valid on overlay redefined fields. Multiple RESET fields reset in definition order.
123456789DEFINE REC-COUNT W 6 N VALUE 0 RESET DEFINE ECHO-SW W 1 A VALUE 'Y' RESET JOB INPUT FILE1 REC-COUNT = REC-COUNT + 1 JOB INPUT FILE2 * REC-COUNT restored to 0 by RESET at JOB start REC-COUNT = REC-COUNT + 1
Second JOB sees counter zero again because RESET fired at JOB boundary. Without RESET, counter would accumulate across jobs in same run—sometimes desired, often bug.
Broadcom notes RESET is not performed during printing of spooled reports when W fields used in report processing. Sequenced reports spool work files—non-static W accumulators may hold values from pre-sequence processing that differ from values at format time. Static S fields or careful job design avoids wrong averages. Read Getting Started warning on W-type fields in sequenced reports before building scratch totals.
FILE fields receive record bytes on READ or PUT context. New VSAM file initialization job sets CUST-ID = 0 and NEXT-ID = 1 then PUT CUST—assignment in JOB, not VALUE on FILE DEFINE. First record seeds control file. Batch programs reading production extracts inherit whatever upstream wrote—validate before arithmetic.
12345JOB INPUT NULL CUST-ID = 0 NEXT-ID = 1 PUT CUST STOP
Activity logic clears buffers before building output records. MOVE SPACE TO alpha fields, zero patterns to numeric groups. Example from manuals: initialize numeric and alpha fields before concatenation or PUT. Runs every time statement executes—not once at compile like VALUE. Use inside PROC before writing trailer or after reading header.
1234INIT-RECORD. PROC MOVE SPACE TO OUT-NAME OUT-ADDR WS-AMT = 0 END-PROC
Varying alphanumeric default is zero-length string until VALUE supplies default content and length. Fixed-length beginners encounter this when advancing to variable-length name fields in online programs.
Initialization sets starting value. Validation checks after READ—IF ACCT NUMERIC, IF DATEVAL YES. LOW-VALUES in file numeric fields pass initialization concept but fail validation—use FLDCHK in PARM DEBUG during test. Do not conflate initialized working storage with clean file data.
Initialization is setting up toys before play. Empty number toys start at zero, letter toys start blank. VALUE puts a sticker saying start at five instead. RESET cleans the toy back to the sticker number when a new game round starts. File toys come filled from the delivery box— you do not choose their starting stuff from home stickers.
1. Alphabetic W field without VALUE initializes to:
2. RESET on W field returns field to:
3. RESET applies to:
4. FILE field bytes on first READ come from:
5. RESET with OCCURS arrays: