Dimensioning an array means deciding how many elements exist and how large each element is. In Easytrieve those two numbers live on DEFINE: field length and type set element size, OCCURS sets repetition count, INDEX names the subscript. A payroll tax table with fifty states might be STATE-CODE OCCURS 50 with each element ten bytes, consuming five hundred bytes in working storage. A character walk buffer uses OCCURS 80 with one-byte elements. Wrong dimensions on FILE definitions shift every following field in the record—silent data corruption until totals disagree with control counts. This page teaches size formulas, FLDMAX interaction, INDEX field sizing, nested repeating groups, alignment with copybooks, and comparison tables beginners use when translating COBOL OCCURS DEPENDING or fixed-count tables into Easytrieve Library entries.
Two independent knobs control array footprint. Element size comes from length and type on DEFINE—4 P 2 is four bytes per rate, 16 A is sixteen bytes per name. Occurrence count is the integer after OCCURS. Total contiguous storage is their product. The product applies whether location is W, S, or a byte offset on FILE. Report writers and MOVE statements see one element at a time based on INDEX; the product still reserves all slots in memory or in the record image.
| DEFINE pattern | Bytes per element | OCCURS | Total bytes |
|---|---|---|---|
| W 3 P 2 | 3 | 12 | 36 |
| W 10 A | 10 | 50 | 500 |
| W 1 A | 1 | 80 | 80 |
| W 4 N | 4 | 999 | 3,996 |
| Group 25 bytes | 25 | 8 | 200 |
Broadcom documents FLDMAX in the options table as the maximum field length. The entire OCCURS group is one field for this purpose—not one element. If FLDMAX is 32767 and your array needs 40000 bytes, compilation or generation fails until you shrink OCCURS, shrink element length, or ask operations to raise FLDMAX where policy allows. Raising FLDMAX increases memory pressure for every large field in every step—not a casual change. Document array sizing in program headers so maintainers know why OCCURS 500 was chosen instead of 501.
On FILE, start location plus total array length must match the data dictionary. Example: LINE-ITEM starts at byte 101, each occurrence is 30 bytes, OCCURS 5 spans bytes 101–250. If you declare OCCURS 4, byte 251 fields read wrong data. Cross-check against COBOL copybook OCCURS or SLIDE documentation. FB and VB records differ: on variable-length files, repeating groups usually sit in fixed portions; do not assume OCCURS extends into variable region without layout proof.
1234567FILE INVOICE FB(280 2800) INV-NO 1 10 A INV-DATE 11 6 N LINE-ITEM 17 30 A OCCURS 8 INDEX LINE-SUB INV-TOTAL 257 8 P 2 * 30 × 8 = 240 bytes for lines starting at 17 → ends before 257
INDEX names a separate numeric field. It must hold values from 1 through OCCURS maximum. OCCURS 12 needs at least two zoned digits if you use type N 2; OCCURS 200 needs N 3 or wider. Unsigned packed U fields work when shops prefer packed subscripts. Do not reuse a one-byte INDEX for OCCURS 100—overflow wraps or truncates depending on assignment rules and produces intermittent wrong-element bugs hardest to diagnose in production month-end jobs.
| Maximum OCCURS | Suggested INDEX type | Notes |
|---|---|---|
| 1–9 | N 1 0 or N 2 0 | Prefer N 2 for growth headroom |
| 10–99 | N 2 0 | Standard for small tables |
| 100–999 | N 3 0 | Common for code tables |
| 1000+ | N 4 0 or I 4 | Verify FLDMAX first |
An element can be a group: LINE-ITEM contains PROD-CODE 10 A and QTY 5 N inside each occurrence. Group length is sum of child lengths (15 in this example). OCCURS applies to the whole group. Nested OCCURS—rows and columns—uses an outer OCCURS on the row group and inner OCCURS on a field within the group, each with its own INDEX. Easytrieve does not use COBOL-style OCCURS 5 OCCURS 10 in one clause; structure nested DEFINE lines mirror copybook hierarchy. Draw a diagram before coding nested layouts.
1234DEFINE ROW W 15 A OCCURS 10 INDEX ROW-SUB DEFINE COL-VAL W 3 N OCCURS 5 INDEX COL-SUB * Within each ROW overlay, declare COL-VAL nested— * shop standards vary; verify against 11.6 DEFINE nesting rules
Pure one-dimensional arrays index a single list. Two-dimensional logic uses two INDEX fields: ROW-SUB and COL-SUB, with nested OCCURS or computed offset into a flattened OCCURS n×m array. Flattening OCCURS 50 on a fifty-byte row where each row holds ten five-byte columns is one pattern; nested OCCURS is another. Flattening simplifies one loop; nesting mirrors COBOL readability. Pick based on maintenance team familiarity.
VARYING length fields follow special rules in the Language Reference. Combining VARYING with OCCURS may be restricted or require specific release features. Beginners should use fixed-length elements in OCCURS until experienced with product limits. Character parsing arrays use fixed one-byte elements, not varying strings per slot.
Dimensions tell you how many same-sized blocks sit in a row and how big each block is. If each block is three LEGO studs wide and you have twelve blocks, you need thirty-six studs of table space. The INDEX dial only goes as high as the number of blocks—if you have twelve blocks, a dial that stops at nine is too small. On a file record, the blocks must start exactly where the blueprint says or you read someone else's data by mistake.
1. Total bytes for DEFINE ITEM W 5 N OCCURS 20 is approximately:
2. OCCURS on a FILE field must match:
3. FLDMAX controls:
4. Nested OCCURS (group within group) requires:
5. INDEX field length should: