CPYSPLF and AFPDS
February 23, 2005 Ted Holt
Printing is one of the primary concerns of people who use computers for what I still refer to as data processing, so it’s no wonder I have received a good bit of mail in response to printing-centric articles such as Page 1 of X, Reading Spool Files in RPG, and Extract Reports from Disk Files. Since packaged software is so widely used in installations staffed by readers of this publication, several people have asked about a CPYSPLF equivalent that works with AFPDS. Today, I address that issue.
At least one astute reader of this publication pointed out that the Page 1 of X tip only worked with SCS spooled files. I couldn’t agree more. The Copy Spooled File (CPYSPLF) command only copies SCS spooled files. So what do you do when you want to read an IPDS or AFPDS spooled file that was produced by some package to which you have no source code? I recently and reluctantly dragged my lazy self out of bed to determine the answer to this question, mainly because one of my superiors told me to.
I did not like the first solution I found–the Get Spooled File (QSPGETSP) API. QSPGETSP is plenty capable of reading an AFPDS spooled file, but the complexity of this API rivals the instructions that accompany the U.S. federal income tax return. None of that for me.
Then I discovered something interesting. One would think–or at least I thought–that the type of spooled file produced–SCS, IPDS, or AFPDS–is determined when the printer file object is created. Well, I was wrong. I found that the type of spooled file is determined at runtime.
The solution is to change or override the DEVTYPE attribute of a printer file so that it produces an SCS spooled file instead of an AFPDS spooled file. (I assume the same can be said of IPDS spooled files, but I was not able to test it to be sure.)
CHGPRTF FILE(SomePrtf) DEVTYPE(*SCS) OVRPRTF FILE(SomePrtf) DEVTYPE(*SCS) CALL SomePgm DLTOVR FILE(SomePrtf)
CPYSPLF will happily copy the text portion of the report to a disk file, which you can read and massage any way you like with a program written in your high-level language of choice.
–Ted
Click here to contact Ted Holt by e-mail.