Skip to main content

Problem:

Do you have a Cobol program to count records in an index file?

Resolution:

The attached zip file contains a utility that allows you to get a record count for an index file. The utility is called RMRECX. An example COBOL program, TSTRMREC.CBL, is included that demonstrates the proper use of this utility.

The index file must be closed in the run unit that calls RMRECX, because it has to open the file as a binary sequential file to get the number of records in it. A conflict occurs when the file is currently open as an index file. It can't open it both ways at the same time.

When the index file is open in the run unit at the time RMRECX is called, the file manager has a physical file descriptor indicating it is an index file. Thus, the binary sequential open fails as an organization mismatch. If the file is not open, the file manager doesn't know that it is an index file and the open succeeds.

In the attached RMRECX utility, the error status returned from the OPEN statement when the index file is open in the calling program is a 39,01. This error indicates a physical file organization mismatch.

With this version, you can check the file status returned (see the TSTRMREC.CBL program), and if it returns an error, you can take appropriate action. At least you will know there was a problem and that the count value is not usable. A previous version of this utility, (RMREC), did not return a file status, and is therefore obsolete.

    

Attachments:

RMRECX.zip

Old KB# 4666