In COBOL applications, handling files correctly is crucial for ensuring that data is read, written, and processed efficiently. When opening a file in COBOL, you might encounter a variety of errors, one of which is a status code 90 error. This error typically signals that the file cannot be opened successfully for reasons such as incorrect file configuration, file access issues, or mismatched file attributes.

If you're encountering a status code 90 when trying to open a file with a fixed block size in your COBOL application, this guide will walk you through troubleshooting and resolving the issue.

2. What is Status Code 90 in COBOL?

In COBOL, when you attempt to open a file (using the OPEN statement), the system returns a status code that provides information about whether the operation was successful or if an error occurred. Status code 90 is typically returned when the file cannot be opened due to a configuration or access problem.

The general meaning of status code 90 is:

File cannot be opened due to an invalid file name, incorrect file attributes, or an issue with file access permissions.

The status codes are defined in the COBOL standard and are used to identify specific issues during file handling. The number 90 corresponds to a problem that prevents opening the file, which may be due to incorrect file specifications or other issues with the file or its environment.

3. Common Causes of Status Code 90

There are several potential reasons why you might encounter a status code 90 when trying to open a file in COBOL. Below are some common causes:

Incorrect File Path or Name: The file path or file name provided in the COBOL program may be incorrect, preventing the file from being located.

File Access Permissions: The file may not have the correct permissions, meaning the program cannot read from or write to the file.

File Format Mismatch: If the file has a fixed block size but is not defined correctly in the COBOL program, the application will fail to open it.

Incorrect File Organization or Structure: The file might be organized incorrectly, such as using an incompatible file format or organization type (e.g., sequential vs indexed files).

File Already Opened Elsewhere: The file may already be opened by another program or user, causing a conflict when your program tries to access it.

File System Issues: There could be issues with the file system itself, such as disk corruption, a missing directory, or a full disk.

4. How to Fix Status Code 90

To resolve the status code 90 error, follow these troubleshooting steps systematically:

4.1 Verifying the File Path and Accessibility

The first step is to ensure that the file exists at the specified location and that the path you provided in your COBOL program is correct.

Check the File Path: Double-check the file path in your COBOL program to ensure it is correctly specified.

Test File Accessibility: Ensure that the file can be accessed by the COBOL program. Try opening the file manually or using a command-line tool to verify that the file is present and accessible.

4.2 Checking File Access Permissions

Ensure that the file has the appropriate permissions for the operation your COBOL program is performing. The application must have read or write access (depending on the file mode you are using).

Review Permissions: Use tools like ls -l on Unix/Linux or the properties dialog on Windows to check the file permissions.

Adjust Permissions: If the file lacks the necessary permissions, you can update them using chmod on Unix/Linux or modify the file's properties on Windows.

4.3 Ensuring Correct File Attributes (Fixed Block Size)

Since you are working with a file that has a fixed block size, you must ensure that the file is opened correctly with the correct attributes in your COBOL program.

Fixed Block Size Definition: In COBOL, the RECORD and BLOCK clauses in the SELECT statement define how the file is opened. Make sure the BLOCK CONTAINS clause corresponds to the block size of the file.

Example:

cobol

Copy code

SELECT MYFILE ASSIGN TO 'myfile.dat' ORGANIZATION IS LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-STATUS.

Correct Block Size in COBOL: When dealing with fixed block size files, ensure that you specify the correct block size using the BLOCK CONTAINS clause.

Example:

cobol

Copy code

SELECT MYFILE ASSIGN TO 'myfile.dat' ORGANIZATION IS LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL BLOCK CONTAINS 512 CHARACTERS FILE STATUS IS WS-STATUS.

4.4 Correct File Organization

The file organization must match the type of file you're trying to access. For example:

Line Sequential: For files where records are stored sequentially, such as text files.

Indexed or Relative: For files where records are accessed via keys or relative positions.

Ensure the file organization and access mode in your SELECT statement align with the file's actual organization.

4.5 Opening the File in the Correct Mode

You need to open the file in the correct mode (INPUT, OUTPUT, I-O) depending on what operation you want to perform.

INPUT: Open for reading.

OUTPUT: Open for writing.

I-O: Open for both reading and writing.

For example:

cobol

Copy code

OPEN INPUT MYFILE.

4.6 Reviewing the COBOL File Control Entry

The file control entry in your COBOL program must correctly reference the file and its attributes. Double-check the SELECT clause, ASSIGN statement, and any related file control statements to ensure they are properly defined.

5. Tips for Testing Files in COBOL

When testing file handling in COBOL, it's important to create a consistent environment to ensure that your file operations are properly tested:

Use a Sample File: Before testing with production files, create a small, sample test file with known content and structure.

Check for End-of-File Conditions: Ensure that you handle end-of-file (EOF) conditions in your program. A common mistake is not correctly checking for EOF when reading files.

Use Debugging Tools: Utilize any available debugging or logging features to trace file operations and identify the root cause of errors.

6. Best Practices for File Handling in COBOL

To minimize errors and ensure efficient file handling in COBOL, follow these best practices:

Always Check the Status Code: Always monitor the file status code after each file operation (OPEN, READ, WRITE, CLOSE). This helps identify issues early.

Use Structured File Names: Define and use clear, consistent file naming conventions.

Organize Files Properly: Ensure that files are organized according to the type of operation you need to perform (e.g., sequential vs indexed).

Ensure Proper Error Handling: Implement comprehensive error handling that checks for specific file-related errors and reports them effectively.

7. Debugging Tips

When debugging issues related to file handling in COBOL, keep these tips in mind:

Enable Detailed Logging: Some systems allow you to enable verbose logging to see more details about the file operations.

Simulate File Access: Use test cases with known inputs and outputs to simulate file access in different modes (read/write).

Check File Permissions: Incorrect file permissions are often a culprit in file access issues.

Inspect System Messages: Many systems provide system logs or messages when a file cannot be opened. Check these logs for additional information.

8. Frequently Asked Questions (FAQ)

Q1: What does status code 90 mean in COBOL?

Status code 90 indicates that the file cannot be opened due to an invalid file name, file path, or file permissions issue.

Q2: How can I check the file permissions?

On Unix/Linux systems, use the ls -l command to check file permissions. On Windows, right-click the file and select "Properties" to view and modify permissions.

Q3: What file organizations are supported in COBOL?

COBOL supports various file organizations, including SEQUENTIAL, INDEXED, and RELATIVE. Each organization type requires different handling in your SELECT and FD statements.

Q4: How do I open a fixed block size file in COBOL?

Use the BLOCK CONTAINS clause in the SELECT statement to specify the block size when working with fixed block size files.

Q5: How do I handle end-of-file (EOF) in COBOL?

Check the status code after each READ operation to handle EOF conditions. When reading sequential files, check if the status code is 10 (end-of-file).

9. Conclusion

Status code 90 errors can be frustrating, but with careful attention to file attributes, access permissions, and COBOL file handling specifications, they can be resolved efficiently. By following the steps outlined in this guide, you should be able to troubleshoot and fix the issue quickly.

Author's Bio: 

Rchard Mathew is a passionate writer, blogger, and editor with 36+ years of experience in writing. He can usually be found reading a book, and that book will more likely than not be non-fictional.