Printing Multiple Jobs Simultaneously

If you need to print multiple jobs at the same time, you must open multiple File Descriptors that point to -P SPOOLER or -P SPOOLER-DIRECT simultaneously. For example, you may have two simultaneous print jobs:

SELECT FIRST-FILE
       ASSIGN TO PRINTER "-P SPOOLER".

SELECT SECOND-FILE
       ASSIGN TO PRINTER "-P SPOOLER".

..

PROCEDURE DIVISION.

..

       OPEN OUTPUT FIRST-FILE.
       OPEN OUTPUT SECOND-FILE.

and both will print to the default Windows printer without interfering with each other. You can call WIN$PRINTER using WINPRINT-SETUP or WINPRINT-SETUP-USE-MARGINS before one or both of the OPEN statements. Each file may have individual file status variables, or may refer to a common file status variable.

This does not mean that you can open a single File Descriptor multiple times. For example, the following will return file status indicating that the file is already opened:

SELECT FIRST-FILE
       ASSIGN TO PRINTER "-P SPOOLER".

..

PROCEDURE DIVISION.

..

       OPEN OUTPUT FIRST-FILE.
       OPEN OUTPUT FIRST-FILE.

This is normal behavior and is consistent with the way file handling is implemented in COBOL and in other programming languages.

If you are using only the verbs OPEN, CLOSE, and WRITE, no further changes to your code are needed. If you are using WIN$PRINTER (other than WINPRINT-SETUP or WINPRINT-SETUP-USE-MARGINS), you need to specify which print job is affected. This can be done in one of two ways:

  1. The simplest way is to execute the WIN$PRINT operation immediately after an OPEN or WRITE statement on the intended job. Every execution of OPEN and WRITE sets the current job as the default so that subsequent activity using WIN$PRINTER is automatically directed to the job that was last accessed with an OPEN or WRITE statement.

    In this situation, if you have multiple jobs running, and you close one of them, the runtime switches to the next job in the list. For example, if you are printing jobs 1, 2, and 3, and you close job 2, the close command sets the current job to 3. If there is no job 3, the runtime attempts to set to the job that preceded the closed job (which in this case is job 1). If there are no jobs, the current job is initialized.

  2. The other method is to use the WINPRINT-SET-JOB operation of the WIN$PRINTER library routine.