COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
30 Printer and Spooler Output
There are two ways that a process can write a report to paper: it can write directly to a printer or
it can write to a spooler collector.
When a process writes directly to a printer, it has exclusive use of the printer from the time it opens
the file until the time it closes the file.
When a process writes to a spooler collector, the spooler collector accumulates the lines of the
report on a disk and does not engage a printer until the process closes the file.
Some installations insist that processes write only to a spooler, because this can even out the printer
usage or speed up jobs that would be output bound if they had to wait for a slow printer.
An installation can configure its spooler locations such that a printer is either accessible only to
the spooler and never by other processes or accessible to other processes whenever the spooler
is not using it.
HP has no file structure that is strictly for printer files. To establish a COBOL file for use with a
printer, declare it to have sequential organization and to be accessed sequentially.
Using a Printer Directly
Each installation chooses names for its printers. To write to a printer, an HP COBOL program
declares a file with sequential organization and sequential access and associates that file with the
printer device name.
The HP COBOL process tries to open the printer file with the open mode OUTPUT or EXTEND. If
the printer is not available, the OPEN statement fails with file status code “30” and a run-time
error. The HP COBOL run-time routines deliver a diagnostic message to the process’ home terminal.
If no declarative procedure is available for the printer file, the process terminates. If a declarative
procedure is available for the printer file, the declarative procedure can examine the special
register, GUARDIAN-ERR, and take appropriate action.
GUARDIAN-ERR contains the file-system error number that specifies the reason the printer was not
available. Typical values for GUARDIAN-ERR are 14 (device does not exist) and 12 (file in use).
If the file is in use, the process can call the operating system routine DELAY to let some time pass
and then try the open operation again.
If the printer is available, the open operation succeeds, and the process can go ahead and write
to the printer. By default, an HP COBOL program opens a printer file with exclusion mode
EXCLUSIVE. All other processes that attempt to write to the printer are excluded until the process
that has the printer open closes it.
Understanding Spoolers
The HP spooler is a set of processes that acts as an interface between the print devices of a system
and the users and their application programs. A spooler receives output from a process and stores
it on disk, queued for delivery to a print process. This unit of storage is called a job.
For more information on spoolers, see the Spooler Programmer’s Guide.
Spooler Components
The spooler has these components:
• Supervisor Process
• Collector Process
• Print Process
Using a Printer Directly 899










