Microsoft KB Archive/43638

How to Assign Output to Printer at Run-Time in ASSIGN Clause

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

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: In a COBOL Version 3.0 or 3.0a program, you can choose to send output to either a printer or to a file at run time by specifying the desired device name in a WORKING-STORAGE data item, such as File-Name, and then ASSIGN TO File-Name. To send to the printer, initialize File-Name at run time with LPT1: or PRN, which are valid MS-DOS device names for the printer device. Sending output to a file can be performed by specifying any valid filename.

More Information: If you mistakenly try to assign output to an identifier that contains the name “PRINTER”, the program below will send the output to a file called PRINTER on the disk because PRINTER is not a valid MS-DOS printer device name. If you use ASSIGN TO PRINTER syntax in the COBOL source code (not shown below), output always goes to the printer. In this context, PRINTER is a COBOL reserved word. Code Example: The following code example prompts you for a filename and sends the output to that file: $set ans85 IDENTIFICATION DIVISION. PROGRAM-ID. TESTus. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. * *************************** FILE-CONTROL. * *************************** SELECT OUTPUT-FILE ASSIGN TO file-name ORGANIZATION IS LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL. FD OUTPUT-FILE. 01 OUTPUT-REC PIC X(20). WORKING-STORAGE SECTION. * file to which data should be sent 01 file-name PIC X(12). PROCEDURE DIVISION. 000-MAIN. DISPLAY “input file name to send output to”. ACCEPT file-name. OPEN OUTPUT OUTPUT-FILE. DISPLAY “input name”. ACCEPT OUTPUT-REC. WRITE OUTPUT-REC. CLOSE OUTPUT-FILE. STOP RUN.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.