How to automatically create physical file from spoolfile when there are duplicates


I want to create a physical file from a spoolfile on a daily basis. It works fine with the command cpysplf if I enter all job information (job number/job user/job name).

But I want to automate this command and because the job number changes all the time, I need to find a way how to copy the last created spoolfile into a physical file.
I saw the possibility to use the param CRTDATE(*LAST) but this doesn't work, I still get the message from AS400 "Duplicate job names found.".

I think I have two possibilities, but don't know how to do them:
a) I modify the command CPYSPLF that it takes only the last created spoolfile
b) I create a CL script which somehow reads the jobnumber of the last created spoolfile and uses this jobnumber as a variable which will then be used in the CPYSPLF command

Thanks in advance for ideas and help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
The easiest thing to do is modify the job that creates this spooled file to perform the CPYSPLF command:

Will grab the last spooled file named MYSPLF generated by the current job.  

There are other solutions, but they start to get more complex.

- Gary Patterson

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
InfraMenAuthor Commented:
Seemed really the best and simpliest solution and it works. great!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.