Delete old spool files

4280 pts.
Tags:
CL
CL programming
Spool files
The following question was recently submitted by a user via e-mail: I am trying to create a program in CL to delete old spool files on the AS400. I am using the following code, but my program does not recognize any of the commands. Does anyone have any suggestions or solutions? Thank you very much.
                                                                                  

/* DECLARE FILES AND VARIABLES                                      */            

             DCL        VAR(&SPLDAYSOLD) TYPE(*DEC) LEN(20) VALUE(-14)            

             DCL        VAR(&NEWDATE) TYPE(*CHAR) LEN(6)                          

             DCL        VAR(&CYMDDATE)      TYPE(*CHAR)  LEN(8)                   

             DCL        VAR(&SPLDATE)       TYPE(*CHAR)  LEN(8)                   

             DCL        VAR(&SPDAT)         TYPE(*CHAR)  LEN(8)                   

             CVTOUTQ    OUTQ(QPRINT)    OUTLIB(QGPL)                              

                                                                                  

             MONMSG     MSGID(CPF2479)                                            

             MONMSG     MSGID(CPF4903)                                            

             MONMSG     MSGID(CPF9898)                                            

             MONMSG     MSGID(CPF9999)                                            

             CVTOUTQ    OUTQ(OPTIOWO01) OUTLIB(QGPL) REPLACE 

 (*NO)                                                                            

              MONMSG     MSGID(CPF2479)                                           

              MONMSG     MSGID(CPF4903)                                           

              MONMSG     MSGID(CPF9898)                                           

              MONMSG     MSGID(CPF9999)                                           

  /* MORE QUEUES HERE, ETC....*/                                                  

             DCLF       FILE(*LIBL/OUTQP)                                         

 /* SETUP THE DATE FOR DELETING THE SPOOL FILES                      */           

              ADDDAT     DAYS(&SPLDAYSOLD) TOVAR(&NEWDATE)                        

              CVTDT   DATE(&NEWDATE) TOVAR(&CYMDDATE) FROMFMT(*MDY) +             

              TOFMT(*YYMD) TOSEP(*NONE) 

 /* READ THROUGH THE SPOOLFILES AND DETERMINE WHICH SHOULD BE        */         

/*  PURGED BASED ON THE DATE ORD USER DATA...                       */          

            READ:        RCVF                                                   

            MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF))                    

            CVTDAT     DATE(&SPDAT) TOVAR(&SPLDATE) FROMFMT(*YMD) +             

            TOFMT(*YYMD) TOSEP(*NONE)                                           

            IF   COND(&SPLDATE *LE &CYMDDATE *AND &SPUDTA *NE +                 

            'DALYSALE' *AND &SPUDTA *NE 'PRODUCTION') +                         

            THEN(DO)                                                            

            DLTSPLF    FILE(&SPFILE) JOB(&SPJNBR/&SPUSER/&SPJNAM) +             

            SPLNBR(&SPFNBR)                                                     

            MONMSG     MSGID(CPF0000)                                           

            ENDDO                                                               

            GOTO       CMDLBL(READ)                                             

            EOF:        CLRPFM     FILE(*LIBL/OUTQP)                            

            MONMSG     MSGID(CPF0000)                                           

            ENDPGM             

Answer Wiki

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

Here are a few – of many sites with code available.

http://www.freerpgtools.com/downloads/dltosplf.html

http://www.mcpressonline.com/programming/rpg/tips-and-techniques-delete-old-spool-files.html

http://www.itjungle.com/fhg/fhg113005-story03.html

http://tommyholden.com/downloads/

if you have TAATOOL it contains a command for this.

Problems with your code
1. All DCL including DCLF must be before any commands
2. CVTOUTQ appears to convert the actural spool files to physical files not a list of spool files.
3. Could to use WRKSPLF or WRKOTUQ command to get a spool file listing all spool files in outq
4. Could use CVTOUTQ or CPYSPLF to copy that file to a physical file
5. Then you receive the rows as a long string and need to parse them into fields — lots of work

Phil

Discuss This Question: 7  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
  • Gilly400
    Hi, I believe the CVTOUTQ, CVTDAT and ADDDAT commands are part of TAATOOLS - if you don't have TAATOOLS on your system (or in your library list) then these commands are not recognised by the system. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • pdraebel
    I have seen different techniques involving spoolfile cleanup. The one I use now is built around the List Object API (OUTQ) and the QUSLSPL (List spoolfiles). It manages cleanup of a +1000outq system with some 450000 spoolfiles in about 30 minutes daily. most of the time spent delting obsolete spools.
    3,040 pointsBadges:
    report
  • Gilly400
    Hi, Another option is to use the system cleanup to handle this for you. GO CLEANUP - Option 1. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • wpoulin
    Martin, I don't believe Cleanup will delete old spool files, job and system logs yes. Bill Poulin
    2,480 pointsBadges:
    report
  • Gilly400
    Hi Bill, You may well be right on that - I don't have access to it on my system at the moment. I thought that there was some sort of cleanup option for spooled files as standard these days....maybe I imagined it.... Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • GreenleeB
    This is a program I use to clean-up spools for a specific user after a period of days . It is modified from a program available on http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp under Programming->APIs. Like most IBM examples, it's not terribly pretty to look at - but it works. I modified it specifically to select by only the user and age of the spool but you can easily change it to select by outq, form type or user data. 15.00 PGM PARM(&LISTUSER &DAYS) 16.00 17.00 /*é**********************************************************·*/ 18.00 /*¹DECLARATIVES ·*/ 19.00 /*é**********************************************************·*/ 20.00 DCL &LISTUSER *CHAR 10 21.00 22.00 DCL &FILE *CHAR 10 23.00 DCL &JOBNAME *CHAR 10 24.00 DCL &USER *CHAR 10 25.00 DCL &JOBNUMBER *CHAR 6 26.00 DCL &FILENR *DEC 4 27.00 DCL &FILEDATE *CHAR 6 28.00 DCL &DAYS *DEC 3 /* No. days cvt'd to num */ 29.00 DCL &DATENUM *DEC 6 /* Date cvt'd to num */ 30.00 DCL &NEWDATE *DEC 6 /* Calculated date */ 31.00 DCL &RTNCODE *CHAR 1 /* Req'd for proc call */ 32.00 DCL &WRKDTE6 *CHAR 6 /* Work for date 6 */ 33.00 DCL &dltorsave *CHAR 6 34.00 35.00 DCL &MSGID *CHAR 7 36.00 DCL &MSGDTALN *DEC (9 0) 37.00 DCL &MSGDTA *CHAR 80 38.00 DCL &NO_ERROR *CHAR 4 VALUE(X'00000000') 39.00 40.00 /*¹Declares for QUSCRTUS - Create User Space */ 41.00 42.00 DCL &QCUS_NAME *CHAR 20 + 43.00 VALUE('SPL_DATA QTEMP ') 44.00 DCL &QCUS_EXATR *CHAR 10 + 45.00 VALUE('USRSPC ') 46.00 /*¹Maximum number of SPLF the User Space will contain */ 47.00 DCL &QCUS_SIZE *CHAR 4 + 48.00 VALUE(X'00010000') 49.00 DCL &QCUS_INIT *CHAR 1 VALUE(X'00') 50.00 DCL &QCUS_PUBA *CHAR 10 + 51.00 VALUE('*ALL ') 52.00 DCL &QCUS_TEXT *CHAR 50 53.00 DCL &QCUS_REPL *CHAR 10 + 54.00 VALUE('*YES ') 55.00 DCL &QCUS_DOMN *CHAR 10 + 56.00 VALUE('*DEFAULT ') 57.00 58.00 /*¹Declares for QUSLSPL - List Spooled Files */ 59.00 60.00 DCL &QLSF_NAME *CHAR 20 + 61.00 VALUE('SPL_DATA QTEMP ') 62.00 DCL &QLSF_FOMT *CHAR 8 + 63.00 VALUE('SPLF0100') 64.00 DCL &QLSF_USER *CHAR 10 65.00 DCL &QLSF_OUTQ *CHAR 20 66.00 DCL &QLSF_FORM *CHAR 10 67.00 DCL &QLSF_USRD *CHAR 10 68.00 69.00 /*¹Declares for QUSRTVUS - Retrieve User Space */ 70.00 71.00 DCL &QRUS_NAME *CHAR 20 + 72.00 VALUE('SPL_DATA QTEMP ') 73.00 DCL &QRUS_STRT *CHAR 4 74.00 DCL &QRUS_LENG *CHAR 4 75.00 DCL &QRUS_HEAD *CHAR 16 76.00 DCL &QRUS_LINE *CHAR 82 77.00 DCL &INT_OFFSET *DEC (9 0) 78.00 DCL &INT_NUMBER *DEC (9 0) 79.00 DCL &INT_SIZE *DEC (9 0) 80.00 DCL &INT_POSIT *DEC (9 0) 81.00 82.00 /*¹Variables QUSRSPLA - Get Spooled File Attributes */ 83.00 84.00 DCL &QGSA_RCV *CHAR 3772 85.00 DCL &QGSA_RCVLN *CHAR 4 + 86.00 VALUE(X'00000EBC') 87.00 DCL &QGSA_FOMT *CHAR 8 + 88.00 VALUE('SPLA0200') 89.00 DCL &QGSA_JOB *CHAR 26 + 90.00 VALUE('*INT ') 91.00 DCL &QGSA_IJOB *CHAR 16 92.00 DCL &QGSA_ISPL *CHAR 16 93.00 DCL &QGSA_SPLF *CHAR 10 + 94.00 VALUE('*INT ') 95.00 DCL &QGSA_SPLNB *CHAR 4 + 96.00 VALUE(X'00000000') 97.00 98.00 /*¹Declares for QUSDLTUS - Delete User Space */ 99.00 100.00 DCL &QDUS_NAME *CHAR 20 + 101.00 VALUE('SPL_DATA QTEMP ') 102.00 103.00 /*¹Declares for QERRCD - Error Code */ 104.00 105.00 DCL &QERRCD *CHAR 96 106.00 /*é**********************************************************·*/ 107.00 108.00 /*é**********************************************************·*/ 109.00 /*¹Get today's date.·*/ 110.00 RTVJOBA DATE(&WRKDTE6) 111.00 /*¹Convert to decimal for the date calculation.·*/ 112.00 CHGVAR &DATENUM &WRKDTE6 113.00 /*¹Calculate n days ago today.·*/ 114.00 CALLPRC PRC(CALCDURATION) PARM(('MDY') (&DATENUM) + 115.00 ('S') ('D') (&DAYS) ('YMD') (&NEWDATE) + 116.00 (&RTNCODE)) The CALCDURATION procedure is not included here but it's just a bit of code to calculate the date n days +/- from the current date. Any similar routine will do. 117.00 CHGVAR &WRKDTE6 &NEWDATE 118.00 119.00 /*¹Create Userspace */ 120.00 121.00 CHGVAR VAR(%SST(&QERRCD 1 8)) + 122.00 VALUE(X'0000006000000000') 123.00 CALL PGM(QUSCRTUS) PARM(&QCUS_NAME &QCUS_EXATR + 124.00 &QCUS_SIZE &QCUS_INIT &QCUS_PUBA + 125.00 &QCUS_TEXT &QCUS_REPL &QERRCD &QCUS_DOMN) 126.00 IF COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) + 127.00 THEN(GOTO CMDLBL(ERROR_API)) 128.00 129.00 /*¹List all Spooled Files for a given User */ 130.00 131.00 /*¹These four parameters are pased to the API to·*/ 132.00 /*¹create a list of spooled files in the user ·*/ 133.00 /*¹space: ·*/ 134.00 135.00 /*¹Spools for a specific user or *ALL. ·*/ 136.00 CHGVAR VAR(&QLSF_USER) VALUE(&LISTUSER) 137.00 /*¹ for a specific outq or *ALL. ·*/ 138.00 CHGVAR VAR(&QLSF_OUTQ) VALUE('*ALL') 139.00 /*¹Spools of a particular form type or *ALL ·*/ 140.00 CHGVAR VAR(&QLSF_FORM) VALUE('*ALL') 141.00 /*¹Spools with specific USRDTA or *ALL ·*/ 142.00 CHGVAR VAR(&QLSF_USRD) VALUE('*ALL') 143.00 144.00 CHGVAR VAR(%SST(&QERRCD 1 8)) + 145.00 VALUE(X'0000006000000000') 146.00 CALL PGM(QUSLSPL) PARM(&QLSF_NAME &QLSF_FOMT + 147.00 &QLSF_USER &QLSF_OUTQ &QLSF_FORM + 148.00 &QLSF_USRD &QERRCD) 149.00 IF COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) + 150.00 THEN(GOTO CMDLBL(ERROR_API)) 151.00 152.00 /*¹Read Header data from Userspace */ 153.00 154.00 CHGVAR VAR(%BIN(&QRUS_STRT)) VALUE(125) 155.00 CHGVAR VAR(%BIN(&QRUS_LENG)) VALUE(16) 156.00 CHGVAR VAR(%SST(&QERRCD 1 8)) + 157.00 VALUE(X'0000006000000000') 158.00 CALL PGM(QUSRTVUS) PARM(&QRUS_NAME &QRUS_STRT + 159.00 &QRUS_LENG &QRUS_HEAD &QERRCD) 160.00 IF COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) + 161.00 THEN(GOTO CMDLBL(ERROR_API)) 162.00 163.00 CHGVAR VAR(&INT_OFFSET) VALUE(%BIN(&QRUS_HEAD 1 4)) 164.00 CHGVAR VAR(&INT_NUMBER) VALUE(%BIN(&QRUS_HEAD 9 4)) 165.00 CHGVAR VAR(&INT_SIZE) VALUE(%BIN(&QRUS_HEAD 13 4)) 166.00 167.00 /*¹Loop through the Userspace */ 168.00 169.00 CHGVAR VAR(&INT_POSIT) VALUE(0) 170.00 LOOP_SPACE: CHGVAR VAR(&INT_POSIT) VALUE(&INT_POSIT + 1) 171.00 IF COND(&INT_POSIT *GT &INT_NUMBER) THEN(GOTO + 172.00 CMDLBL(END_SPACE)) 173.00 174.00 /*¹Read next Userspace detail line */ 175.00 176.00 CHGVAR VAR(%BIN(&QRUS_STRT)) VALUE(&INT_OFFSET + + 177.00 ((&INT_POSIT - 1) * &INT_SIZE) + 1) 178.00 CHGVAR VAR(%BIN(&QRUS_LENG)) VALUE(82) 179.00 CHGVAR VAR(%SST(&QERRCD 1 8)) + 180.00 VALUE(X'0000006000000000') 181.00 CALL PGM(QUSRTVUS) PARM(&QRUS_NAME &QRUS_STRT + 182.00 &QRUS_LENG &QRUS_LINE &QERRCD) 183.00 IF COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) + 184.00 THEN(GOTO CMDLBL(ERROR_API)) 185.00 186.00 /*¹Get Spooled File Attributes */ 187.00 188.00 CHGVAR VAR(&QGSA_IJOB) VALUE(%SST(&QRUS_LINE 51 16)) 189.00 CHGVAR VAR(&QGSA_ISPL) VALUE(%SST(&QRUS_LINE 67 16)) 190.00 CHGVAR VAR(%SST(&QERRCD 1 8)) + 191.00 VALUE(X'0000006000000000') 192.00 CALL PGM(QUSRSPLA) PARM(&QGSA_RCV &QGSA_RCVLN + 193.00 &QGSA_FOMT &QGSA_JOB &QGSA_IJOB + 194.00 &QGSA_ISPL &QGSA_SPLF &QGSA_SPLNB &QERRCD) 195.00 IF COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) + 196.00 THEN(GOTO CMDLBL(ERROR_API)) 197.00 198.00 CHGVAR VAR(&JOBNAME) VALUE(%SST(&QGSA_RCV 49 10)) 199.00 CHGVAR VAR(&FILE) VALUE(%SST(&QGSA_RCV 75 10)) 200.00 CHGVAR VAR(&USER) VALUE(%SST(&QGSA_RCV 59 10)) 201.00 CHGVAR VAR(&JOBNUMBER) VALUE(%SST(&QGSA_RCV 69 10)) 202.00 CHGVAR VAR(&FILENR) VALUE(%BIN(&QGSA_RCV 85 4)) 203.00 CHGVAR VAR(&FILEDATE) VALUE(%SST(&QGSA_RCV 212 6)) 204.00 205.00 If (&filedate *LE &WRKDTE6) do 206.00 chgvar &dltorsave 'Delete' 207.00 DLTSPLF FILE(&FILE) JOB(&JOBNUMBER/&USER/&JOBNAME) + 208.00 SPLNBR(&FILENR) 209.00 EndDo 210.00 Else do 211.00 chgvar &dltorsave 'Keep' 212.00 EndDo 213.00 214.00 SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) + 215.00 MSGDTA(&FILE |> 'JOB:'||&JOBNUMBER || '/' || + 216.00 &USER |< '/' || &JOBNAME |> 'DATE:'||&FILEDATE + 217.00 |> &dltorsave) 218.00 219.00 /* Read next Spooled File from User Space */ 220.00 221.00 GOTO CMDLBL(LOOP_SPACE) 222.00 223.00 /* Delete Userspace */ 224.00 225.00 END_SPACE: CHGVAR VAR(%SST(&QERRCD 1 8)) + 226.00 VALUE(X'0000006000000000') 227.00 CALL PGM(QUSDLTUS) PARM(&QDUS_NAME &QERRCD) 228.00 IF COND(%SST(&QERRCD 5 4) *NE &NO_ERROR) + 229.00 THEN(GOTO CMDLBL(ERROR_API)) 230.00 /* JUMP */ 231.00 232.00 GOTO CMDLBL(END) 233.00 234.00 /* API-Error */ 235.00 236.00 ERROR_API: CHGVAR VAR(&MSGID) VALUE(%SST(&QERRCD 9 7)) 237.00 CHGVAR VAR(&MSGDTALN) VALUE(%BIN(&QERRCD 5 4)) 238.00 CHGVAR VAR(&MSGDTALN) VALUE(&MSGDTALN - 16) 239.00 CHGVAR VAR(&MSGDTA) VALUE(%SST(&QERRCD 17 &MSGDTALN)) 240.00 SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + 241.00 MSGTYPE(*DIAG) 242.00 243.00 /* Error */ 244.00 245.00 ERROR: SNDPGMMSG MSGID(CPF9899) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) 246.00 247.00 END: I run this program in a scheduled job each day. I also noticed today another API example at http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp under Programming->APIs->Examples->Deleting Old Spooled Files. It's in RPG instead of CL and might be clearer but I didn't look at it too closely. Good luck.
    95 pointsBadges:
    report
  • ITKE
    test
    350,945 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