咖啡馆

有空坐下来喝杯咖啡,放松下心情~
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过CLP实现library之间的自动复制 (转)

Posted on 2008-07-22 14:09  mshwu  阅读(480)  评论(0编辑  收藏  举报
通过CLP实现library之间的自动复制!
 
因业务需要定期从生产LIB复制数据到目标LIB,考虑执行效率和降低人为出错率,写了CLP工具实现自动复制.
 
程序思路:
 
1.因LF关联PF,所以必须先删除LF后才能删除其他objects,通过DSPFD过滤出LF文件,然后循环执行删除.
2.当监控到CPF2123系统提示不存在LF文件,程序直接跳转NEXT处理.
3.当LF删除完毕系统提示CPF0864,程序跳转NEXT处理.
4.删除LF文件后,清除整个LIB.
5.为了提高程序自动维护效率,同时考虑LIB处于使用中情况,将创建临时qtemp/savf,并savlib时使用SAVACT(*LIB)参数.
6.目标library恢复完毕,执行授权autl;
7.所有步骤完成后系统通过SNDDST自动发送邮件通知管理员.
8.程序结束执行清除QTEMP下临时workfile,tempsavf文件.
9.最后将工具写成CMD,便于调用.
 
**注意:编译前需执行DSPFD产生临时文件QTEMP/WORKFILE后编译才能通过.
 
CLP: AUTOUPDLIB ,编译在QGPL/AUTOUPDLIB
 

/*===================================================================*/

/*     PROGRAM NAME    : AUTOUPDLIB                                  */

/*     CREATED BY      : BOT LIU YUAN YAO                            */

/*     CREATED DATE    : 2008/02/21                                 */

/*     DESCRIPTION     : AUTO-UPDATE OVER SELECTED LIBRARIES         */

/*     USAGE           : BEFORE COMPILE [2008/03/06 DSPOBJD->DSPFD] */

/*     DSPFD FILE(&TRGLIB/*ALL) TYPE(*MBR) +                         */

/*           OUTPUT(*OUTFILE) OUTFILE(QTEMP/WORKFILE)                */

/*===================================================================*/

             PGM        PARM(&SRCLIB &TRGLIB)

 

             DCL        VAR(&SRCLIB) TYPE(*CHAR) LEN(10)

             DCL        VAR(&TRGLIB) TYPE(*CHAR) LEN(10)

             DCLF       FILE(QTEMP/WORKFILE) RCDFMT(QWHFDMBR)

 

             DCL        VAR(&SRCAUTL) TYPE(*CHAR) LEN(10)

             DCL        VAR(&TRGAUTL) TYPE(*CHAR) LEN(10)

 /** AUTO-DELETE ALL LF OF TARGET LIBRARY [2008/03/06] **/

             DSPFD      FILE(&TRGLIB/*ALL) TYPE(*MBR) +

                          OUTPUT(*OUTFILE) OUTFILE(QTEMP/WORKFILE)

             MONMSG     MSGID(CPF2123) EXEC(GOTO CMDLBL(NEXT))

 LOOP:       RCVF       RCDFMT(QWHFDMBR)

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

             IF         COND(&MBFATR *EQ 'LF') THEN(DO)

             DLTF       FILE(&TRGLIB/&MBFILE)

             ENDDO

             GOTO       CMDLBL(LOOP)

 NEXT:

             CLRLIB     LIB(&TRGLIB)

             MONMSG     MSGID(CPF0000)

 /** USE TEMPORARY SAVF TO SAVE AND RESTORE LIBRARY **/

             CRTSAVF    FILE(QTEMP/TMPSAVF) TEXT('Temporary savf')

             SAVLIB     LIB(&SRCLIB) DEV(*SAVF) SAVF(QTEMP/TMPSAVF) +

                          SAVACT(*LIB)

             MONMSG     MSGID(CPF0000)

             RSTLIB     SAVLIB(&SRCLIB) DEV(*SAVF) +

                          SAVF(QTEMP/TMPSAVF) RSTLIB(&TRGLIB)

             MONMSG     MSGID(CPF0000)

 /** AUTO-MAINTAIN AUTHORIZATION LIST [2008/03/05] **/

             CHGVAR     VAR(&SRCAUTL) VALUE('A' *CAT %SST(&SRCLIB 1 +

                          7))

             CHGVAR     VAR(&TRGAUTL) VALUE('A' *CAT %SST(&TRGLIB 1 3))

             CHKOBJ     OBJ(&SRCAUTL) OBJTYPE(*AUTL)

             MONMSG     MSGID(CPF9801) EXEC(GOTO CMDLBL(GRTAUTL))

             RVKOBJAUT OBJ(&TRGLIB/*ALL) OBJTYPE(*ALL) AUTL(&SRCAUTL)

             MONMSG     MSGID(CPF0000)

 GRTAUTL:

             CHKOBJ     OBJ(&TRGAUTL) OBJTYPE(*AUTL)

             MONMSG     MSGID(CPF9801) EXEC(DO)

             CRTAUTL    AUTL(&TRGAUTL)

             ENDDO

             GRTOBJAUT OBJ(&TRGLIB/*ALL) OBJTYPE(*ALL) AUTL(&TRGAUTL)

             MONMSG     MSGID(CPF0000)

             GRTOBJAUT OBJ(&TRGLIB/*ALL) OBJTYPE(*ALL) +

                          USER(*PUBLIC) AUT(*EXCLUDE)

             MONMSG     MSGID(CPF0000)

 /** AUTO-SEND EMAIL TO OPERATOR AFTER FINISHED ALL STEPS **/

             SNDDST     TYPE(*LMSG) +

                          TOINTNET((liuyuanyao@swirebev.com)) +

                          DSTD('Update Data Successfully!') +

                          LONGMSG('Update data from source to +

                          target library successfully,thanks!')

 ENDPGM:     DLTF       FILE(QTEMP/WORKFILE)

             MONMSG     MSGID(CPF2105)

             DLTF       FILE(QTEMP/TMPSAVF)

             MONMSG     MSGID(CPF2105)

             ENDPGM

 
CMD:UPDLIB
 
===> CRTCMD CMD(QGPL/UPDLIB) PGM(QGPL/AUTOUPDLIB) SRCFILE(LIUYY/QCMDSRC)
 

/*===================================================================*/

/* PROGRAM NAME : AUTOUPDLIB                                         */

/* DESCRIPTION : AUTO-UPDATE OVER SELECTED LIBRARIES                 */

/* PROGRAMMER : BOT LIU YUAN YAO                                     */

/* DATE : 2008/02/27                                                 */

/*===================================================================*/

             CMD        PROMPT('Auto-Update Selected Libraries')

             PARM       KWD(SRCLIB) TYPE(*CHAR) LEN(10) +

                          DFT('SRCLIB') REL(*NE ' ') +

                          SPCVAL(('HZTDB01') ('XMTDB01') +

                          ('GDTDB01') ('NJTDB01') ('XATDB01') +

                          ('ZZTDB01') ('HFTDB01') ('LQTDB01')) +

                          MIN(0) MAX(1) PROMPT('Source Library')

             PARM       KWD(TRGLIB) TYPE(*CHAR) LEN(10) +

                          DFT('TRGLIB') REL(*NE ' ') +

                          SPCVAL((HHDXA01) (HHDXA02) (HHDXA03) +

                          (HHDXA05) (HHDXA06) (HHDHF01) (HZUDB01) +

                          (XMPDB01)) MIN(0) MAX(1) PROMPT('Traget +

                          Library')

 
UPDLIB+F4显示如下:
 
                     Auto-Update Selected Libraries (UPDLIB)                
                                                                            
 Type choices, press Enter.                                                 
                                                                            
 Source Library . . . . . . . . . > 'srclib'      Character value, HZTDB01...
 Traget Library . . . . . . . . . > 'trglib'      Character value, HHDXA01...
 
 
以后可以QBATCH下执行:
 ===> SBMJOB CMD(UPDLIB SRCLIB('srclib') TRGLIB('trglib')) JOB(UPDLIB) JOBQ(QGPL/QBATCH)                                                                       
或QINTER下交互使用.
===> UPDLIB SRCLIB('srclib') TRGLIB('trglib')