Printing Under MS-DOS

Many COBOL applications need to be able to launch a print job from the MS-DOS operating system. In MS-DOS you typically use the devices furnished by the environment: PRN or LPTx.

To assign a print job to a physical device, you usually declare that device in the SELECT clause. The declaration is similar to the following:


This declaration causes print jobs to be sent directly to the physical device. If the printer goes down, the BIOS interrupts the print job, which can cause some difficulties.

Suppose that a user takes the printer off-line or even switches it off to change paper. When this happens, the Acucobol runtime generates a "30,xx" error (permanent error), which the programmer can recognize as a printer error and can correct with a reset. However, a problem remains. Between the printing interruption and the reset of the print device, some characters could be lost. This is certainly undesirable, and possibly harmful.

Let's take a look at some potential solutions.

Using the MS-DOS PRINT Spooler

The first possible solution is to use the MS-DOS operating system's PRINT spooler, to manage the printing in the background. The spooler can be managed directly from your program or from the runtime configuration file. To accomplish this, use the following syntax:

In the SELECT statement:

Or, you could specify:

and then add this line to the runtime configuration file:

The symbol %TMP% is a placeholder for the name of a temporary file that is created for you. You need to use this temporary file "%TMP%" because the PRINT command does not use standard-input to receive the lines to be printed.

It is also possible to select other printer commands instead of PRINT and still use the same syntax.

Use of the MS-DOS MODE command

If you must address the printing device directly, another solution is to use the MS-DOS MODE command. This causes the printing characters to be held until the printer is reset, so that nothing is lost. The syntax of this setting is:


In this mode, the BIOS does not interrupt the print program, even if the printer is turned off. It waits to send the characters until the printing device has been reset. This solves the problem without any change to your COBOL program.


Here's a tip for those of you who are using ACUCOBOL®-GT Version 3.0. The Windows environment offers speed keys that enable you and your end users to Cut or Copy into a buffer and then Paste the contents of that buffer at a new location. For example, a user might copy the contents of one entry-field into another entry-field. Here are the speed-key sequences:

CTRL + X (Cut)
CTRL + C (Copy)
CTRL + V (Paste)

If you have any suggestions or questions for this "Tips and Tricks" column, please let us know! We hope these hints will be useful to you!

Your Session will expire in 90 minutes
Notification will be shown in:
600 seconds