Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
In a particular program, I am creating a new spool printer file when the account number changes, by doing a close of the current printer file and opening a new one.
How do I capture the spool file number of the print job, within an RPG program?
Thanks in advance,
WCG
If you have COZTOOLS installed:
H BNDDIR('COZTOOLS') /include cozTools/qcpysrc,spool D splfName S 10A D splNbr S 10I 0 /free ... do whatever here close QPRINT; getSPLFID( '*LAST' : '*' : -1 : SPLFNAME : SPLNBR);
This will return the SPOOL File name and number of the most recently created SPOOL file.
We also created a getLastSPLF( ... ) function too, where it just returns the info of the last SPLF--basically a wrapper for the above call. It returns the SPLNBR to you, and also accepts return parms for the SPLFNAME, Internal JOB ID and SPLNBR.
It's in the Open Feedback of the PRINTER file, so you'll need an INFDS. It's at position 160, 4-byte binary, so 10I 0. (See ILE RPG Ref, Ch. 5, File and Program Exception/Errors.) Make sure you get the 6 digit spool nbr, not the old 4-digit field.
Dale, wow! Forget about that one.
WCG, here's the /COPY from COZTOOLS of the INFDS PRT data structure in the INFDSPRT member:
F* exPrtf O F 132 PRINTER INFDS(MYINFDS) D* myINfds DS LikedS(coz_INFDSPRT_T) D coz_infdsPRT_T DS Qualified D splfName 10A overlay(coz_infdsPRT_T:103) D splfLib 10A overlay(coz_infdsPRT_T:113) D SPLNUM 5I 0 overlay(coz_infdsPRT_T:123) D SPLNBR 10I 0 overlay(coz_infdsPRT_T:160) D lines 5I 0 overlay(coz_infdsPRT_T:152) D columns 5I 0 overlay(coz_infdsPRT_T:154) D overflowLine 5I 0 overlay(coz_infdsPRT_T:188)
The file spec is a sample of using the INFDS with the PRINTER file. The MYINFDS is commented out but is also an example of how to declare it. Then the data structure itself is listed. Normally, if you had COZTOOLS DE installed, you just do the following:
FMyexPrtf O F 132 PRINTER INFDS(MYINFDS) /include cozTools/qcpysrc,infdsprt D myInfds DS LikeDS(coz_INFDSPRT_T) /free mySPLNBR = myinfds.splNbr;
In the context of the same program where the SPOOL file is declared, you can retrieve the "current" SPLNBR. If you need to get the *LAST SPOOL Nbr regardless of where the SPOOL file was created in this job, you'll need to call the COZTOOLS function mentioned above.