Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 7 - January 30, 2002

Retrieve a Spool File
Number

Hey, Ted:

Is there a way to retrieve the number the system assigns to a spooled file? Some commands, such as the Copy Spooled File (CPYSPLF) command, allow me to use the special value *LAST to access the highest-numbered spooled file of a certain name. But if I could retrieve the spooled file number, I could do other good things, such as allow other jobs to retrieve and use the spooled file.

-- Moe

Sure, Moe. It's possible. Use the Retrieve Spooled File Attributes API, QUSRSPLA. It returns a data structure packed full of goodies, including the spooled file number.

The following CL program produces two reports, both of which are named QSYSPRT. That is, the RPG programs that produce these reports write to printer file QSYSPRT. After the first RPG program runs, the CL program retrieves the spooled file number. After the second RPG program runs, the CL submits program SPLF03C (given below) to batch, passing parameters containing the job information, spooled file name, and spooled file number. The batch job uses this information to retrieve the spooled file.

PGM

DCL  &SPLFNBR   *CHAR   4
DCL  &WHICHSPLF *CHAR   4
DCL  &RCVLEN    *CHAR   4
DCL  &RECEIVER  *CHAR  80
DCL  &JOBNAME   *CHAR  10
DCL  &JOBUSER   *CHAR  10
DCL  &JOBNBR    *CHAR   6

/* Get identifying info for this job */
RTVJOBA    JOB(&JOBNAME) USER(&JOBUSER) NBR(&JOBNBR)

/* Generate first report */
CALL       PGM(RPGPGM1)

/* Get spool file number of report just produced */
CHGVAR     VAR(%BIN(&WHICHSPLF)) VALUE(-1)
CHGVAR     VAR(%BIN(&RCVLEN)) VALUE(80)
CALL       PGM(QUSRSPLA) PARM(&RECEIVER &RCVLEN +
             'SPLA0100' '*' ' ' ' ' QSYSPRT &WHICHSPLF)
CHGVAR     VAR(&SPLFNBR) VALUE(%BIN(&RECEIVER 77 4))

/* Generate second report */
CALL       PGM(RPGPGM2)

/* Tell another program about the first report */
SBMJOB     CMD(CALL PGM(SPLF03C) PARM(&JOBNAME &JOBUSER +
             &JOBNBR QSYSPRT &SPLFNBR)) JOB(THOLTTEST) 
ENDPGM

Here's SPLF03C, the CL program that runs in batch and accesses the report generated in the other CL program:

PGM        PARM(&JOBNAME &JOBUSER &JOBNBR &FILENAME +
              &SPLFNBR)

DCL        VAR(&SPLFNBR) TYPE(*CHAR) LEN(4)
DCL        VAR(&FILENAME) TYPE(*CHAR) LEN(10)
DCL        VAR(&JOBNAME) TYPE(*CHAR) LEN(10)
DCL        VAR(&JOBUSER) TYPE(*CHAR) LEN(10)
DCL        VAR(&JOBNBR) TYPE(*CHAR) LEN(6)

CPYSPLF    FILE(&FILENAME) TOFILE(SPOOLFILE) +
             JOB(&JOBNBR/&JOBUSER/&JOBNAME) +
             SPLNBR(&SPLFNBR) CTLCHAR(*PRTCTL)
ENDPGM

If there's a possibility that the spooled file won't be there, monitor for message CPF34C0. However, the best way to handle such a situation is to make sure that the Retrieve Spooled File Attributes (QUSRSPLA) API doesn't run if the report is not produced. To find out more about the QUSRSPLA API, visit the iSeries 400 Information Center. Click on the following topics in the navigation pane (located on the left side of the Web page):

  • Programming
  • CL and APIs
  • APIs
  • APIs by category

In the APIs by category list, choose the Print link. On the Print APIs page, click on the Spooled file APIs link. QUSRSPLA is the last API on the Spooled Files API page.

-- Ted

Sponsored By
LANSA

LANSA INTEGRATOR SPEEDS DEVELOPMENT & PERFORMANCE OF JAVA

LANSA Partner MDC replaced its hand-written Java remote system integration programs with LANSA Integrator and gained a tenfold increase in performance. InsureIT uses LANSA Integrator to offer XML Java services between heterogeneous insurer & broker systems.

Find out more at http://www.lansa.com/press/20122.htm

THIS ISSUE
SPONSORED BY:
WorksRight Software
LANSA
BACK ISSUES
TABLE OF CONTENTS
Journaling Changed
Bytes Only
Retrieve a Spool File
Number
Reader Feedback and Insights
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 1/30/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.