CL code to work on a spool file

Tags:
Application development
AS/400
CLP
Hi, I wish to create a database file from a spool file. I know how to do this using cpysplf. I don't want the user to have to track down and enter the parameters for this command because, it will always be the same print file and user. The only variable parameter will be the spool file number. So the code should pick up the first spool file in the (dedicated) output queue and automatically process the cpysplf command. Any ideas? Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi

If you want a CL only solution then you could look at using:

WRKOUTQ OUTQ(queue_name) OUTPUT(*PRINT)

to generate a list of the spool files on an output queue and then copy the generated report to a database file for processing using:

CPYSPLF FILE(QPRTSPLQ) TOFILE(filename) SPLNBR(*LAST)

Using CL you can then read through the file and parse out the relevant fields, e.g.:

2 - 11 Spool File Name
13 - 22 User ID
75 - 78 Spool File Number
84 - 93 Job Name
95 - 100 Job Number

Alternatively, you could add a data queue to the output queue so that when a spool file is written to the output queue an entry is also made to the data queue. You can then process the data queue as and when to retrieve the spool file and update your database.

Hope it helps

Jonathan

========================================================

Since command print formats are never guaranteed to remain constant, processing the result of OUTPUT(*PRINT) should always be avoided. Further, it’s almost always easier to do it the right way anyway.

The List Spooled Files (QUSLSPL) API will list the spooled files on an *OUTQ to a user space; use format SPLF0100. The first element in the list can be retrieved, and the identifiers from format SPLF0100 can be passed into the Retrieve Spooled File Attributes (QUSRSPLA) API to retrieve the spooled file number with format SPLA0100.

Tom

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • WoodEngineer
    Could you add CPYSPLF to the job which creates the report?  That should make it easy to select the desired spool file by specifying  SPLNBR(*LAST).
    6,875 pointsBadges:
    report
  • ToddN2000
    If this is to be done every time that job runs, then I would take WoodEngineers suggestion and put it directly into the job if you have the ability to edit that code.
    15,605 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following