Initialization answers what values array elements hold before your logic reads them. Uninitialized assumptions cause classic bugs: adding PAY-TOTAL to RATE(INDEX) when RATE still holds garbage from a prior employee, or printing blank state codes because the table never loaded. Easytrieve provides compile-time VALUE on DEFINE, automatic defaults for numeric and alphabetic types, RESET refresh at activity boundaries, and runtime MOVE loops you write in INIT procedures or at JOB start. FILE arrays initialize from the input record when READ or GET runs—not from VALUE on working storage. TABLE statement loads keyed data into product-managed tables, while OCCURS arrays often use explicit READ loops or embedded INIT MOVE tables. This page covers each mechanism, when to use which, clearing arrays between passes, and patterns from rate tables, sign arrays, and parsed token buffers beginners maintain in production payroll and finance jobs.
Broadcom rules state numeric working storage fields initialize to zero when no VALUE is specified. Alphabetic type A fields initialize to spaces. Packed P, zoned N, binary B, and other numeric types follow the numeric-zero rule. This applies to each element in an OCCURS group individually as part of the overall field allocation. Beginners can rely on zeroed amount arrays at JOB start but must still load meaningful business values before reports print. Never assume FILE record arrays are zero—the input record defines their content on each READ.
| DEFINE type | Initial value without VALUE | Array note |
|---|---|---|
| A alphabetic | Spaces | Each occurrence blank-filled |
| N zoned numeric | Zero | Each occurrence zero |
| P packed | Zero | Packed zero in each slot |
| B binary | Zero | Binary zero per element |
VALUE sets explicit initial content when the field is created. DEFINE STATUS W 1 A VALUE 'N' OCCURS 10 INDEX ST-IDX gives a uniform initial character when product rules apply VALUE across the definition. For arrays needing different compile-time constants per slot—tax rates 0.05, 0.06, 0.07—shops often use INIT procedure MOVE statements or separate small load file rather than complex VALUE syntax. VALUE on INDEX itself is common: DEFINE IDX W 2 N VALUE 1 starts loops at first occurrence.
1234567891011DEFINE TOKEN W 12 A OCCURS 20 INDEX TOK-IDX DEFINE TOK-IDX W 2 N VALUE 1 DEFINE FLAG-ARR W 1 A OCCURS 5 INDEX FL-IDX VALUE 'N' INIT. PROC FL-IDX = 1 DO WHILE FL-IDX LE 5 FLAG-ARR = 'N' FL-IDX = FL-IDX + 1 END-DO END-PROC
RESET on DEFINE causes working storage fields to return to their initial VALUE when JOB, SCREEN, or SORT activity executes—not on every READ or PRINT. Arrays used as accumulators across an entire JOB omit RESET on those fields. Arrays that must clear each time a new JOB iteration or screen cycle starts include RESET and VALUE together. Conflicts happen when AFTER-SCREEN logic expects a flag array to persist but RESET clears it at JOB restart—document RESET attributes in design specs alongside array initialization.
The most portable initialization pattern sets INDEX to 1 and loops to OCCURS maximum. Inside the loop, MOVE literal or MOVE from another field into the array element, then increment INDEX. Use this for copying FILE repeating groups into working storage, applying uniform defaults, or translating input into normalized form. Combine with IF to load only active slots when a count field says how many lines are valid on the record.
1234567JOB INPUT RATES-FILE LINE-CNT = INPUT-COUNT R-IDX = 1 DO WHILE R-IDX LE LINE-CNT MOVE FILE-RATE TO WS-RATE R-IDX = R-IDX + 1 END-DO
When reference data lives in a TABLE, LOOKUP retrieves values during processing rather than pre-filling OCCURS. Some designs TABLE-load once then COPY into OCCURS for sequential INDEX walks without repeated LOOKUP cost. Initialization phase runs TABLE load at activity start; array copy loop follows. Compare table performance tutorial before choosing TABLE versus static OCCURS for fifty-row code files.
FILE OCCURS fields receive values from the I/O buffer on READ, GET, or WRITE. Initialization means correct FILE declaration matching producer layout—not MOVE at JOB start. When writing output files, clear unused occurrences if downstream expects spaces: loop INDEX through max, MOVE SPACES to unused LINE-ITEM elements before WRITE when COUNT indicates partial fill.
Procedures that process multiple groups in one JOB may reset arrays between groups. PERFORM CLEAR-ARRAYS that loops INDEX and MOVE ZERO or SPACES. Faster when entire group MOVE is supported for your field layout. Reinitialize INDEX to 1 after clear so next loop starts at first element. Totals arrays ACCUM OCCURS 12 may zero only month slots being recomputed rather than entire array when logic partitions by quarter.
One-time setup belongs in INIT or activity START: open auxiliary files, seed random arrays, display banner constants. INIT. PROC runs once per activity invocation. Heavy table load from sequential seed file fits INIT; per-record array refresh from input belongs in JOB INPUT or BEFORE-LINE after READ. Do not reload static rate tables on every detail line—load once in INIT.
Distinguish arrays that hold constants (state codes, edit masks) from arrays that accumulate (monthly totals). Constants load in INIT and rarely change. Accumulators initialize zero at group break or JOB start then add in loops. Using RESET on accumulators clears mid-JOB totals incorrectly. Naming conventions help: WS-TAX-RATE-TBL for constants, ACCUM-MTH for running totals.
Initializing an array is putting the right toys in each box before you play. Empty number boxes start at zero; empty letter boxes start blank. If you have a list of prices to remember, you either write them on the boxes at the start of the day (VALUE or INIT MOVE) or copy them from a paper list (READ loop). If someone shakes the table and says start over (RESET), the boxes go back to what the label on the shelf says they should contain.
1. Numeric OCCURS elements without VALUE initialize to:
2. To load different values into each array slot at compile time you typically:
3. RESET on a W array field with VALUE:
4. Clearing an entire array to spaces quickly uses:
5. Loading arrays from a sequential file usually involves: