Newbie...sorry
Can anyone offer some help on automatically deleting a range of files after a monthly backup?
Thanks
Can anyone offer some help on automatically deleting a range of files after a monthly backup?
Thanks
DLTF lib/TMP*
DLTF lib/TMP*

H* +-------------------------------------------------------------------+
H* | Author: Greg Craill Created: 22 Aug 2011 Version: Initial |
H* +-------------------------------------------------------------------+
H* | Purpose: This program takes purge offset parameters for months |
H* | (PrgMths) and days (PrgDays) and compares them against a sample |
H* | date (USEdate), it then returns the action to take (DoAction). |
H* | If Today - months(PrgMths) - days(PrgDays) > USEdate then *PURG |
H* | If Today - months(PrgMths) - days(PrgDays) <= USEdate then *KEEP |
H* | The calling program will have to take the action based on the |
H* | DoPurge parametyer returned to it. |
H* +-------------------------------------------------------------------+
F*
D* --------- Parameters In/Out --------------
D NumMths S 3A
D NumDays S 3A
D USEdate S 6A
D DoPurge S 5A
D* --------- Other Work Variables -----------
D PRGdate S 8 0
D CHKdate S 8 0
D PrgMths S 3 0
D PrgDays S 3 0
D* Commented out the message bit - for debugging only
D*MsgTxt S 50A
C *Entry PLIST
C* --------- Input Parms --------------------
C* NumMths = The Number of Months data to keep
C* NumDays = The Number of Days data to keep
C* USEdate = The Date of Object to compare against
C* NOTE: Months and Days are added together for the total purge offset
C PARM NumMths
C PARM NumDays
C PARM USEdate
C* --------- Output Parms -------------------
C* DoPurge = The Action to take is returned to the calling program.
C* It will be either "*PURG" or "*KEEP"
C PARM DoPurge
/FREE
// Parms are passed in as *CHAR, convert to *DEC for the date functions
PrgMths = %Dec(NumMths:3:0) * -1;
PrgDays = %Dec(NumDays:3:0) * -1;
PRGDate = %Dec(%Date() + %Days(PrgDays) + %Months(PrgMths));
CHKDate = %Dec(%Date(USEdate: *MDY0));
If PRGdate > CHKdate;
// MsgTxt = 'PrgDate(' + %Char(PRGdate) + ') ChkDate(' +
// %Char(CHKdate) + ') ==> Purge';
DoPurge = '*PURG';
Else;
// MsgTxt = 'PrgDate(' + %Char(PRGdate) + ') ChkDate(' +
// %Char(CHKdate) + ') ==> KEEP';
DoPurge = '*KEEP';
EndIf;
// DSPLY MsgTxt;
*INLR = *ON;
/END-FREE
/* +------------------------------------------------------------+ */
/* | This program clears or deletes files in a target library | */
/* | that meet the criteria selected for last used date and | */
/* | creation date. | */
/* +------------------------------------------------------------+ */
/* | Greg Craill 22 Aug 2011 - Initial Version | */
/* +------------------------------------------------------------+ */
/* | Greg Craill 19 Sep 2011 - Changed to HOLD(*YES/*NO) | */
/* +------------------------------------------------------------+ */
/* | To compile this program first do ... | */
/* | DSPDBR FILE(I321OPSS/OPSPURGES) OUTPUT(*OUTFILE) | */
/* | OUTFILE(QTEMP/LFFILES) OUTMBR(*FIRST *ADD) | */
/* | DSPOBJD OBJ(TEMPFILES/*ALL) OBJTYPE(*FILE) | */
/* | OUTPUT(*OUTFILE) OUTFILE(QTEMP/PFFILES) | */
/* | DSPOBJD OBJ(TEMPFILES/*ALL) OBJTYPE(*FILE) | */
/* | OUTPUT(*OUTFILE) OUTFILE(QTEMP/PFLIST) | */
/* +------------------------------------------------------------+ */
/* | Related Objects; | */
/* | PRGFIL *CMD - Calls PRGFILC1 | */
/* | PRGFILC1 *CLLE - Purges Objects from TEMPFILES Lib | */
/* | PRGFILC2 *CLLE - Save and Purge SAVARKLIB object list | */
/* | PRGDATR1 *RPGLE - Checks file date against purge date | */
/* | and returns *PURG or *KEEP | */
/* +------------------------------------------------------------+ */
/* | Variables: | */
/* | I &PrgLib Library to Purge files from | */
/* | I &PrgTyp *DLT or *CLR the selected files ? | */
/* | IO &PrgMths Number of Months to purge to ( added ) | */
/* | IO &PrgDays Number of Days to purge to (together) | */
/* | I &JobHld *YES or *NO to hold on job queue | */
/* | O &ChkDate Date to check for purge or not | */
/* | O &Action *PURG or *KEEP based on &ChkDate | */
/* +------------------------------------------------------------+ */
PGM PARM(&PRGLIB &PRGTYP &PRGMTHS &PRGDAYS &JOBHLD)
/* Purge Library - Library name to purge from */
DCL VAR(&PRGLIB) TYPE(*CHAR) LEN(10)
/* Purge Type - *DLT or *CLR the selected files */
DCL VAR(&PRGTYP) TYPE(*CHAR) LEN(4)
/* Purge Months - How many months ago to purge to ? */
DCL VAR(&PrgMths) TYPE(*CHAR) LEN(3)
/* Purge Days - How many months ago ? */
DCL VAR(&PrgDays) TYPE(*CHAR) LEN(3)
/* Purge Days - How many months ago ? */
DCL VAR(&JobHld) TYPE(*CHAR) LEN(4)
DCL VAR(&ChkDate) TYPE(*CHAR) LEN(6)
DCL VAR(&Action) TYPE(*CHAR) LEN(5)
DCL VAR(&JobTyp) TYPE(*CHAR) LEN(1)
DCL VAR(&DLTMSG) TYPE(*CHAR) LEN(200)
DCLF FILE(QTEMP/PFLIST) OPNID(F1)
DCLF FILE(QTEMP/LFFILES) OPNID(LF)
DCLF FILE(QTEMP/PFFILES) OPNID(PF)
/* +------------------------------------------------------------------+ */
/* | Cancel if ICMS library name is used. | */
/* +------------------------------------------------------------------+ */
IF COND(%SST(&PRGLIB 2 4) = 'ICMS') THEN(DO)
SNDPGMMSG MSG('Not allowed to use this program to +
purge from ICMS libraries. Request Cancelled!')
GOTO CMDLBL(ENDPGM)
ENDDO
/* +------------------------------------------------------------------+ */
/* | Submit to Batch &JobTyp 0 = Batch 1 = Interactive | */
/* +------------------------------------------------------------------+ */
RTVJOBA TYPE(&JobTyp)
IF COND(&JOBTYP = '1') THEN(DO)
SBMJOB CMD(CALL PGM(PRGFILC1) PARM(&PRGLIB &PRGTYP +
&PRGMTHS &PRGDAYS &JobHld)) JOB(PRGUSRLIB) +
JOBQ(MULTI) HOLD(&JobHld)
GOTO CMDLBL(ENDPGM)
ENDDO
/* +------------------------------------------------------------------+ */
/* | Log status messages | */
/* +------------------------------------------------------------------+ */
SNDPGMMSG MSG('Purge Library is:' *BCAT &PrgLib)
SNDPGMMSG MSG('Purge Type is:' *BCAT &PrgTyp)
SNDPGMMSG MSG('Purge Date is:' *BCAT &PRGMTHS *BCAT +
'months and' *BCAT &PRGDAYS *BCAT 'days.')
/* +------------------------------------------------------------------+ */
/* | Clear Temp Work files | */
/* +------------------------------------------------------------------+ */
CLRPFM FILE(QTEMP/PFFILES)
MONMSG MSGID(CPF0000)
CLRPFM FILE(QTEMP/LFFILES)
MONMSG MSGID(CPF0000)
/* +------------------------------------------------------------------+ */
/* | List all files in target library to file PFLIST. | */
/* +------------------------------------------------------------------+ */
DSPOBJD OBJ(&PRGLIB/*ALL) OBJTYPE(*FILE) +
OUTPUT(*OUTFILE) OUTFILE(QTEMP/PFLIST)
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(NOFILES))
/* +------------------------------------------------------------------+ */
/* | Read files and find ones with valid purge dates. | */
/* +------------------------------------------------------------------+ */
SNDPGMMSG MSG('Checking File Dates')
READ1: RCVF OPNID(F1)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF1))
/* &F1_ODCDAT is the Creation Date. */
/* &F1_ODRDAT is the Restore Date. */
/* &F1_ODLDAT is the Last Changed Date. */
/* &F1_ODUDAT is the Last Used Date. */
/* Only process for PF attributes, ignore LF, PRTF, SAVF etc */
/* --------------------------------------------------------- */
IF COND(&F1_ODOBAT = 'PF') THEN(DO)
/* If non blank then priority in file dates is Last_Used, */
/* Last_Changed, Last_Restored, File_Created. */
CHGVAR VAR(&CHKDATE) VALUE(&F1_ODUDAT)
IF COND(&CHKDATE = ' ') THEN(CHGVAR VAR(&CHKDATE) VALUE(&F1_ODLDAT))
IF COND(&CHKDATE = ' ') THEN(CHGVAR VAR(&CHKDATE) VALUE(&F1_ODRDAT))
IF COND(&CHKDATE = ' ') THEN(CHGVAR VAR(&CHKDATE) VALUE(&F1_ODCDAT))
CALL PGM(PRGDATR1) PARM(&PRGMTHS &PRGDAYS &CHKDATE &ACTION)
/* If program PRGDATR1 returns *PURG then add the file */
/* details to the output files. */
IF COND(&ACTION = '*PURG') THEN(DO)
DSPOBJD OBJ(&PRGLIB/&F1_ODOBNM) OBJTYPE(*FILE) +
OUTPUT(*OUTFILE) OUTFILE(QTEMP/PFFILES) +
OUTMBR(*FIRST *ADD)
MONMSG MSGID(CPF0000)
DSPDBR FILE(&PRGLIB/&F1_ODOBNM) OUTPUT(*OUTFILE) +
OUTFILE(QTEMP/LFFILES) OUTMBR(*FIRST *ADD)
MONMSG MSGID(CPF0000)
/* SNDPGMMSG MSG('File(' *TCAT &F1_ODOBNM *TCAT ') Date(' + */
/* *TCAT &CHKDATE *TCAT ') => Purge') */
ENDDO
ELSE CMD(DO)
/* SNDPGMMSG MSG('File(' *TCAT &F1_ODOBNM *TCAT ') Date(' + */
/* *TCAT &CHKDATE *TCAT ') => Keep') */
ENDDO
ENDDO
GOTO CMDLBL(READ1)
/* +------------------------------------------------------------------+ */
EOF1:
/* +------------------------------------------------------------------+ */
/* | Action = *CLR (Clear) | */
/* | - Create spoolfile report | */
/* | - Read file PFFILES and do CLRPFM on them all. | */
/* +------------------------------------------------------------------+ */
IF COND(&PrgTyp = '*CLR') THEN(DO)
/* Create spoolfile listing all physical files */
RUNQRY QRY(*NONE) QRYFILE((QTEMP/PFFILES)) OUTTYPE(*PRINTER)
/* Read PFFILES and clear the physical files */
READ2: RCVF OPNID(PF)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF2))
IF ((&PF_ODLBNM *NE ' ') *AND (&PF_ODOBNM *NE ' ')) THEN(DO)
CLRPFM FILE(&PF_ODLBNM/&PF_ODOBNM)
MONMSG MSGID(CPF3133) /* No members in file to clear */
ENDDO
GOTO CMDLBL(READ2)
EOF2:
ENDDO
/* +------------------------------------------------------------------+ */
/* +------------------------------------------------------------------+ */
/* | Action = *DLT (Delete) | */
/* | - Create spoolfile report | */
/* | - Read file LFFILES and delete any dependent files listed | */
/* | - Read file PFFILES and delete the physical files listed | */
/* +------------------------------------------------------------------+ */
IF COND(&PrgTyp = '*DLT') THEN(DO)
/* Create spoolfile listing all physical files */
RUNQRY QRY(*NONE) QRYFILE((QTEMP/PFFILES)) OUTTYPE(*PRINTER)
/* Create spoolfile listing all logical files */
RUNQRY QRY(*NONE) QRYFILE((QTEMP/LFFILES)) OUTTYPE(*PRINTER)
/* Read LFFILES and delete logical files */
READ3: RCVF OPNID(LF)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF3))
IF ((&LF_WHRELI *NE ' ') *AND (&LF_WHREFI *NE ' ')) THEN(DO)
DLTF FILE(&LF_WHRELI/&LF_WHREFI)
ENDDO
GOTO CMDLBL(READ3)
EOF3:
/* Read PFFILES and delete physical files */
READ4: RCVF OPNID(PF)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF4))
IF ((&PF_ODLBNM *NE ' ') *AND (&PF_ODOBNM *NE ' ')) THEN(DO)
DLTF FILE(&PF_ODLBNM/&PF_ODOBNM)
ENDDO
GOTO CMDLBL(READ4)
EOF4:
ENDDO
/* +------------------------------------------------------------------+ */
NOFILES:
ENDPGM:
ENDPGM
CMD PROMPT('Delete or Clear Files')
/* Purge Library - Library name to purge from */
PARM KWD(PRGLIB) TYPE(*CHAR) LEN(10) MIN(1) +
PROMPT('Library to Purge From')
PARM KWD(PRGTYP) TYPE(*CHAR) LEN(4) RSTD(*YES) +
VALUES(*CLR *DLT) MIN(1) PROMPT('Clear or Delete')
PARM KWD(PRGMTHS) TYPE(*CHAR) LEN(3) DFT(12) +
PROMPT('Months of data to keep')
PARM KWD(PrgDays) TYPE(*CHAR) LEN(3) DFT(0) +
PROMPT('Days of data to keep')
PARM KWD(JOBHLD) TYPE(*CHAR) LEN(4) RSTD(*YES) +
DFT(*YES) VALUES(*YES *NO) PROMPT('Hold on Job Queue?')
Comment