Wednesday, 23 March 2011

Automatically Deleting Spooled Files through Expiration Dates

I found another interesting news on the IT Jungle website and I have copied it below for your information.


Automatically Deleting Spooled Files through Expiration Dates

Published: March 23, 2011

Hey, Joe:

Last year, I stumbled on a cool method for automatically deleting spooled files. When you create a spooled file, you can set the number of days that you want to keep that file on your system. Then once a night, you can submit a job that runs the Delete Expired Spooled Files (DLTEXPSPLF) command that will automatically delete expired spooled files. You should try it.

--Peter


After working with the Power i and its antecedents for almost 30 years, I always find it interesting when somebody shows me something valuable that I haven't used before. DLTEXPSPLF is a simple command that automatically removes all expired spooled files from all the system Auxiliary Storage Pools (ASPs) or the system ASP on your iSeries, System i, and Power i partitions.

DLTEXPSPLF takes a little planning because spooled files don't just expire on their own accord. Rather, you have to configure each spooled file with its own expiration date for later removal. This can be done before or after the spooled file is created.

To really understand DLTEXPSPLF, it's best to look at an example. Let's say that we want to set up all our INVOICE spooled files to automatically be deleted from the system after 30 days. We can easily do this by making the following changes.

1.Change the printer file that is used to create your target spooled file, so that it includes a target expiration period for newly created invoices--Let's assume you're using a third-party accounting package that uses a printer file called INVOICE to create all your invoice spooled files. If we want to designate that all INVOICE spooled files will expire after 30 days, we can change the EXPIRATION DATE FOR FILE (EXPDATE) parameter to *DAYS and the DAYS UNTIL FILE EXPIRES (DAYS) parameter to 30 days inside the INVOICE printer file. For this modification, we can simply run the following CHANGE PRINTER FILE (CHGPRTF) command.

CHGPRTF FILE(INVOICE) EXPDATE(*DAYS) DAYS(30)

This command changes the printer file immediately so all new invoices will automatically be tagged with an expiration date of 30 days past their creation dates. Note that this will work for any spooled files that are created through an associated printer file. Altering source printer file parameters can serve as an easy way to set different expiration dates for different types of spooled files.

2. Set up a daily job to delete all spooled files that have expired during the previous day--This can be done either through IBM's job scheduler or through a third-party i/OS job scheduler such as Help/Systems' Robot/SCHEDULE. Run DLTEXPSPLF this way in your scheduled job if you want to delete expired spooled files in all of your ASPs.

DLTEXPSPLF ASPGRP(*ALL)

Run DLTEXPSPLF this way if you only want to delete expired spooled files in your system ASP (ASP 1).

DLTEXPSPLF ASPGRP(*SYSBAS)

Spooled files always expire at 23:59:59 military time on their expiration date. So if you run DLTEXPSPLF once a day, it will delete all the spooled files that expired the day before.

To add an entry to the IBM job scheduler for running DLTEXPSPLF on a daily schedule, you can run the following ADD JOB SCHEDULER ENTRY (ADDJOBSCDE) command that IBM lists in its i5/OS V5R4 Information Center entry on DLTEXPSPLF.

ADDJOBSCDE   JOB(DLTEXPSPLF)  CMD(DLTEXPSPLF  ASPGRP(*ALL))          
FRQ(*WEEKLY) SCDDATE(*NONE) SCDDAY(*ALL)SCDTIME(010000)
JOBQ(QSYS/QSYSNOMAX) TEXT('DELETE EXPIRED SPOOLED FILES SCHEDULE ENTRY')

And that's all there is to automatically deleting your job logs. If you want to add any other types of spooled files to your automatic deletion schedule, change their print file attributes, provided you can find the print file they are created from.

You can also change spooled file expiration dates on the fly by running the CHANGE SPOOLED FILE ATTRIBUTES (CHGSPLFA) command to modify the expiration dates of files as they are created or as they sit in an output queue. To change the expiration date on a recently created spooled file to 30 days, all you have to do is gather the relevant spooled file information and run the following CHGSPLFA command.

CHGSPLFA   FILE(spooled file name) JOB(job number/user name/job name)
SPLNBR(spooled file number) EXPDATE(*DAYS) DAYS(30)

If you don't want to mess around with changing expiration dates on the fly, you can create your own program to change the expiration dates for all spooled files in an output queue. A few years, I wrote a program called MOVSPLF that was used to move spooled files from one output queue to another. This program creates a work file of all the spooled files in a particular output queue and uses CHGSPLFA to move each spooled file to another output queue. With a little modification, you can easily change MOVSPLF to set expiration dates for all the spooled files in an output queue. Click here to check out the architecture and code for the MOVSPLF program.

--Joe

No comments:

Post a Comment