IGZ0020S: File logic error with no FILE STATUS or declarative
IGZ0020S means a COBOL READ, WRITE, REWRITE, DELETE, OPEN or CLOSE failed with a logic error, and the program had neither a FILE STATUS clause nor an error declarative for that file, so the runtime ended it. The status code at the end of the message, such as 48 or 46, tells you which logic error it was.
Other names for this code
Also written as IGZ0020, IGZ020S, IGZ0020S status code 48, IGZ0020S 46, IGZ0020S U4038, a logic error occurred neither FILE STATUS nor a declarative.
What it means
COBOL sorts I/O failures into classes by the first digit of the file status. Status codes starting with 4 are logic errors. They mean the program asked for something that doesn't fit the state of the file, such as writing to a file it opened for input.
A program can deal with these errors in two ways. It can name a FILE STATUS field and test it, or it can code a USE AFTER ERROR declarative. If it does neither, the runtime writes IGZ0020S and ends the program. The message names the file (the name from the SELECT clause), the program and the relative location, and ends with the status code. Newer runtimes add a line with the compile unit, entry point and offset.
Under Language Environment the step then ends with user abend U4038.
The status codes in this class mean the following.
- 41 is an OPEN of a file that is already open.
- 42 is a CLOSE of a file that isn't open.
- 43 is a REWRITE or DELETE in sequential access that wasn't preceded by a successful READ.
- 44 is a boundary violation, where the record is the wrong size for the file.
- 46 is a sequential READ after the end of file was already reached, or after a failed READ.
- 47 is a READ of a file that isn't open for INPUT or I-O.
- 48 is a WRITE to a file that isn't open for OUTPUT, I-O or EXTEND.
- 49 is a DELETE or REWRITE of a file that isn't open for I-O.
IBM APAR PN77687 also shows IGZ0020S for a program that read a sequential file to its end with no AT END phrase, FILE STATUS or declarative.
Common causes
- Status 48 comes from a WRITE to a file that was opened INPUT, never opened, or already closed. Another form is a WRITE to a sequential file opened I-O, which only allows REWRITE.
- Status 46 comes from a read loop that doesn't stop at end of file and reads again.
- Status 47 comes from a READ before the OPEN, or after a CLOSE that ran too early.
- Status 44 comes from writing a record longer or shorter than the file allows. It often shows up with RECORDING MODE V and a length field that doesn't match the record.
- Status 41 or 42 comes from opening or closing a file twice.
How to find the problem
- Read the status code at the end of the IGZ0020S message in SYSOUT, and the file name. The name is the one in the SELECT clause, so check the program for its DD name.
- Use the relative location or compile unit offset with the compile listing (LIST or OFFSET option) to find the failing statement.
- Trace the OPEN and CLOSE statements for that file and the mode used, and check whether the failing statement fits that mode.
- For status 44, compare the record length in the FD with the LRECL and RECFM of the data set, using the JCL and the data set attributes.
How to fix it
- Add a FILE STATUS clause for every file and test it after each I/O statement. The program can then report the problem and end cleanly.
- Open the file in a mode that fits what the program does with it. A sequential file that is read and then written back needs a separate output file, or REWRITE in I-O mode.
- Stop read loops at end of file with an AT END phrase or a status 10 check.
- For status 44, make the record you write fit the file's record size limits.
- Make OPEN and CLOSE run once each.
What it looks like
IGZ0020S A logic error occurred. Neither FILE STATUS nor a declarative was specified for file ACCT-OUT in program ACCTUPD at relative location X'086C'.
The status code was 48.
From compile unit ACCTUPD at entry point ACCTUPD at compile unit offset +0000086C
IEF450I PAYRUN01 STEP030 - ABEND=S000 U4038 REASON=00000001IBM documentation
IBM z/OS documentation. Use the documentation for your installed release.
This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.
Related codes
Questions
What is the difference between IGZ0020S and IGZ0035S?
IGZ0035S is for an OPEN or CLOSE that failed with a permanent error, such as status 35 or 39. IGZ0020S is for a logic error, a status starting with 4, on any I/O statement.
Will adding FILE STATUS make the error go away?
No. It stops the runtime from ending the program, but the program then has to test the status and act on it. The logic bug that caused the status is still there until you fix it.
Which file does IGZ0020S mean?
The one named in the message, which is the COBOL file name from the SELECT clause. The ASSIGN clause on that SELECT gives the DD name in the JCL.