The API Corner: Determining the Last Spool File Created

APIs
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The QSPRILSP API can simplify your access to a job's most recent spool file.

 

Last month, in "Just How Many Spool Files Do You Have?," we looked at the Retrieve Spool Information API QSPSPLI. I received quite a bit of feedback on the article—some suggesting a follow-on topic, others reporting a problem they were running into.

 

The "problem" feedback started the same day the article was published and was related to incorrect output. Alan L., the first to report the problem, wrote that while the sample program and API worked fine when accessing the number of spool files with a special value such as *CURRENT and a user name such as VINING, it failed to return the correct number of spool files for a user profile name such as AADDONOHUE. The name and number of spool files displayed would be AADDONOH and 0, respectively. This problem, truncating the user name to 8 bytes while accessing the number of spool files, was reported to IBM, and PTFs are being provided: SI44375 for 6.1 and SI44376 for 7.1.

 

Several readers were also interested in finding out if there is an easy way to determine what spool file was the last one created by a job. In many cases, this was related to automating the sending of "incorrect output" to support personnel, though other scenarios were also mentioned. This feedback leads us to the Retrieve Identity of Last Spool File Created (QSPRILSP) API.

 

The QSPRILSP API, first introduced with V5R2, returns the complete spool file identity of the last spool file created by the current job/thread. The API defines four parameters: a receiver variable where the identity information is returned, the size of the receiver variable, the format of the identity information to be returned, and the standard API error code.

 

The following sample program, utilizing the QSPRILSP API, demonstrates displaying the most recently created spool file name, owning job, and spool file number.

 

dGetLstSplFID     pr                  extpgm('QSPRILSP')           

d RcvVar                         1    options(*varsize)            

d LenRcvVar                     10i 0 const                        

d FmtRcvVar                      8    const                        

d QUSEC                               likeds(QUSEC)                

                                                                   

dWait             s              1                                  

                                                                   

 /copy qsysinc/qrpglesrc,qsprilsp                                  

 /copy qsysinc/qrpglesrc,qusec                                     

                                                                    

 /free                                                             

                                                                   

  QUSBPrv = 0;                                                     

                                                                    

  GetLstSplFID(QSPL0100 :%size(QSPL0100) :'SPRL0100' :QUSEC);      

                                                                   

  dsply ('Last file created is: ' + QSPSN03);                       

  dsply (' for job ' + %trimr(QSPJN00) + '/' +                     

          %trimr(QSPUN00) + '/' + QSPJNBR00);                      

  dsply (' Spool file number is ' + %char(QSPSNBR03)) ' ' Wait;    

                                                                    

  *inlr = *on;                                                     

  return;                                                          

                                                                   

 /end-free                                                          

 

The QSYSINC source member QSPRILSP is copied into the sample program using the /copy directive and provides the following variable definitions (several of which are used by the sample program):

 

D****************************************************************  

D*Structure for SPRL0100 format                                    

D****************************************************************  

DQSPL0100         DS                                                

D*                                             Qsp SPRL0100        

D QSPBR03                 1      4B 0                              

D*                                             Bytes Return        

D QSPBA03                 5      8B 0                              

D*                                             Bytes Avail         

D QSPSN03                 9     18                                 

D*                                             Splf Name           

D QSPJN00                19     28                                 

D*                                             Job Name            

D QSPUN00                29     38                                 

D*                                             Usr Name             

D QSPJNBR00              39     44                                 

D*                                             Job Number          

D QSPSNBR03              45     48B 0                          

D*                                             Splf Number     

D QSPJSN                 49     56                             

D*                                             Job System Name 

D QSPDFILO               57     63                             

D*                                             Date File Open  

D QSPERVED08             64     64                             

D*                                             Reserved        

D QSPTFILO               65     70                             

D*                                             Time File Open               

 

To compile the program, assuming that your source member is named LSTSPLFID and can be found in source file *LIBL/QRPGLESRC, you might use this command:

 

CRTBNDRPG PGM(LSTSPLFID)

 

Calling the LSTSPLFID program will then display information about the last spool file created, as in this example:

 

DSPLY  Last file created is: LSTSPLFID    

DSPLY   for job QPADEV0005/VINING/093336  

DSPLY   Spool file number is 1

 

Having seen how easy it is to access the identity of the last spool file created, you can now, with the use of an API such as Process Commands (QCAPCMD), rapidly work with the spool file using CL commands such as Send Network Spool File (SNDNETSPLF), Copy Spooled File (CPYSPLF), Change Spooled File Attributes (CHGSPLFA) to move the report to a designated output queue, etc. If you would like a refresher on the QCAPCMD API (along with other similar APIs), you can review the series of articles starting with "Do I Really Need to Call a CL Program to Perform This Function?"

 

As usual, if you have any API questions, send them to me at This email address is being protected from spambots. You need JavaScript enabled to view it.. I'll see what I can do about answering your burning questions in future columns.

as/400, os/400, iseries, system i, i5/os, ibm i, power systems, 6.1, 7.1, V7, V6R1

Bruce Vining

Bruce Vining is president and co-founder of Bruce Vining Services, LLC, a firm providing contract programming and consulting services to the System i community. He began his career in 1979 as an IBM Systems Engineer in St. Louis, Missouri, and then transferred to Rochester, Minnesota, in 1985, where he continues to reside. From 1992 until leaving IBM in 2007, Bruce was a member of the System Design Control Group responsible for OS/400 and i5/OS areas such as System APIs, Globalization, and Software Serviceability. He is also the designer of Control Language for Files (CLF).A frequent speaker and writer, Bruce can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it.. 


MC Press books written by Bruce Vining available now on the MC Press Bookstore.

IBM System i APIs at Work IBM System i APIs at Work
Leverage the power of APIs with this definitive resource.
List Price $89.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: