An application may abend with either a Protection Exception (S0C4 abend) or Data Exception (S0C7 abend) when the program logic fails to address the possibility of an empty input file. If the logic passes through tests against the data, or attempts to pass empty files to the sort, undesirable consequences will occur. As the saying goes: Garbage In, Garbage Out.
This is easily avoided by including a simple test for the case when there is no data in the input file.
VISION:Results provides a keyword, STATUS, on the FILE statement which is followed by a dataname you choose. The field pointed to by this dataname is automatically populated with the file status after each attempted access. (Please refer to the VISION:Results Reference Guide for more details.) This field should be tested for end of file at the beginning of every program.
In this example a message is printed if end of file is encountered on the first read before the program is terminated by the QUIT command:
FILE INFILE INPUT ... STATUS IEOF
IF IEOF EQ 'E'
PRINT 'ATTENTION! INPUT FILES ARE EMPTY. NO REPORT GENERATED.'