Microsoft KB Archive/46368

From BetaArchive Wiki

Printing 5-Character Printer Codes in COBOL 2.x; HP LaserJet

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

2.00 2.10 2.20 MS-DOS

The information in this article applies to:
- Microsoft COBOL for MS-DOS, versions 2.0, 2.1, and 2.2

Summary: This article describes how to send five-character printer control codes to an HP LaserJet printer from a COBOL Version 2.0, 2.1, or 2.2 program. The HP LaserJet requires a 5-byte code. However, no single COMPUTATIONAL can occupy more than 4 bytes in COBOL 2.0, 2.1, or 2.2. Therefore, to send the entire 5-byte code, the code must be broken into two parts that can be sent simultaneously. To split the code in two, enter the printer code into a 01 level record with two subordinate entries. In the example below, that would be the two 05 level entries under the variable 01 CNTL-REC. The control code cannot be split at a random point. The code must be broken into two specific parts, ESC+<the rest of the control code>.

More Information: Your printer manual may list the control codes in hexadecimal notation. In COBOL 2.0, 2.1, or 2.2, you must break the five-character printer control codes into two parts, and convert each part into decimal. For more information on how to convert the hexadecimal code into decimal, query on the following words: three-character and printer and code and 2.x and hexadecimal The following program is specific to the HP LaserJet, but can be used as a basis for sending control codes to other types of printers. Note that printers other than the HP LaserJet usually have entirely different control codes. Please refer to your printer manual to determine the necessary control codes. The following is a code example: IDENTIFICATION DIVISION. PROGRAM-ID. PRINTER-TEST. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. PRINTER IS PRINTER-DEVICE. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD PRINT-FILE LABEL RECORDS OMITTED. 01 PRINT-REC PIC X(80). 01 CNTL-REC. 05 ESC-CHAR PIC 9(4) USAGE COMP-0. 05 FOUR-CHAR PIC 9(10) USAGE COMP-4. * Here we assign the value of ESC (1B) plus the rest of the * of the code (&l1o) to set the HP to landscape mode. WORKING-STORAGE SECTION. 01 ESC-CODE PIC 9(4) VALUE 27 COMP-0. 01 FOUR-CODE PIC 9(10) VALUE 644624719 COMP-4. PROCEDURE DIVISION. 0100-MAIN-CODE. OPEN OUTPUT PRINT-FILE. * Here we move the two halves into the sub-level of CNTL-REC. MOVE ESC-CODE TO ESC-CHAR. MOVE FOUR-CODE TO FOUR-CHAR. WRITE CNTL-REC BEFORE ADVANCING 0. MOVE “THIS LINE WILL BE IN LANDSCAPE MODE” TO PRINT-REC. WRITE PRINT-REC. CLOSE PRINT-FILE. STOP RUN.

Additional reference words: 2.00 2.10 2.20 Copyright Microsoft Corporation 1993.