I need to create a job to delete PFs based on create date or a variable w/in the name

15 pts.
Tags:
AS/400 backup
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!

Answer Wiki

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

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

Discuss This Question: 1  Reply

 
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
  • Mars808
    Aloha- Thank you so much for your time, I really appreciate it. I actually came up w/ something really simple (maybe too much so!) Here's mine, maybe if anyone sees anything glaringly 'wrong' you could be so kind as to let me know- PGM DCL VAR(&MO) TYPE(*CHAR) LEN(2) DCL VAR(&DLTUB) TYPE(*CHAR) LEN(9) DCL VAR(&DLTHF) TYPE(*CHAR) LEN(9) RTVSYSVAL SYSVAL(QMONTH) RTNVAR(&MO) CHGVAR VAR(&DLTUB) VALUE('ECPAU4' *CAT &MO *CAT '*') CHGVAR VAR(&DLTHF) VALUE('ECPAH4' *CAT &MO *CAT '*') DLTF FILE(HS#FTST/&DLTUB) MONMSG MSGID(CPF2125) DLTF FILE(HS#FTST/&DLTHF) MONMSG MSGID(CPF2125) ENDPGM
    15 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