Arrays in Easytrieve let one field name represent many repeated values—weekly hours for twelve pay periods, fifty state tax codes loaded from a table, or eighty characters walked one byte at a time when you split a delimited string. Unlike COBOL, where you write EMP-TABLE(3), Easytrieve declares OCCURS on DEFINE and uses a separate INDEX field as the subscript. Set INDEX to 4, and references to the array element use the fourth occurrence. This model matches how Broadcom documents DEFINE in the 11.6 Language Reference: OCCURS maximum-occurrences creates the array, INDEX names the controlling subscript field. Beginners encounter arrays in working storage for scratch tables built during a JOB, on FILE layouts when records carry repeating groups, and in advanced parsing patterns with one-byte OCCURS overlays. Total size is bounded by FLDMAX and by element length multiplied by occurrence count—planning matters before you declare SALES(9999). This overview explains why arrays exist in batch reporting, how they relate to TABLE and LOOKUP features, syntax essentials, memory implications, and the learning path through dimensions, initialization, access, and iteration pages in this section.
Batch jobs rarely process only scalar fields. Payroll reads twelve month-to-date buckets. Inventory extracts compare quantities across warehouse slots. Validation programs scan every character in an account number. Without arrays you would copy-paste DEFINE lines RATE-01 through RATE-12 and duplicate logic twelve times—unmaintainable when rates change. OCCURS collapses repetition into one definition and one loop. Arrays also bridge to TABLE statement loading: many shops load reference data into OCCURS working storage, then LOOKUP or sequential INDEX walks during JOB processing. Report writers print one element per detail line by incrementing INDEX inside a DO loop. Understanding arrays is prerequisite for table performance tuning and for PARSE-style character walks documented elsewhere in this tutorial series.
DECLARE creates the repeated structure; INDEX creates the subscript controller. Both appear on DEFINE in the Library or inside an activity before first reference. The INDEX field is typically a small numeric working storage field—often type N length 2 or 4—defined on the same line or immediately after the OCCURS field. Before you MOVE AMOUNT TO TOTAL-PAY(INDEX) style logic, you assign INDEX. Reference syntax uses the element field name directly once INDEX holds the desired occurrence number. Occurrence numbers start at 1 unless your shop documents otherwise—test with DISPLAY or a small test job when migrating from another language.
12345678910DEFINE RATE W 3 P 2 OCCURS 12 INDEX RATE-SUB DEFINE RATE-SUB W 2 N VALUE 1 JOB INPUT MASTER DO WHILE RATE-SUB LE 12 IF RATE(RATE-SUB) GT 0 PAY = PAY + RATE(RATE-SUB) END-IF RATE-SUB = RATE-SUB + 1 END-DO
| Location | Declared | Typical use |
|---|---|---|
| FILE record field | After FILE in Library, OCCURS on group item | Repeating groups in input—invoice lines, weekly buckets in master record |
| W working storage | DEFINE name W length type OCCURS n INDEX idx | Scratch tables, parsed tokens, counters built during JOB |
| S static storage | DEFINE name S length type OCCURS n INDEX idx | Tables persisting across procedures within run; less spooled to report work files |
FILE arrays map directly from the record layout: if the copybook shows five line items of twenty bytes each, OCCURS 5 on the line group matches the physical record. Working storage arrays are independent of any file—you load them with MOVE, READ into a buffer, or TABLE load. Choose W for simple JOB counters unless report spooling of W fields affects your design; see the working storage tutorial for W versus S trade-offs.
TABLE statement loads keyed reference data into memory the product manages. OCCURS arrays are developer-managed structures you index yourself. Some programs combine both: TABLE holds the corporate rate file, while an OCCURS array holds twelve computed values for the current employee. LOOKUP searches TABLE keys; arrays use INDEX walks or stored key parallel fields. Beginners should learn DEFINE OCCURS first, then TABLE, because many maintenance programs still use hand-loaded OCCURS arrays for small code tables under fifty rows where TABLE overhead is unnecessary.
Each field—including the entire OCCURS group—must fit within maximum field length controlled by the FLDMAX installation option. If one element is 100 bytes and OCCURS is 200, the product allocates 20,000 bytes for that field group. Exceeding FLDMAX causes compile or allocation errors. Dimension planning page walks formulas; for now remember that wide elements times high occurrence counts consume real memory in the address space. Batch REGION and Easytrieve work file settings interact with large arrays the same way large TABLE definitions do.
A powerful idiom overlays a string buffer with OCCURS 80 INDEX CX where each element is one byte type A. Set CX from 1 upward to examine CH(CX) or the equivalent element name your DEFINE uses. This pattern replaces missing PARSE statement functionality for comma-separated values, fixed-format sign positions, and delimiter hunting. The PARSE patterns tutorial shows full examples; arrays overview introduces the concept because it is often a beginner's first OCCURS use case outside numeric tables.
123456DEFINE WORK-LINE W 80 A DEFINE CH W 1 A OCCURS 80 INDEX CX DEFINE CX W 2 N VALUE 1 * Overlay: redefine WORK-LINE as byte array via matching length OCCURS * Walk CX from 1 to 80 to inspect each character
Defining RATE-01, RATE-02, RATE-03 without OCCURS is valid for three fixed slots when no loop will ever run. Arrays win when count exceeds a handful or when logic is uniform across elements. Migration from COBOL often starts as separate fields; refactoring to OCCURS reduces LINE and PRINT duplication in reports. Cost: slightly harder debugging until you DISPLAY INDEX and element together in test output.
An array is a row of numbered boxes with the same label. Instead of saying "open box number three" with special punctuation, Easytrieve gives you a pointer dial called INDEX. Turn the dial to 3, then the program knows you mean the third box. All boxes are the same size and sit next to each other in memory. You can have a row of boxes in a file record or a row you built yourself in working storage for homework the job is doing right now.
1. An Easytrieve array is declared with:
2. The INDEX parameter on DEFINE:
3. Total array storage is limited by:
4. A one-byte OCCURS field is often used to:
5. Compared to COBOL OCCURS, Easytrieve subscripts are: