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
as/400, os/400, iseries, system i, i5/os, ibm i, power systems, 6.1, 7.1, V7, V6R1
LATEST COMMENTS
MC Press Online