Skip to main content

This article provides CBL_OPEN_FILE Documentation clarification.

Problem:

When opening a file that is, or will, be greater than 4GB using CBL_OPEN_FILE, a file status 181 is returned:

Invalid Parameter Error

Why is this?

Resolution:

CBL_OPEN_FILE is used to open an existing file for byte stream operating. When using CBL_OPEN_FILE one of the parameters the routine requires is “access-mode”. The documentation shows the following valid modes:

1. Read only
2. Write only (deny-mode must be 0)
3. Read/write
64  Read/write files greater than 4GB

Deny-modes are as follows:

0 Deny both read and write (exclusive)
1 Deny write
2 Deny read
3 Deny neither read nor write

Device is reserved for future use (must be zero).

When opening a file that is greater than 4GB it looks as if the “access-mode” should be “64”. In actuality you must also pass value 1, 2, or 3 along with the 64. The call to CBL_OPEN_FILE would look like the following if opening a file greater than 4GB for read only. Notice access-mode-64-gt-4G equals 65. The reason is that you would pass the access-mode-1-read plus access-mode-64-gt-4G.

Access mode and deny mode parameters are additive for example read/write access is enabled by adding read (value 1) and write (value 2) to get a result = 3 for Read/Write access – Adding 64 to the setting in order to enable for Large Files produces a value of 67 – indicating Large File with Read/Write access.

WORKING-STORAGE SECTION.

01 CBL_OPEN_FILE_PARAMETERS.

05 access-mode-1-read pic x comp-x value 1.

05 access-mode-2-write pic x comp-x value 2.

05 access-mode-3-read-write pic x comp-x value 3.

05 access-LRG-FILE-READ pic x comp-x value 65.

05 deny-mode-0-both pic x comp-x value zero.

05 deny-mode-1-write pic x comp-x value 1.

05 deny-mode-2-read pic x comp-x value 2.

05 deny-mode-3-neither pic x comp-x value 3.

05 device-0-std pic x comp-x value zero.

PROCEDURE DIVISION.

move '/usr/mydata_files/TEST1.DAT' to INFILE-PATHNAME.

call 'CBL_OPEN_FILE' using INFILE-PATHNAME

access-mode-64-gt-4G

deny-mode-1-write

device-0-std

INFILE-HANDLE.

Note: INFILE-HANDLE returns a file handle for a successful open.

Incident Number: 2355542

Old KB# 14715