Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 36 - May 10, 2002

Automatically Hold Large Reports

Hey, Ted:

I would like to share a utility with your readers.

If a report has a lot of pages, it will occupy the printer for a while, so other reports, which might have higher priority, must wait until the 'big' one is printed. The problem with holding spooled files manually is that the spooled file needs to be held before the report starts printing. If the report is already printing it can still be put on hold, but then an operator has to realign the printer, so the next report will be printed with correct alignment.

We determined that it would be a good operations practice to automatically hold large reports. I wrote an RPG program that, based on total number of pages, can put a spooled file on hold and send a message to the QSYSOPR message queue to notify an operator that this report was put on hold due to its size.

To use the utility, which I call XXHOLD, create a data area named HOLDPAGES. It will store a 3-digit decimal value with no decimal places. If the number of pages in a spooled file reaches this value, the program places the report on hold and notifies the operator that the report was held. Set this data area to a value of your choosing:

CRTDTAARA DTAARA(xxx/HOLDPAGES) +
   TYPE(*DEC) LEN(3 0) VALUE(200)

The parameters needed to hold a spool file are job name, spooled file name, and spooled file number. XXHOLD uses this information to determine how many pages of output were generated.

You will need two source members--one for the procedure prototype and one for the program. Here is the prototype, which I place in member XXHOLD in source physical file PROTOTYPES:

D XXHold          pr                  extpgm('XXHOLD') 
D   QualJobName                 26    const            
D   SplFileName                 10    const            
D   SplFileNr                   10i 0 const           

The second source member is for the program itself:

H DEBUG(*YES) datfmt(*iso) option(*srcstmt: *nodebugio)
 * 

==============================================================
 *
 *-  Program......: XXHOLD.
 *-  Designed.by..: VICTOR PISMAN
 *-  Version.nbr..: 000.00
 *
 *-  Copyright - North American Paper Company, 2001
 *
 *-  General Description:·This program holds a spool file and
 *-                       sends a message to QSYSOPR
 * 

==============================================================
 * Passed parameters....: Qualified job name
 *                           * = this job
 *                        Spooled file name
 *                        Spooled file number
 *                           0 = *ONLY
 *                          -1 = *LAST
 * 

==============================================================
D Cmd             S            256
D hPageNr         S              3  0 dtaara(holdpages)
D
D QCmdExc         pr                  extpgm('QCMDEXC')
D  Command                     256    const
D  CommandLen                   15p 5 const
D
D QUsrSplA        pr                  extpgm('QUSRSPLA')
D  Receiver                    144
D  ReceiverLen                  10i 0 const
D  SplFileFmt                    8    const
D  QualJobName                  26    const
D  IntJobID                     16    const
D  IntSplFID                    16    const
D  SplFName                     10    const
D  SplFNbr                      10i 0 const
D  ErrorDS                      15
D
D ErrorDS         ds            15
D  BytesProvided                10i 0 inz(%size(ErrorDS))
D  BytesAvail                   10i 0
D  ErrorID                       7
D
D Receiver        ds           245
D  SplFileNr             77     80i 0
D  PageNr               141    144i 0
D  Program              236    245

D*ENTRY PLIST
 /copy prototypes,xxhold
 *
D XXHold          pi
D   QualJobName                 26    const
D   SplFileName                 10    const
D   SplFileSelec                10i 0 const
 *
 * Retrieve critical number of pages to hold printing of the report.
C                   in        hPageNr
 *
 * Retrieve number of pages in report, along with spool file
 *    number and name of the program that generated the spool file
C                   Callp     QUsrSplA (Receiver: 

%len(Receiver):
C                                 'SPLA0100': QualJobName:
C                                  *blanks: *blanks:
C                                  SplFileName: 

SplFileSelec:
C                                  ErrorDS)
 *
C                   If        ErrorID <> *blanks
C                   Eval      *inlr = *on
C                   Return
C                   Endif
 *
 * If number of pages is greater or equal to critical number
 * then put printing of the report on hold and notify QSYSOPR.
C                   If        PageNr >= hPageNr
 *
C                   Eval      Cmd='HLDSPLF 

FILE('+SplFileName+
C                             ') JOB('+%trim(QualJobName+') 

SPLNBR('+
C                             %char(SplFileNr)+')')
C                   Callp     QCmdExc (Cmd:%len(Cmd))
 *
C                   Eval      Cmd='SNDMSG MSG('''+
C                             'Printing of ' +
C                             %trimr(SplFileName)+
C                             ' is on hold due to the 

number'+
C                             ' of pages.'') 

TOUSR(QSYSOPR)'
C                   Callp     QCmdExc (Cmd:%len(Cmd))
 *
C                   Endif
 *
C                   Eval      *inlr = *on
C                   Return

To compile the program, use the Create Bound RPG Program (CRTBNDRPG) command:

CRTBNDRPG PGM(xxx/XXHOLD)  +
   SRCFILE(xxx/QRPGLESRC) +
   SRCMBR(XXHOLD)      

A program that produces a report that may need to be held requires only two lines of source code to invoke XXHOLD.

The first is a copy directive to include the procedure prototype

 /copy prototypes,xxhold

The second is the call. In the second parameter, place the name of the printer file:

C                   callp     XXHold ('*': 'XXPRTFILE': -1)

Call XXHOLD immediately before the program ends, when all pages have been generated.

Here is a program you can use for testing. I call it XXPRINT:

Fqsysprt   o    f  132        printer oflind(*inof)
 * Program information Data Structure
DPGMDS           SDS
D PgmID             *PROC
D ErrmsgID               40     46
D Errmsg                 91    169
D JobName               244    253
D UserID                254    263
D JobNr                 264    269  0
 *
D PageNr          S              4  0
D SplFile         S             10
D JobNrChar       S              6
D LoopNrChar      S              4
D LoopNum         S              4s 0
D Count           S              4  0 inz(1)
 *
 /copy prototypes,xxhold
 *
C     *entry        plist
C                   parm                    LoopNum
 *
C                   Dow       Count <= LoopNum
C                   except    Header
C                   Eval      Count = Count + 1
C                   Enddo
 *
 * Before ending program, check to see if the report should
 * be put on hold because of large number of pages.
C                   callp     XXHold ('*': 'QSYSPRT': -1)
 *
C                   Move      *on           *inlr
Oqsysprt   e            header         1  5
O                                              'Page'
O                       page             +   1

To call the test program, pass one parameter--a four-digit number of pages to generate--in single quotes:

call xxprint '0125'

-- Victor Pisman

Sponsored By
ALDON COMPUTER GROUP


Free Whitepaper on
Application Modernization Through Multi-Platform Development.

Aldon Computer Group, the industry leader in multi-platform change management, offers a cutting-edge solution for companies seeking e-business success. Aldon Affiniti is the only application development tool that allows you to manage all your code, whether RPG, JAVA, COBOL, C++, or anything else from ONE single screen.

Find out more today at www.aldon.com . (And while you're at it, don't forget to sign up for a FREE online seminar on multi-platform development.)

THIS ISSUE
SPONSORED BY:
Advanced Systems Concepts (ASC)
Aldon Computer Group
BACK ISSUES
TABLE OF CONTENTS
Table-Driven Programming
Automatically Hold Large Reports
Reader Feedback and Insights: CSV and SQL Utilities from a Reader
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 5/10/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.