File Status Conventions [ Micro Focus COBOL System Reference, Volume 2 ] MPE/iX 5.0 Documentation
Micro Focus COBOL System Reference, Volume 2
File Status Conventions
This COBOL system supports a number of file status conventions. Each
convention has a separate set of codes defined, though there is some
overlap. The conventions supported are:
* ANSI'85 and extended file status codes
* Microsoft COBOL v2 file status codes
* Ryan-McFarland RM/COBOL file status codes
* IBM mainframe status codes (DOS, OS/2 and Windows)
* ANSI'74 and extended file status codes
ANSI'85 File Status
If you are using the standard system loaded for ANSI'85 operation, then
ANSI'85 codes are produced by default.
On DOS, Windows and OS/2 systems, if the -Aswitch is used at run time
with a program compiled for ANSI'85 operation, then ANSI'74 file status
codes are produced. (DOS, Windows and OS/2)
Microsoft COBOL V2 File Status
On DOS, Windows and OS/2 systems, if you compile your program with the
directives, MS(2) NOANS85, then Microsoft COBOL v2 file status codes are
produced. If you do not specify NOANS85 when compiling, then ANSI'85
file status codes are produced. If you want to use ANSI'85 syntax, but
have Microsoft COBOL v2 file status codes, replace the NOANS85 directive
with ANS85(SYNTAX) or remove the NOANS85 directive and use the -A switch
at run-time. (DOS, Windows and OS/2)
RM/COBOL File Status
On DOS, Windows and OS/2 systems, a conversion routine, RMSTAT, is
available to convert file status codes to RM/COBOL values. This is
invoked by setting the environment variable COBFSTATCONV to the value
RMSTAT and compiling the program with the COBFSTATCONV directive. This
will convert all status values on indexed files. If sequential and
relative files also need to be converted, then the CALLFH compiler
directive must be set when compiling the source. (DOS, Windows and OS/2)
By default on UNIX systems, when the Q run-time switch is set, file I/O
errors with a value of 9 in the first byte are mapped onto RM/COBOL file
status 9 codes. You can change this by altering the alternate file
status table. See the section Alternate File Status Table later in this
appendix for details of how to do this.(UNIX)
ANSI'74 File Status
If you compile your program with the directive NOANS85, then ANSI'74 file
status codes are produced. If you do not specify NOANS85 when compiling,
then ANSI'85 file status codes are produced. If you want to use ANSI'85
syntax, but have ANSI'74 file status codes, then replace the NOANS85
directive with ANS85(SYNTAX) or, under DOS, OS/2 and Windows, remove the
NOANS85 directive and use the -A switch at run-time.
IBM Mainframe Status Codes
On DOS, Windows and OS/2 systems, a conversion routine, HOSTSTAT, is
available to convert file status codes to IBM mainframe values. This is
invoked by setting the environment variable COBFSTATCONVto the value
HOSTSTAT and compiling the program with the COBFSTATCONV directive. This
converts all status values on indexed files. If sequential and relative
files also need to be converted, then the CALLFH compiler directive must
be set when compiling the source. (DOS, Windows and OS/2)
Extended File Status
The ANSI'74 and ANSI'85 file status conventions described above are
augmented with more detailed extended file status codes. Extended file
status codes have the character "9" as the first byte of the file status.
The second byte is a binary (COMP-X) number, which is equivalent to a
run-time error number. These are written as 9/nnn where nnn is the
binary number in the second byte. Run-time errors are documented in your
Error Messages.
For example, if you are writing a file to disk and the disk runs out of
space, the ANSI'74 file status would be a "30", which translates into the
error message:
Permanent error - no other information is available
That error message is very general; a "permanent error" could mean that
the disk has failed, or that the disk drive door is open. So, rather
than return a generic file status, this COBOL system returns an extended
file status of 9/007 (that is, the character, "9", in the first byte, and
binary 7 in the second) meaning "disk full".
When using ANSI'74 or ANSI'85 file status codes, the run-time system
returns extended status codes if the extended file status is more
specific than what would normally be returned.
The following example demonstrates how to redefine a "standard" file
status so it can be used as an extended file status.
Assume for this example that the input file does not exist. When the
OPEN INPUT statement is executed, a file status of 9/013 is returned
meaning "file not found".
select in-file
assign to ...
. . .
file status is ans74-file-status.
working-storage section.
01 ans74-file-status.
05 ans74-status-key-1 pic x.
05 ans74-status-key-2 pic x.
05 ans74-status-key-2-binary
redefines ans74-status-key-2 pic 99 comp-x.
procedure division.
open input in-file
if ans74-file-status not = "00"
if ans74-status-key-1 = "9"
if ans74-status-key-2-binary = 13
display "File not found"
. . .
. . .
If you want to DISPLAY the extended file status, you need to move the
second byte of the file status to a DISPLAY field large enough to hold
the maximum value 255:
select in-file
assign to ...
. . .
file status is ans74-file-status.
working-storage section.
01 ans74-file-status.
05 ans74-status-key-1 pic x.
05 ans74-status-key-2 pic x.
05 ans74-status-key-2-binary
redefines ans74-status-key-2 pic 99 comp-x.
01 display-ext-status
05 filler pic xx value "9/"
05 display-key 2 pic 999
procedure division.
open input in-file
if ans74-file-status not = "00"
display "Error. File status ="
with no advancing
if ans74-status-key-1 = "9"
move ans74-status-key-2-binary to
display-key-2
display display-ext-status
else
display ans74-file-status
end-if
. . . . . .
MPE/iX 5.0 Documentation