Microsoft KB Archive/37887

COBOL 3.00-4.00: Sending Two-Character Printer Control Codes

PSS ID Number: Q37887 Article last modified on 04-25-1991

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

Summary: The following example shows how to send two-character printer control codes to the printer in COBOL versions 3.00, 3.00a, and 4.00. The control-code sequence must be concatenated into one hexadecimal number. For example, ESC+@ is the standard Epson printer-control code sequence to reset the printer. In hexadecimal representation, ESC is 1B hex, and @ is 40 hex. When you concatenate these hexadecimal codes, you get 1B40 hex. The statement MOVE x“” can move this hexadecimal number into a data item for sending to the printer. (There is no need to convert the printer control sequence to a decimal number, because COBOL versions 3.00, 3.00a, and 4.00 support hexadecimal notation.) The example below, plus examples for COBOL versions 1.x and 2.x, are included in an application note titled “COBOL 1.x-4.00 Printer Control Codes,” which can be obtained from Microsoft Product Support Services.

More Information: A sample program, PRINTESC.CBL, is included with Microsoft COBOL Professional Development System version 4.00. It can be found in the DEMO subdirectory of your COBOL directory. If you did not install the sample programs on your initial setup, you can use SETUP.EXE to select the “All sample programs” component, and then repeat the installation process with only the new component selected. The following is a code example:

IDENTIFICATION DIVISION. PROGRAM-ID. printcodefor3. * * Two-character Printer Control Codes for COBOL V. 3.00 and 4.00 * 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 underline-rec   pic x(20). 01 reset-rec       pic x(20). WORKING-STORAGE SECTION. 77 name-strec           pic x(30). PROCEDURE DIVISION. P00-MAIN-ROUTINE. open output print-file. * *This hex code, Esc@, resets the printer *     move x&quot;1B40&quot; to reset-rec. write print-rec from reset-rec. move &quot;This line is not underlined&quot; to name-strec. write print-rec from name-strec after advancing 2. *  *The hex code below will enable auto-underlining of text. *The code is Esc- *     move x&quot;1B2D&quot; to underline-rec. write print-rec from underline-rec. move &quot;This line is underlined&quot; to name-strec. write print-rec from name-strec after advancing 2. *  *The hex code below will disable auto-underlining of text. *The code is Esc@ *     move x&quot;1B40&quot; to underline-rec. write print-rec from underline-rec. close print-file. stop run. Copyright Microsoft Corporation 1991.