tnt400.com - AS/400 Tips And Techniques

Sponsored by news400.com

This page is a discussion on the mentioned topic.
Most of the answers are in their original posted form, including any technical/spelling/grammatical errors.
No guarantees are expressed or implied. :-)
Comments, corrections, concerns about this tip?

Got another AS/400 question? Ask it here


What's New?
See what's new at Tips-N-Tech.

AS/400 Tips-N-Tech
AS/400 tips, techniques, and FAQ. Updated frequently.
CODEPage/400
All the code samples you can eat! RPG, CL, DDS, etc. etc.
AS/400 FAQs
The official news400.com FAQs.






All AS/400 Tip Categories / AS/400 Programming / CPYSPLF Automation


Question:

I had the same question that is posted here many times, about converting a spooled file to a PC file. I can do this manually thanks to the CPYSPLF command and FTP. However, now I want to automate the process, but the piece I'm missing is how to obtain the spool file information in a CLP program to automatically run the CPYSPLF command. There is a lot alluding to this process, but no examples of how to code it. Particularly, I need to be able to get the SPOOL FILE NUMBER, because, for the most part, the JOB and USER name are always constant. Thanks in advance.


Answer(s):



I use both *dtaqs and the APIs, depending on what I need. No weird results with the APIs except when I have more spoolfiles than they can handle. (We routinely have 100,000 or more spoolfiles in our biggest system.) So, I'm now digging into the various 'Open List' APIs to see how they can help.




I just wrote a program that does pretty much the same thing. It constantly monitors an outq. When a new file pops up, it moves the file to a new outq. It is a never ending C/L program that sleeps once in awhile then calls an RPG program to do the dirty work. The heart of it is in the RPG program. Using QCMDEXC it runs WRKOUTQ OUTPUT(*PRINT), then copies that spool file to a data base file. Then it deletes the WRKOUTQ spool file. The data base file now has more than enough information in it (including job number) to make decisions and run further commands against the spool files on the outq being monitored. I am running CHGSPLF but CPYSPLF will work just fine. If this meets your needs and you need further information let me know. John P.S. I tried using API's to list the spool file into a user space and read the user space but I was getting weird results. I was running out of time (and getting pissed) so I did it the old fashioned way.




There are two problems with the *dtaq method that irritate me. First, the *dtaq entry is sent when a spoolfile goes to *RDY status; *HOLD or any other status doesn't do it. And second, a *dtaq entry is sent *every* time a spoolfile goes to *RDY status; place the spoolfile on *HOLD, then release it and you get another *dtaq entry. That is, the *dtaq entry is not sent when a spoolfile arrives on the *outq; the entry is sent "when a spoolfile goes to *RDY status". Do you have a way around either of those issues?




The best way to retrieve spool file info is to use a data queue attached to the output queue. When a spool entry goes to ready in the output queue, an entry is written to the data queue with all the spool file's info. You can then receive the data queue entry and substring the field entry into info needed for CPYSPLF. The layout of the data queue entry can be found in the "IBM Printer Device Programming Guide". I have done this many times and works great.




This can be pretty easy assuming a couple of things: (1) The copy take place withing the same job stream (2) There is only one spool file or the one you are coping is the last one. #2 can be worked around if the statement is not true. Use the SPLNBR parameter of the CPYSPLF command. SPLNBR can be *ONLY (the only spool file for the job), or *LAST (the last spool file for the job), or the actual spool file number.




Yes, there are APIs to retrieve spooled file information, but maybe you'd like the use of a data queue connected with the output queue(s). You then receive an entry in the dtaq every time a spooled file gets the status READY. In the entry, you find all infos to access the spooled file, including spooled file number. This is the best performing method; you do also use a minimum of system ressources, when you wait "for ever" for a data queue entry.




Two possible APIs, depending on exactly how much you know at the time the function runs and exactly what you need to know. Both are in the Print APIs section of the API documentation. The first is the List Spooled Files (QUSLSPL) API and the second is Retrieve Spooled File Attributes (QUSRSPLA). The first will return a list of spooled files depending on what you ask for, e.g., all spooled files for current user, all spooled files on a particular outq, etc. And the second returns the attributes for a specific spooled file. If you know you want the *LAST splf named QSYSPRT for the current job, then all you need is the second API. Lots of combinations possible.




the more easy way if you can is to include CPYSPLF just after print program and use *last (or *only if it is) as number.





Other tips in this category:

Click here to see all categories.

Socket Programming And Timeout Issues
Deleting Duplicate Records From A Table
What are data queues and how to use
Retrieving SMTP Name
RPGLE example for Dynamic Screen Manager API
Calling APIs from CL - with examples!
Compare two strings in RPG character by character
How to search all pgms in QCLSRC for a keyword
Retrieve Database File Description (QDBRTVFD) API
How to redirect the output to STDERR from RPG-IV
Using Multiformat Logical To Join 2 Identical File
D-Spec *LIKE DEFN
RPG: Converting Character to Decimal
Example of ILE RPG CGI Program
Handling ILE RPG Numeric Overflow
Help with Subfile Programming in RPG III
Zoned parameter in ILE RPG
What's the best way to do modulus in CL?
RPG Nesting Source Print Utility
More on changing the SIGNON screen
A silly ILE RPG question
Calling Validation List API From ILE RPG
Soft Coding Module Names
RPG Multidimensional Arrays in Action
Build a Page-Equals-Size Lookup Window
Procedures within an ILE RPG program
Break msg from RPG
Source Debugger for batch jobs
RPGLE debugging
Timing out display sessions in DDS
Building Dynamic Stored Procedures
Put Message in System Log
Dynamic RPGSQL
Randomize function for the AS/400
What's the fastest way to do a simple RPG lookup?
First time Data queue application in RPG
Print file overflow in ILE RPG
Mapping Fields To Arrays in ILE RPG
Named inidicators
STRQMQRY: comparision operator '=' isn't correct?!
DSPDTAARA to an outfile - possible?
PCL ESC codes in RPG
Sharing DB files between two AS/400s
Help: AS/400 subfiles
How do you change the signon screen?
Determining Even/Odd Values in queries
Get day of the week in RPG
Convert UPPERCASE to lowercase
RPG IV help using APIs
Help with data area API
Detecing IFS Files from RPG
SQL in a CL program
Calling AS/400 APIs from ILE RPG
CVTDAT command to convert an *MDY to a *LONGJUL
CPYSPLF Automation
Subfile Window background problem
Using IFS APIs w/ ILE RPG
Packed or unpacked fields?
QRYDFN to source and back
What does the "optimize" parm do?
Determining the calling program
Sockets in RPG?
Sorting a user space
OVRDBF and SECURE() keyword in an ILE environment
RPG record locking
RPG Differences: V2R3 to V3R2 upgrade
Getting the relative record number (RRN)
What is the longest parameter usable in RPG?
A C function that returns a string to an RPG pgm
Problems with ZADD *ZEROS
Can you highlight code in SEU?
Reusing deleted records - OK?
Is there an easy way to change edit codes?
Help - Windowed Subfiles
Logical Files and DDS
AS/400 'machine language' - MI Programming
Library lists and performance
How to use ERRSFL
Updating in CL
Record lock wait time
Message subfile problem
Physical File Joins
CL: Copying User Profiles
Commands and PARM
ILE RPG, RPG IV, vs. RPG/400
RPG and subfiles
Multiple subfiles
Field masking for passwords
SFLMODE keyword in an ILE program
Subfile size
Color coding records in a subfile
MSGLINE in windows
Controlling cursor movement on a display file
API returns error! Why?
Put an RPG Program on the Web
Variable length records in RPG
Differences Between RPG400, RPG IV, and ILE RPG


You are at a news400.com site.
Contact Us | Report Bugs | Submit Comments/Suggestions | Read Site Use Agreement | Read Privacy Policy
Copyright © 2000 Duke Communications International.
This site is best viewed with the latest versions of Netscape or Internet Explorer, 800 x 600 resolution (or higher), and at least 256 colors.
Duke Communications   NEWS/400 | 29th Street Press | Business Finance | DominoPro | Selling AS/400 Solutions | SQL Server Magazine | Windows NT Magazine