Test the END-OF-FILE or AT END condition for files accessed sequentially, and test the INVALID KEY condition for files accessed randomly.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.
Syntax: for Format 1
conditionalverb [AT] END ON filename
statementblock
Syntax: for Format 2
conditionalverb INVALID [KEY] ON filename
statementblock
Syntax Rules:
- S-COBOL defines 05
filename--END PIC X and 05
filename--INV PIC X as flags for the AT END and INVALID KEY conditions for each file.
- END ON
filename and INVALID ON
filename are 88-level file status condition names that S-COBOL provides with the AT END and INVALID KEY flags. You can use these as a condition in any conditional statement.
- Flag are set when the file is accessed by a READ, WRITE, etc., statement and before the AT END ON/INVALID KEY ON condition is valid.
Example:
PARA MAIN-LOGIC
OPEN INPUT MASTER-FILE
REPEAT
READ MASTER-FILE INTO MASTER-REC
... INVALID KEY
MASTER-REC = HIGH-VALUES
ELSE-IF MASTER-TYPE = 'A'
PERFORM PROCESS-TYPE-A
ELSE-IF MASTER-TYPE = 'C'
PERFORM PROCESS-TYPE-C
ELSE
PERFORM PROCESS-OTHER-TYPES
UNTIL INVALID KEY ON MASTER-FILE
CLOSE MASTER-FILE
STOP RUN