Opening and closing ReportWriter printer channels

You can overload ReportWriter’s default printer interface with user-supplied routines to open and close the output channel for the Print report and Generate report file functions.

RW_PRTOPEN_METHOD

subroutine RW_PRTOPEN_METHOD
a_channel       ,n      ;Returned as the channel for output (d2)
a_file          ,a      ;Either name of report file to generate, if
                        ; print_flag is zero, or unique filename 
                        ; that may be used for temporary file storage,
                        ; if print_flag is nonzero (a30)
a_prnt_flg      ,n      ;Indicates whether report is being printed (d1)
                        ; 0   Generate report file; do not print it.
                        ; 1   Print report.
a_quit          ,n      ;Returned with true if no further report 
                        ; generation should occur (d1)
a_mode          ,n      ;Optional, file open mode. If passed and nonzero
                        ; output file will be opened in append mode. 
                        ; Otherwise, it will be opened in creation mode (d1)

Use RW_PRTOPEN_METHOD to open a file and output channel for printing. The version of this routine linked with the original ReportWriter distribution opens the specified file and returns the channel. If an error occurs on open, a_quit is returned with the error code. Any user-overloaded version of this routine should at minimum perform these functions. ReportWriter outputs the report to the channel returned in a_channel, using the Synergy DBL WRITES and FORMS statements.

This is the version of RW_PRTOPEN_METHOD that is linked with your original ReportWriter distribution.

subroutine rw_prtopen_method
;
; Description:  Printer open routine for ReportWriter
;
; Arguments:
;
    a_chan              ,n      ;Output channel (incoming unassigned)
    a_file              ,a      ;A unique filename which may be used
    a_qflg              ,n      ;Queue flag - 1 = Print, 0 = Create file
    a_quit              ,n      ;Returned true if no further report generation should occur
    a_mode              ,n      ;Optional file open mode 
.include "WND:tools.def"
.include "RPT:rptmsg.def"
.include "DBLDIR:dbl.def"
record
    line                ,a80
    linlen              ,d2
proc
.ifdef D_VMS
    ;If this is printing on an OpenVMS system, use the O:S format
    if (a_qflg) then
      line = "/SI=96/DEQ=96/BUFNUM=2/BUFSIZ=16/IO=O:S"
    else
.endc
    ;Part of the above 'else'
    clear line
    if (%passed(a_mode)) then
      begin
        if (a_mode) then
            xcall u_open(a_chan, 'A', a_file, line,, a_quit)
        else
            xcall u_open(a_chan, 'O', a_file, line,, a_quit)
      end
    else
      xcall u_open(a_chan, 'O', a_file, line,, a_quit)
    if (a_quit)
      begin
        xcall ru_sbld(line, linlen, MSG_OOPNERR, a_file)
        xcall u_message(line(1:linlen), D_ERROR)
      end
    xreturn
endsubroutine

RW_PRTCLOSE_METHOD

subroutine RW_PRTCLOSE_METHOD
a_chan          ,n      ;Channel used for output (d2)
a_file          ,a      ;Filename passed to RW_PRTOPEN_METHOD (a30)
a_pflg          ,n      ;Indicates whether report is being printed (d1)
                        ; 0   Generate report file; do not print it.
                        ; 1   Print report.

Use RW_PRTCLOSE_METHOD to close the channel used for printing and the file. The version of this routine linked with the original ReportWriter distribution closes the channel specified by a_chan, and if a_pflg is true, the file specified by a_file is submitted to the queue via the Synergy DBL LPQUE statement. At a minimum, any user-supplied version of this routine must close a_chan.

This is the version of RW_PRTCLOSE_METHOD that is linked with your original ReportWriter distribution.

subroutine rw_prtclose_method
;
; Description:  ReportWriter printer close routine 
;
; Arguments:
;
    a_chan              ,n      ;Channel on which output performed
    a_filnam            ,a      ;Filename passed to RW_PRTOPEN_METHOD
    a_qflg              ,n      ;0 = Generating report file; don't print
                                ;1 = Output to printer
.include "WND:tools.def"
.include "RPT:rptmsg.def"
proc
    xcall u_close(a_chan)
    if (a_qflg)
      begin
        xcall e_state(D_ON, D_INTR)             ;Allow interrupt
        onerror noprt 
        lpque(a_filnam, DELETE)
        offerror
        xcall e_state(D_OFF, D_INTR)            ;Disallow interrupt
      end
    xreturn

noprt,
    offerror    
    xcall ru_message(MSG_NOPNTR, D_ERROR)
    xcall e_state(D_OFF, D_INTR)        ;Disallow interrupt
    xreturn
endsubroutine

Here’s another example:

subroutine rw_prtclose_method
;
;Description: Processes printer close for ReportWriter
;
;Arguments:
;
    a_channel           ,n      ;Channel used for output. Must be closed by routine
    a_filename          ,a      ;Filename passed to RW_PRTOPEN_METHOD
    a_genprt            ,n      ; 0 - Generate report file - do not print
                                ; 1 - Printer output
;
;Notes:
;       This subroutine is called when ReportWriter is finished 
;       generating a printed report.
;
;       This routine requires an external file that has the following
;       format:
;
;       "Name you want user to see", "LPQUE queue name"
;
;       In other words, the format is a single quoted string with the name
;       you want your users to see, followed by a comma, followed by 
;       another quoted string with the queue name LPQUE uses for printing
;       on the particular device.
;
;       This file is named PRT:print.lst, although you can change the 
;       filename by changing the OPEN statement in the fifth line after 
;       the PROC statement.
;
;       In addition, the following needs to be placed in the window script
;       file opened as win_libchn:
;
; --------------------------------------------------------
;
; print.wsc - window script file for rw_prtclose_method
;
;---------------------------------------------------------
;;
;; Menu column definition
;;
;.column s_select, "Selection functions"
;.entry s_down, "Next selection", key(down)
;.entry s_up, "Prior selection", key(up)
;.end
; --------------------------------------------------------
;
.include "WND:tools.def"
.include "WND:windows.def"
.define ITEMS, 10
.align
static record
    win_libchn          ,i4     ;Window library channel
    colid               ,i4     ;Column ID for input window
    wndid               ,i4     ;Input window ID
    list_ix             ,i4     ;List index
 
    name                ,ITEMS a30      ;List of printer names
    device              ,ITEMS a15      ;List of printer system device names
.align
record
    file_chn            ,i4     ;File channel
    error               ,i4     ;Error number
    start_loc           ,i4     ;Start of parse string
    end_loc             ,i4     ;End of parse string
    sel_printer         ,i4     ;Selected printer
    status              ,i4     ;Status of routine
    prt_name            ,a40    ;Printer name
    prt_device          ,a15    ;Printer's device name for operating system
    wnd_name            ,a25    ;Window name
    buffer              ,a80    ;Buffer for buffered output
    item_pos            ,ITEMS d2       ;Item position list for s_parse
    item_length         ,ITEMS d2       ;Item length list for s_parse
    item_type           ,ITEMS d2       ;Item type list for s_parse
    num_items           ,d2             ;Number of items for s_parse
proc
    xcall u_close(a_channel)
    if (.not.list_ix)                   ;Has list been loaded?
      begin
        xcall u_open(file_chn, 'I', "PRT:print.lst",,, error)
        if (error)
          goto no_print
        repeat
          begin
            reads(file_chn, buffer, err)
            if (buffer(1:1).eq.';')             ;Comment line
              nextloop
            call get_prtinfo
            incr list_ix                ;Load lists
            name[list_ix] = prt_name
            device[list_ix] = prt_device
          end
err,
        xcall u_close(file_chn)
      end
    if (.not.win_libchn)                ;Has window library been loaded?
      begin
        xcall u_open(win_libchn, 'I:I', "PRT:print",,, error)
        if (error)
          goto no_winlib
      end
    xcall e_enter
    xcall m_column(D_REMOVE, D_LOCAL)   ;Remove unprocessed columns
    xcall m_ldcol(colid, win_libchn, "s_select", D_NOPLC)
    if (.not.wndid)
      xcall s_selbld(wndid, 'PRINTERS', list_ix, 15, name)
    xcall w_brdr(wndid, WB_TITLE, "Select a printer", WB_TPOS, WBT_TOP, WB_TON)
    xcall u_window(D_PLACE, wndid, 5, 5)
    while (.not.sel_printer) do
      begin
        xcall s_select(wndid, 1,, colid, sel_printer)
        case (g_entnam) of
          begincase
            "O_EXIT": exitloop
            "O_CANCEL": exitloop
          endcase
        else
          begin
            xcall u_beep
            nextloop
          end
      end
    if (.not.sel_printer)
      begin
        xcall u_message("No printer was selected,using default printer.")
        sel_printer = device[1] 
      end
    if (FALSE)
      begin
no_winlib,
        xcall u_message("PRT:print was not found,using default printer.")
        sel_printer = device[1]
      end
    if (a_genprt)
      begin
        xcall e_state(D_ON, D_INTR)
        onerror ($ERR_IOFAIL) no_print
        lpque(a_filename, LPNUM:device[sel_printer], DELETE)
        offerror
        xcall e_state(D_OFF, D_INTR)            ;Disallow interrupt
      end
cleanup,
    xcall e_exit
    xreturn
get_prtinfo,
    xcall s_parse(buffer, start_pos, 10, item_pos, item_length, 
  &               item_type, num_items, end_pos)
    return
no_print,
    xcall u_message("File not printed.  Filename was: " + a_filename)
    goto cleanup
endsubroutine