質問: I need to create a job to delete PFs based on create date or a variable w/in the name ------------------------------------------------------------------------------------- There are several files (they are claim files) created on a daily basis; they have MMDD appended to the name, e.g. ECPAU1118, ECPAH1118. They would like to keep these files out there for a year! but want a 'month-end' job that will delete all files from the previous year for the upcoming month. Can anyone offer a 'simple' solution for this? Thank you so much for your time and assistance!
回答: I’d create a CL program that does a dspobjd to an outfile of all pf’s in the library. Then read the outfile and select the create date that is less than or equal to the date that I pass in as a parm to the program. If the object meets the date criteria, delete it. Mars808 I had a couple of minutes so I threw the following CL together, I know you said month end job, but I believe the following program would work if you ran it on the first day of the month. Anyway it gives you a starting point. No warranties here ! PGM DCLF FILE(QSYS/QAFDBASI) RCDFMT(QWHFDBAS) DCL VAR(&ATFCMO) TYPE(*CHAR) LEN(2) DCL VAR(&ATFCYR) TYPE(*CHAR) LEN(2) DCL VAR(&DATE) TYPE(*CHAR) LEN(6) DCL VAR(&MONTH) TYPE(*CHAR) LEN(2) DCL VAR(&MSG) TYPE(*CHAR) LEN(100) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(100) DCL VAR(&MSGF) TYPE(*CHAR) LEN(10) DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&TYPE) TYPE(*CHAR) LEN(1) DCL VAR(&YEAR) TYPE(*CHAR) LEN(2) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) RTVJOBA DATE(&DATE) TYPE(&TYPE) IF COND(&TYPE *EQ ‘1’) THEN(DO) SBMJOB CMD(CALL PGM(DLTFD)) JOB(DLTFD) GOTO CMDLBL(END) ENDDO CHGVAR VAR(&MONTH) VALUE(%SST(&DATE 1 2)) CHGVAR VAR(&YEAR) VALUE(%SST(&DATE 5 2)) DSPFD FILE(YOURLIB/*ALL) TYPE(*BASATR) + OUTPUT(*OUTFILE) OUTFILE(QTEMP/YOURFILE) OVRDBF FILE(QAFDBASI) TOFILE(QTEMP/YOURFILE) READ: RCVF RCDFMT(QWHFDBAS) MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END)) + /* End of file detected */ CHGVAR VAR(&ATFCMO) VALUE(%SST(&ATFCDT 3 2)) CHGVAR VAR(&ATFCYR) VALUE(%SST(&ATFCDT 1 2)) IF COND(&ATFCMO *EQ &MONTH *AND &ATFCYR *NE + &YEAR) THEN(DO) DLTF FILE(YOURLIB/&ATFILE) MONMSG MSGID(CPF3142) /* File not found */ ENDDO GOTO CMDLBL(READ) ERROR: RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) + MSGF(&MSGF) MSGFLIB(&MSGFLIB) RTVMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) + MSGDTA(&MSGDTA) MSG(&MSG) SNDMSG MSG(&MSG) TOUSR(YOURPROFIL) END: RETURN ENDPGM Hope this helps, Bill Poulin