COBOL file status

File status 49: REWRITE or DELETE on a file not open I-O

File status 49 means a REWRITE or DELETE was issued for a file that isn't open in I-O mode. Updating or deleting existing records needs OPEN I-O.

Other names for this code

Also written as FS 49, file status code 49, COBOL status 49, status key 49, REWRITE not open I-O, SK49.

What it means

Status 49 is a logic error. REWRITE changes a record that's already in the file, and DELETE removes one. Both need the file open for input and output at once, which COBOL calls I-O mode. A file that's closed, or open INPUT, OUTPUT or EXTEND, gets 49.

Which files support these statements at all also matters. For QSAM, REWRITE works only on a disk data set opened I-O, and DELETE isn't available for sequential files. An ESDS is a sequential file to COBOL, so it allows REWRITE in I-O mode but not DELETE. A KSDS or RRDS allows both in I-O mode, whatever the access mode. Line-sequential files allow neither.

Under the older CMPR2 behavior 49 was reported as 92. Like 47 and 48, it often follows an OPEN that failed without being checked.

Common causes

  • The file was opened INPUT for a read-only version of the program, and update logic was added later without changing the OPEN.
  • OPEN I-O failed, for example with 35 on a VSAM cluster that was never loaded or 37 on a tape, and the status wasn't checked.
  • The file was opened OUTPUT to load it, and the program then tries to REWRITE records without closing and reopening it I-O.
  • An update runs after the file was closed in an end-of-job routine.

How to find the problem

  1. DISPLAY the status of the OPEN for the file.
  2. Check the open mode on the OPEN statement. REWRITE and DELETE need I-O.
  3. Trace any CLOSE that can run before the REWRITE or DELETE.

How to fix it

  • Open the file I-O when the program updates or deletes records.
  • Check the status after every OPEN and stop if it fails.
  • After loading a file with OPEN OUTPUT, CLOSE it and OPEN it I-O before updating.
  • Use DISP=OLD on the DD of a QSAM file updated in place, so no other job reads it while it's half updated.

IBM documentation

IBM Enterprise COBOL 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.

Report a correction to WND Software.

Questions

What is the difference between 49 and 43?

49 means the file isn't open I-O, so updates aren't allowed. 43 means the file is open I-O, but the REWRITE or DELETE didn't follow a successful READ in sequential access.

Can I DELETE a record from a sequential file?

No. DELETE works on indexed and relative files only. For a sequential file, copy it and leave out the records you don't want.