zOs/TX/MF15HIST
//A540769C JOB (CP00,KE50),'DB2 REO', 00010000
// MSGCLASS=T,TIME=1440, 00020000
// NOTIFY=&SYSUID,REGION=0M 00030000
//*MAIN CLASS=DBTF 00040000
//*
//* mf historisierung mf150A1 ==> mf150H1
//* mit PartitionenWeisen Load auf MF150H1
//*
//DEL EXEC PGM=IEFBR14
//SYSREC00 DD DISP=(MOD,DELETE),DSN=TSS.SKA.TMP.MF15HIST
//S1 EXEC PGM=IKJEFT01,DYNAMNBR=200,TIME=99
//SYSTSIN DD *
DSN SYSTEM(DBTF)
RUN PROGRAM(DSNTIAUL) PARMS('SQL')
//SYSTSPRT DD SYSOUT=*
//*
//* sql: r: für nichtLeere Partition in mf150H v(on) und b(is)
//* p: alle Partitionen die gelöscht werden können
//* t: für jede Partition 4 Utility Statements:
//* copy, sql exec, load, copy
//*
//SYSIN DD *
with r (l, p, v, b) as
( /* r = rekursiv Partitionen berechnen, */
/* p = Partition, v=von inklusiv, b=bis exklusiv */
select 0, 0, date('01.01.1800'), date('01.01.1900')
from sysibm.sysdummyE
union all select l+1, -1,
(select min(MF150013) from oa1t.tmf150a1 where MF150013 >= r.b),b
from r where p >= 0 and v < current date - 12 month and l < 999
union all select l+1, year(v)*24+month(v)*2 +10-48002, v,
v + (16-day(v)) days
from r where p = -1 and day(v) <= 15 and l < 999
union all select l+1, year(v)*24+month(v)*2 +11-48002, v,
v - (day(v)-1) days + 1 month
from r where p = -1 and day(v) > 15 and l < 999
)
, p (p, v, b) as
(
select strip(char(p)), v, b
from r
where p > 0 and b < current date - 12 month
)
, t (p, v, b, n, t) as
( /* für jede Partition utility ctl: copy, load, copy */
select p.*, 1, 'COPY TABLESPACE MF01A1T.MF150H DSNUM ' || p
from p
union all select p.*, 2, ' COPYDDN(TCOPYD) SHRLEVEL REFERENCE'
from p
union all select p.*,10, 'EXEC SQL' from p
union all select p.*,11, ' DECLARE CUR' || p ||' CURSOR FOR' from p
union all select p.*,12, ' SELECT *' from p
union all select p.*,13, ' FROM OA1T.TMF150A1' from p
union all select p.*,14, ' WHERE MF150013 >= '''
|| char(v) || '''' from p
union all select p.*,15, ' and MF150013 < '''
|| char(b) || '''' from p
union all select p.*,16, ' order by MF150013 asc, MF150067 asc'
from p
union all select p.*,17, 'ENDEXEC' from p
union all select p.*,21, 'LOAD DATA INCURSOR CUR' || p from p
union all select p.*,22, ' LOG NO RESUME YES ' from p
union all select p.*,23, ' SORTDEVT DISK SORTNUM 50' from p
union all select p.*,24, ' WORKDDN(TSYUTS,TSOUTS)' from p
union all select p.*,25, ' INTO TABLE OA1T.TMF150H1' from p
union all select p.*,26, ' IGNOREFIELDS YES PART ' || p from p
union all select p.*,31, 'COPY TABLESPACE MF01A1T.MF150H DSNUM ' || p
from p
union all select p.*,32, ' COPYDDN(TCOPYD) SHRLEVEL REFERENCE'
from p
)
select char(coalesce(t, '??????'), 80)
from t order by v, n
;
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSPUNCH DD SYSOUT=*,RECFM=FB,LRECL=80
//SYSREC00 DD DISP=(NEW,CATLG),DSN=*.DEL.SYSREC00,
// DCB=(LRECL=80,RECFM=FB,BLKSIZE=26800),
// SPACE=(CYL,(2,1000))
//LOAD EXEC PGM=DSNUTILB,PARM='DBTF,A540769L.LOAD' 00020001
//SYSMAP DD SYSOUT=*
//UTPRINT DD SYSOUT=*
//SYSERR DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSTEMPL DD DSN=DBTF.DBAA.LISTDEF(TEMPL),DISP=SHR
//SYSIN DD DISP=SHR,DSN=*.DEL.SYSREC00