Microsoft KB Archive/43929

COBOL 3.0 Run-Time Error 027 with Multiple Print Jobs

PSS ID Number: Q43929 Article last modified on 04-20-1993

3.00 3.00a MS-DOS

Summary: Microsoft COBOL Versions 3.0 and 3.0a issue the run-time error 027 “Device not available” when attempting to OPEN and CLOSE the PRINTER more times than the number specified in the FILES=n statement in the CONFIG.SYS. To avoid this problem, leave the printer open during the run of the program. The problem also occurs when a driver program CHAINs to other programs that OPEN and CLOSE the PRINTER file. Please note that the above workaround does not work when CHAINing because you cannot leave open the PRINTER file across a CHAIN. Another workaround is to send output to a LINE SEQUENTIAL file, which can be printed all at once using the following statement in MS-DOS: COPY filename PRN You can put this MS-DOS command in a batch file, which can be invoked with CALL X“91”, with function 35, from within a COBOL program. For more information, query on the following words: X“91” and 35 and COBOL Microsoft has confirmed this to be a problem in Microsoft COBOL versions 3.0 and 3.0a. This problem has been corrected in Microsoft COBOL Professional Development System version 4.0.

More Information: The run-time error occurs because the COBOL program does not release the file handles used for the printer after a CLOSE statement is issued. The following code fragment produces a run-time error 027 after the print loop has been executed as many times as are stated with the FILES= statement in the CONFIG.SYS:

Code Example
SELECT PRINTER-FILE ASSIGN TO DISK ACCESS MODE IS SEQUENTIAL ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD PRINTER-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS REPORT-DEVICE DATA RECORD IS PRINT-LINE. 01 PRINT-LINE    PIC X(80). WORKING-STORAGE SECTION. 77 REPORT-DEVICE      PIC X(25) VALUE &quot;LPT1&quot;. 77 PASS-NUMBER     PIC 9(5) VALUE ZERO. SCREEN SECTION. 01 DUMMY-SCREEN. 02 PICTURE 9(5) LINE 1 COLUMN 1 FROM PASS-NUMBER TO PASS-NUMBER. PROCEDURE DIVISION. MAIN-LINE. DISPLAY SPACE AT LINE 1 COLUMN 1. PERFORM MAIN-LOOP 9999 TIMES. STOP RUN. MAIN-LOOP. ADD 1 TO PASS-NUMBER. DISPLAY DUMMY-SCREEN. ACCEPT DUMMY-SCREEN. OPEN OUTPUT PRINTER-FILE. MOVE PASS-NUMBER TO PRINT-LINE. WRITE PRINT-LINE. CLOSE PRINTER-FILE. Additional reference words: 3.00 3.00a unavailable Copyright Microsoft Corporation 1993.