Microsoft KB Archive/31884

COBOL Example to DISPLAY the FILE STATUS; STATUSes Defined

PSS ID Number: Q31884 Article last modified on 04-21-1993

2.00 2.10 2.20 MS-DOS

Summary: This article explains the different FILE STATUS values returned for SEQUENTIAL, LINE SEQUENTIAL, RELATIVE and ISAM files in Microsoft COBOL Versions 2.0, 2.1, and 2.2. The sample program below illustrates how to use and DISPLAY the FILE STATUS.

More Information: The following are the File Type codes used in the table below: S = SEQUENTIAL or LINE SEQUENTIAL R = RELATIVE files I = Indexed Sequential (ISAM) files Type File S R I Status Meaning X X X 00 Successful completion X 02 Duplicate key; duplicates allowed X X X 10 End of file X 21 Sequence error X X 22 Duplicate key; duplicates not allowed X X 23 Key not found X X 24 Disk space full X X X 30 Permanent error or file not found X 34 Disk space full X X 91 File structure error X X X 94 Record or file locked X 95 Indexed file system not available Please see Pages 299, 319, and 342 of the “Microsoft COBOL Reference Manual” (for COBOL Versions 2.x) for more information on FILE STATUS. The following is a code example:

IDENTIFICATION DIVISION. PROGRAM-ID. MyProgram. * * Example:  File status *  ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MyInputFile ASSIGN TO DISK FILE STATUS IS MyFileStatus. DATA DIVISION. FILE SECTION. FD  MyInputFile LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS &quot;MyInFile.dat&quot;. 01  MyString        PIC XXX. WORKING-STORAGE SECTION. 01  MyFileStatus    PIC XX. PROCEDURE DIVISION. MyOpen. OPEN OUTPUT MyInputFile. DISPLAY (10, 10) &quot;OPEN File status = &quot;, MyFileStatus. MOVE &quot;zzz&quot; to MyString. WRITE MyString. DISPLAY (11, 10) &quot;WRITE File status = &quot;, MyFileStatus. CLOSE MyInputFile. DISPLAY (12, 10) &quot;CLOSE File status = &quot;, MyFileStatus. STOP RUN. Additional reference words: 2.00 2.10 2.20 Copyright Microsoft Corporation 1993.