EOF means end-of-file. In Easytrieve it appears in a file-presence condition such as IF EOF SORT2, DO WHILE NOT EOF INPUT1, or DO UNTIL EOF MASTER. The condition tells you whether a named file has been exhausted; it does not test a field's bytes, compare a key with HIGH-VALUES, or interpret FILE-STATUS as zero or nonzero. EOF matters most in controlled input and synchronized multi-file JOB activities, where one file can end while another still supplies records. Automatic single-file JOB INPUT follows a different lifecycle: Easytrieve fetches the next record, runs the JOB body, repeats, and transfers to FINISH processing when no next record exists. Broadcom explicitly notes that the EOF presence test can never be true for an automatic input file. This tutorial explains file presence, automatic versus controlled reads, synchronized inputs, NOT EOF loops, FINISH, FILE-STATUS, merge sentinels, empty files, and common off-by-one mistakes.
Easytrieve conditional expressions include field relational, field class, file presence, file relational, and record relational conditions. EOF belongs to file presence. Its documented form is IF, DO WHILE, or DO UNTIL followed by optional NOT, optional EOF, and a file subject. With EOF present, the test is true when the subject is at end-of-file. With NOT, the result reverses.
1234567IF EOF FILE2 DISPLAY 'FILE2 HAS ENDED' END-IF IF NOT EOF FILE1 DISPLAY 'FILE1 STILL HAS A CURRENT RECORD' END-IF
JOB INPUT PAYFILE normally gives Easytrieve control of retrieval. Before each JOB iteration, the runtime obtains a record. After the last statement, an implied return to JOB requests the next record. When there is no next record, Easytrieve does not enter the JOB body with an EOF flag for PAYFILE; it completes the input activity and invokes FINISH logic. That is why an EOF test cannot become true for the automatic input file itself.
1234567JOB INPUT PAYFILE FINISH END-OF-JOB WS-COUNT = WS-COUNT + 1 PRINT PAY-RPT END-OF-JOB. PROC DISPLAY 'RECORDS PROCESSED' WS-COUNT END-PROC
The FINISH procedure runs once after automatic input ends. It is the right location for final counts, trailers, totals, and completion messages. Coding IF EOF PAYFILE inside the ordinary JOB body and expecting it to identify the last record misunderstands the automatic cycle.
Controlled input programs explicitly request records with GET or RETRIEVE. They can test EOF and decide what to do next. The safe order depends on the statement and access method: initialize input, retrieve a record, check whether a current record exists or EOF was reached, process only valid data, then retrieve again. Never process the buffer after an unsuccessful retrieval as though it contained a new record.
12345GET INPUT-FILE DO WHILE NOT EOF INPUT-FILE PERFORM PROCESS-RECORD GET INPUT-FILE END-DO
This skeleton shows the familiar priming-read pattern. Confirm the exact GET and status conventions for the file type in your Broadcom release. Indexed and database access can return statuses other than ordinary sequential EOF.
In synchronized JOB INPUT, files advance according to their keys. One secondary file can reach EOF before the primary file. Easytrieve continues JOB iterations driven by remaining data, making IF EOF secondary-file meaningful. Broadcom examples show EOF on one file staying true across later iterations while another file continues.
1234567891011JOB INPUT (SORT1 KEY (CUSTOMER-ID), + SORT2 KEY (CUSTOMER-ID)) + FINISH MERGE-FINISH IF EOF SORT2 DISPLAY 'NO MORE SORT2 RECORDS' END-IF IF SORT1 AND NOT SORT2 PERFORM ONLY-IN-SORT1 END-IF
IF SORT1 is a presence test for a current SORT1 record. IF NOT SORT2 means no matching SORT2 record is present on this iteration; it is not necessarily identical to EOF SORT2. SORT2 can still have later keys even when it is absent for the current match key.
| Condition | Question answered | Example meaning |
|---|---|---|
| IF FILE2 | Is FILE2 present for this iteration/key? | Matching secondary record exists |
| IF NOT FILE2 | Is FILE2 absent for this iteration/key? | No matching secondary record |
| IF EOF FILE2 | Has FILE2 been completely exhausted? | No later FILE2 record can exist |
| IF NOT EOF FILE2 | Can FILE2 still provide data? | Current or later data remains |
This difference is central to match/merge programming. A secondary file can be absent for customer 100 but still contain customer 200. IF NOT FILE2 is true for the current match; IF EOF FILE2 is false because later data remains.
EOF is a logical file-presence state. FILE-STATUS records the result of an I/O operation. A nonzero status may mean not found, duplicate key, access error, record-length problem, or another file-specific condition. Do not translate every nonzero status into EOF. Check operation documentation and handle expected EOF or not-found separately from errors.
12345678910GET PAYMSTR IF EOF PAYMSTR DISPLAY 'END OF PAYMSTR' ELSE IF PAYMSTR:FILE-STATUS NOT ZERO DISPLAY 'PAYMSTR I/O ERROR' PAYMSTR:FILE-STATUS STOP END-IF END-IF
During normal automatic input, the current record can be the last record without EOF being visible in the JOB body. EOF becomes known only when retrieval attempts to move beyond the end. If logic must identify a final record before processing it, use record-relational conditions where applicable, trailer conventions, look-ahead logic, or FINISH processing. Do not label the current record “last” simply because its key equals a guessed maximum.
With automatic input, an empty file produces no ordinary JOB iterations. FINISH behavior and report output then determine whether a zero-record report or completion message is produced. Initialize counters before JOB and inspect them in FINISH. With controlled input, the first retrieval can immediately establish EOF; guard the record buffer before any field reference.
123456789101112DEFINE WS-COUNT W 7 N VALUE 0 JOB INPUT INPUT-FILE FINISH CHECK-EMPTY WS-COUNT = WS-COUNT + 1 CHECK-EMPTY. PROC IF WS-COUNT ZERO DISPLAY 'INPUT FILE WAS EMPTY' ELSE DISPLAY 'INPUT RECORD COUNT' WS-COUNT END-IF END-PROC
Hand-controlled two-file merges often compare current keys. After one file reaches EOF, moving HIGH-VALUES to its work key can make that key sort after every real key, allowing the other file to drain. The sentinel is a work-field technique. Keep a separate EOF state and ensure no real key can equal the sentinel.
1234567891011IF EOF FILE-A MOVE HIGH-VALUES TO A-WORK-KEY END-IF IF EOF FILE-B MOVE HIGH-VALUES TO B-WORK-KEY END-IF IF A-WORK-KEY LT B-WORK-KEY PERFORM WRITE-A-ONLY END-IF
DO WHILE NOT EOF FILE continues while the file is not exhausted. DO UNTIL EOF FILE also expresses a stopping condition, but loop timing and the first retrieval must be planned. A poorly primed loop can process an uninitialized buffer once or process the last record twice. Draw the states—before first GET, current record available, after successful GET, after failed GET—before coding complex controlled input.
FINISH is part of the JOB lifecycle rather than an EOF figurative value. It gives one controlled location for final totals and cleanup after automatic input. Reports also finish control breaks and pagination at activity completion. Avoid issuing duplicate final lines both in an attempted IF EOF branch and in FINISH.
Normal EOF is not an error. Do not display alarming I/O failure messages or force a bad return code merely because sequential processing completed. Conversely, do not hide a true read error as normal EOF. Separate expected exhaustion, not-found statuses in random access, and hardware or data errors. Include file name, operation, status code, and key in diagnostics.
The file-presence syntax is documented in Broadcom Easytrieve Report Generator 11.6 and earlier CA-Easytrieve Plus guides. Whether a particular operation establishes EOF, not found, or another status depends on sequential, synchronized, VSAM, virtual, SQL, and database input modes. Use the file-processing chapter for the actual file type rather than copying a sequential GET loop into random VSAM code.
Imagine reading cards from a box. EOF means you reached into the box and there were no more cards. In automatic mode, Easytrieve hands you each card and stops calling you when the box is empty, then calls your FINISH helper. In controlled mode, you reach into the box yourself, so you must check whether you actually received a card before reading it. A missing card for one customer is not always EOF—the box may contain cards for later customers.
1. What does IF EOF FILE2 test?
2. Which condition continues while records remain?
3. How does EOF differ from FILE-STATUS?
4. In automatic input processing, normal final logic is usually placed in:
5. Why might a merge program move HIGH-VALUES to a key after EOF?