Writing a Printer Exit

An example of a printer exit module, sampprnx.cbl, is provided in the \src\enterpriseserver\exits sub-directory of your product installation directory by default. This example simply takes each line and calls the COBOL run-time system's print routines to print it.

Printer exits need not be written in COBOL, but they must handle parameters as illustrated in sampprnx. These parameters are defined and documented in the cascbprn.cpy copybook. COBOL printer exits must be compiled with the non-mainframe dialect, which implies CHARSET(ASCII). They must be also built as an .int, a .gnt, or a .dll.

The linkage section of sampprnx, and the cascbprn.cpy are shown below.

linkage section.
 copy 'cascbprn.cpy' replacing ==(ws)== by ==lk==.
 01 lk-catalog-rec. 
  copy 'mvscatlg.cpy' replacing ==(TAG)== by ==lk==. 
 01 LK-OUTPUT.
  copy mvsdout  replacing ==()== by ==LK-OUTPUT==.
 01 LK-SPOOL.
  copy 'spool.cpy' replacing ==(tag)== by ==lk==.
       01  (ws)-prn-exit-interface.
           *>  What is the format of the structure used to call the
           *>  printer exit.  Will change with major revisions to this
           *>  Data Structure.
           03  (ws)-prn-version                     pic x(4) comp-5.
               88  (ws)-prn-current-version-88      value 1.
           *>  The printer exit is driven once as the batch printer SEP
           *>  starts, once for every print job, and once when the batch
           *>  printer is shut down.
           03  (ws)-prn-command                     pic x    comp-5.
               88  (ws)-prn-exit-init-88            value 0.
               88  (ws)-prn-exit-print-88           value 1.
               88  (ws)-prn-exit-term-88            value 2.
           *>  For the requested print job.  (ws)-prn-exit-print-88
           *>  what is the character set of the data being printed.
           03  (ws)-prn-char                        pic x.
               88  (ws)-prn-char-ascii-88           value 'A'.
               88  (ws)-prn-char-ebcdic-88          value 'E'.
               88  (ws)-prn-char-unknown-88         value '?'.
           *>  This is the file status returned by driving the procedure
           *>  pointers:
           *>              (ws)-prn-sysout-open-pptr
           *>              (ws)-prn-sysout-read-next-pptr
           *>              (ws)-prn-sysout-close-pptr
           *>
           03  (ws)-prn-sysout-status               pic x(2).
               88  (ws)-prn-sysout-status-ok-88     value '00'.
               88  (ws)-prn-sysout-status-eof-88    value '10'.
      ***--------------------------------------------------------------*
           *>  Procedure pointer to drive the open of the sysout dataset
           *>    (ws)-prn-exit-print-88 only
           03  (ws)-prn-sysout-open-pptr            procedure-pointer.
           *>  Procedure pointer to a read of the sysout dataset
           *>    (ws)-prn-exit-print-88 only           
           03  (ws)-prn-sysout-read-next-pptr       procedure-pointer.
           *>  Procedure pointer to drive the close of the sysout dataset
           *>    (ws)-prn-exit-print-88 only           
           03  (ws)-prn-sysout-close-pptr           procedure-pointer.
           *>  Procedure pointer to allow a message to be driven to the 
           *>  console.  (all functions)
           03  (ws)-prn-message-pptr                procedure-pointer.
           *>  Procedure pointer to retrieve the next OUTPUT statement.
           *>  Returns a null (ws)-prn-output-record-ptr if none are 
           *>  available.
           *>    (ws)-prn-exit-print-88 only           
           03  (ws)-prn-output-read-next-pptr       procedure-pointer.
           03                                       procedure-pointer.
           03                                       procedure-pointer.
      ***--------------------------------------------------------------*
           *>  A pointer to the data structure contained in Spool.cpy
           *>    (ws)-prn-exit-print-88 only                 
           03  (ws)-prn-spool-record-ptr            pointer.
           *>  A pointer to the data structure contained in mvscatlg.cpy
           *>    (ws)-prn-exit-print-88 only                      
           03  (ws)-prn-catalog-record-ptr          pointer.
           *>  The printer handle for the printer assigned to the this SEP           
           03  (ws)-prn-printer-handle              pic x(4) comp-5.
           *>  The LRECL of the dataset being printed.
           *>    (ws)-prn-exit-print-88 only                                 
           03  (ws)-prn-lrecl                       pic x(4) comp-5.
           *>  The Maximum LRECL of the dataset being printed.
           *>  Same as ws-prn-lrecl.
           *>    (ws)-prn-exit-print-88 only                                            
           03  (ws)-prn-lrecl-max                   pic x(4) comp-5.
           *>  The Minimum LRECL of the dataset being printed. 
           *>  (Variable Length SYSOUT Datasets.           
           *>    (ws)-prn-exit-print-88 only                                                       
           03  (ws)-prn-lrecl-min                   pic x(4) comp-5.
           03  (ws)-prn-file-disp                   pic x.
           *>  set to '1' to delete spool file on return
           03                                       pic x(3).
           *>  The length of the buffer used to return data when driving 
           *>     (ws)-prn-sysout-read-next-pptr
           *>  (How much data was returned)
           *>    (ws)-prn-exit-print-88 only                                                                             
           03  (ws)-prn-buffer-len                  pic x(4) comp-5.
           03  (ws)-prn-buffer.
               05  (ws)-prn-buffer-byte occurs 384 times pic x comp-x.
           *>  The "MVS" Name of the document being printed.
           *>    (ws)-prn-exit-print-88 only                                                                             
           03  (ws)-prn-document.
               05  (ws)-prn-document-len            pic x(2) comp-5.
               05  (ws)-prn-document-title          pic x(128).
           *>  The name of the batch printer driving this print job.
           03  (ws)-prn-printer.
               05  (ws)-prn-printer-name-len        pic x(2) comp-5.
               05  (ws)-prn-printer-name            pic x(128).
           *>  The "physical" filename for the file being printed.
           *>  (eg.  Where does it reside on the disk pack)
           *>    (ws)-prn-exit-print-88 only                                                                  
           03  (ws)-prn-sysout-file-name            pic x(260).
           *>  A pointer to an OUTPUT Statement associated with this 
           *>  SYSOUT Dataset.  Points to the data structure contained
           *>  in IDADOUTP.CPY
           *>    (ws)-prn-exit-print-88 only                                                                  
           03  (ws)-prn-output-record-ptr           pointer.