Microsoft KB Archive/62831

Sending Output to Both LPT1 and LPT2 from COBOL 2.x Program

PSS ID Number: Q62831 Article last modified on 06-21-1990

2.00 2.10 2.20 MS-DOS

Summary: In Microsoft COBOL versions 2.00, 2.10, 2.20, 3.00, and 3.00a, a single program can send output to more than one printer by sending output to different device names. However, the method by which this is accomplished differs between versions 2.x and versions 3.00 and 3.00a. A COBOL 3.00 or 3.00a program allows you to change at run time the device name to which output will be sent. In COBOL versions 2.x, this decision cannot be made at run time; it must be hard-coded into the program. This article discusses how output can be sent to more than one printer in a COBOL 2.x program. For information on how a COBOL 3.00 or 3.00a program can dynamically change the printer to which output is being sent, query in the Knowledge Base on the following words: COBOL and 3.00 and ASSIGN and LPT1 This information applies to Microsoft COBOL versions 2.00, 2.10, and 2.20, 3.00, and 3.00a for MS-DOS.

More Information: To send output to two separate printer ports, you will need two SELECT ASSIGN TO DISK clauses. The SELECT statements should define the organization as ORGANIZATION IS LINE SEQUENTIAL. There should be associated FD’s specifying the clause LABEL RECORDS ARE STANDARD. For the VALUE OF FILE-ID clause, you should specify a valid device name for the printer, such as “LPT1” or “LPT2”. The following program opens LPT1 for output, writes information to the printer hooked up to the LPT1 printer port, and then closes the LPT1 device name. The program then opens LPT2 for output, writes information to the printer hooked up to the LPT2 printer port, and then closes the LPT2 device name.

Code Example
IDENTIFICATION DIVISION. PROGRAM-ID. PRTTEST. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT LPT1 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. SELECT LPT2 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD LPT1 LABEL RECORDS STANDARD VALUE OF FILE-ID IS &quot;LPT1&quot;. 01 OUTPUT-REC-1   PIC X(20). FD LPT2 LABEL RECORDS STANDARD VALUE OF FILE-ID IS &quot;LPT2&quot;. 01 OUTPUT-REC-2  PIC X(20). WORKING-STORAGE SECTION. PROCEDURE DIVISION. 000-MAIN. OPEN OUTPUT LPT1. DISPLAY &quot;INPUT SOME INFO TO GO TO LPT1: &quot;. ACCEPT OUTPUT-REC-1. WRITE OUTPUT-REC-1. CLOSE LPT1. OPEN OUTPUT LPT2. DISPLAY &quot;INPUT SOME INFO TO GO TO LPT2: &quot;. ACCEPT OUTPUT-REC-2. WRITE OUTPUT-REC-2. CLOSE LPT2. STOP RUN. Copyright Microsoft Corporation 1990.