Easytrieve Array Initialization

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.

Progress0 of 0 lessons

Default Initialization Without VALUE

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.

Default initial content by type
DEFINE typeInitial value without VALUEArray note
A alphabeticSpacesEach occurrence blank-filled
N zoned numericZeroEach occurrence zero
P packedZeroPacked zero in each slot
B binaryZeroBinary zero per element

VALUE on DEFINE

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.

text
1
2
3
4
5
6
7
8
9
10
11
DEFINE 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 and Activity Boundaries

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.

Runtime Load with MOVE Loops

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.

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

Loading From TABLE Statement

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.

Initializing FILE Record Arrays

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.

Clearing and Reinitializing Mid-Job

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.

INIT and START Procedures

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.

Initialization Versus Accumulation

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.

Common Initialization Mistakes

  • Assuming FILE arrays start at zero without reading a record.
  • Forgetting to set INDEX before MOVE into element inside load loop.
  • RESET on accumulator arrays cleared at wrong time.
  • Loading twelve elements when OCCURS is twelve but only COUNT is valid—downstream reads empty slots.
  • Using HIGH-VALUES to mean uninitialized—compare explicitly in IF when needed.

Explain It Like I'm Five

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.

Exercises

  1. Write INIT PROC loop that sets OCCURS 10 numeric array to zero explicitly.
  2. Declare INDEX with VALUE 1 and explain why.
  3. Describe when RESET helps versus hurts on a totals array.
  4. Load five FILE line items into working storage array with COUNT limit.
  5. List default initial value for type A versus type P OCCURS elements.

Quiz

Test Your Knowledge

1. Numeric OCCURS elements without VALUE initialize to:

  • Zeros
  • Spaces
  • HIGH-VALUES
  • Unpredictable

2. To load different values into each array slot at compile time you typically:

  • Use MOVE in INIT or a load loop after JOB starts
  • Only VALUE on whole OCCURS group
  • JCL DD only
  • Cannot differ per element

3. RESET on a W array field with VALUE:

  • Returns elements to VALUE when JOB or SCREEN starts
  • Clears every PRINT line
  • Runs at compile
  • Disables OCCURS

4. Clearing an entire array to spaces quickly uses:

  • MOVE SPACES to group or loop with INDEX
  • DELETE FILE
  • SORT only
  • END-PROC

5. Loading arrays from a sequential file usually involves:

  • READ or GET in a loop with INDEX increment
  • REPORT TITLE
  • GOTO SCREEN
  • LINK without FILE
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 VALUE RESET and working storage initializationSources: Broadcom Easytrieve 11.6 Language Reference DEFINE VALUE RESET, Working StorageApplies to: Easytrieve array initialization patterns