2007081415342007-08-14 要如何檢核某個 Job 的狀態並採取某些相對應動作 ? (Command: CHKACTJOB)

要如何檢核某個 Job 的狀態並採取某些相對應動作 ? (Command: CHKACTJOB)


File  : QCLSRC
Member: CHKACTJOB
Type  : CLP
Usage : CRTCLPGM CHKACTJOB
     

/*  ===============================================================  */
/*  = Command ChkJob     CPP                                      =  */
/*  =   ChkJob     CLP                                            =  */
/*  =   Paramater notes:                                          =  */
/*  =     Jobname : Jobname to check                              =  */
/*  =     Jobuser : Jobuser to check                              =  */
/*  =     SBS     : Specified jobname running under which sbs     =  */
/*  =     Action  : Change, End, Hold or Release job              =  */
/*  =     Job command option: only for Change or End job          =  */
/*  =     Other command : Other command for job                   =  */
/*  ===============================================================  */
/*  = Date  : 2007/06/04                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */
/*  = Date  : 2007/06/21                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  =         Added on ACTION *MSG to send status message to user =  */
/*  ===============================================================  */
/*  = Date  : 2007/08/08                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  =         Added  on JOBSTS keyword to limit job processing    =  */
/*  ===============================================================  */
/*  = Date  : 2007/08/14                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  =         Added on ACTION *DSP to display job information     =  */
/*  =               DSPJOB OPTION(*ALL) OUTPUT(*PRINT)            =  */
/*  =               DSPJOB OPTION(*JOBLOG) OUTPUT(*PTINT)         =  */
/*  ===============================================================  */

 CHKJOB:     PGM        PARM(&MYJOBNAME &JOBUSER &SBSDANDLIB &JOBSTS +
                      &ACTION &JOBOPT &TOUSR &CMD)

             DCL        VAR(&MYJOBNAME)  TYPE(*CHAR) LEN(10)
             DCL        VAR(&JOBUSER  )  TYPE(*CHAR) LEN(10)
             DCL        VAR(&SBSDANDLIB) TYPE(*CHAR) LEN(20) /* SBSD +
                          AND LIBRARY   */
             DCL        VAR(&SBSD) TYPE(*CHAR) LEN(10) /* SBS */
             DCL        VAR(&SBSDLIB) TYPE(*CHAR) LEN(10)
             DCL        VAR(&RTNSBSDLIB) TYPE(*CHAR) LEN(10)
             DCL        VAR(&JOBSTS) TYPE(*CHAR) LEN(5)
             DCL        VAR(&ACTION) TYPE(*CHAR) LEN(5)
             DCL        VAR(&JOBOPT) TYPE(*CHAR) LEN(3000)
             DCL        VAR(&TOUSR ) TYPE(*CHAR) LEN(10)
             DCL        VAR(&CMD   ) TYPE(*CHAR) LEN(3000)

             DCL        VAR(&CMDSTR) TYPE(*CHAR) LEN(3000)
             DCL        VAR(&CMDLEN) TYPE(*DEC) LEN(15 5)

             DCL        VAR(&JOBNAME)    TYPE(*CHAR) LEN(10)
             DCL        VAR(&USER)       TYPE(*CHAR) LEN(10)
             DCL        VAR(&JOBNBR)     TYPE(*CHAR) LEN(6)
             DCL        VAR(&STATUS)     TYPE(*CHAR) LEN(10)
             DCL        VAR(&JOBTYPE)    TYPE(*CHAR) LEN(1)
             DCL        VAR(&SUBTYPE)    TYPE(*CHAR) LEN(1)

             DCL        VAR(&USP_NAME)   TYPE(*CHAR) LEN(10)
             DCL        VAR(&USP_LIB)    TYPE(*CHAR) LEN(10)
             DCL        VAR(&USP_QUAL)   TYPE(*CHAR) LEN(20)
             DCL        VAR(&USP_TYPE)   TYPE(*CHAR) LEN(10)
             DCL        VAR(&USP_SIZE)   TYPE(*CHAR) LEN(4)
             DCL        VAR(&USP_FILL)   TYPE(*CHAR) LEN(1)
             DCL        VAR(&USP_AUT)    TYPE(*CHAR) LEN(10)
             DCL        VAR(&USP_TEXT)   TYPE(*CHAR) LEN(50)

             DCL        VAR(&API_USQUAL) TYPE(*CHAR) LEN(20)
             DCL        VAR(&API_JBQUAL) TYPE(*CHAR) LEN(26)
             DCL        VAR(&API_JBNAM)  TYPE(*CHAR) LEN(10)
             DCL        VAR(&API_USER)   TYPE(*CHAR) LEN(10)
             DCL        VAR(&API_JOBNR)  TYPE(*CHAR) LEN(6)
             DCL        VAR(&API_STATUS) TYPE(*CHAR) LEN(10)

             DCL        VAR(&STARTPOS)   TYPE(*CHAR) LEN(4)
             DCL        VAR(&DATALEN)    TYPE(*CHAR) LEN(4)
             DCL        VAR(&HEADER)     TYPE(*CHAR) LEN(150)
             DCL        VAR(&LST_OFFSET) TYPE(*DEC)  LEN(5 0)
             DCL        VAR(&LST_SIZE)   TYPE(*DEC)  LEN(5 0)
             DCL        VAR(&LST_DATA)   TYPE(*CHAR) LEN(4096)
             DCL        VAR(&LST_NBR)    TYPE(*DEC)  LEN(5 0)
             DCL        VAR(&LST_LEN)    TYPE(*DEC)  LEN(5 0)
             DCL        VAR(&LST_LENBIN) TYPE(*CHAR) LEN(4)
             DCL        VAR(&LST_POSBIN) TYPE(*CHAR) LEN(4)
             DCL        VAR(&LST_COUNT)  TYPE(*DEC)  LEN(5) VALUE(0)
             DCL        VAR(&EXC_COUNT)  TYPE(*DEC)  LEN(5) VALUE(0)
             DCL        VAR(&TYPE) TYPE(*CHAR) LEN(1) VALUE('*')
             DCL        VAR(&NBRTORTN)  TYPE(*CHAR)  LEN(4)
             DCL        VAR(&KEYSTORTN) TYPE(*CHAR)  LEN(8)
             DCL        VAR(&KEY1     ) TYPE(*CHAR)  LEN(4)
             DCL        VAR(&KEY2     ) TYPE(*CHAR)  LEN(4)
             DCL        VAR(&SBSSYS   ) TYPE(*CHAR)  LEN(20)
             DCL        VAR(&WRKSTS   ) TYPE(*CHAR)  LEN(4)
             DCL        VAR(&JOBWRKSTS) TYPE(*CHAR)  LEN(4)

             DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
             DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(256)
             DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)
             DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
             DCL        VAR(&MSGTXT) TYPE(*CHAR) LEN(256)

             MONMSG     MSGID(CPF0000 MCH0000) EXEC(GOTO CMDLBL(ERROR))

/*- DIVISION OF COMMAND PARAMETER ----------------------------------*/
             CHGVAR     VAR(&SBSD) VALUE(%SST(&SBSDANDLIB 1 10))
             CHGVAR     VAR(&SBSDLIB) VALUE(%SST(&SBSDANDLIB 11 10))

             IF         (&SBSD *NE '*ALL') DO

             CHKOBJ     OBJ(&SBSDLIB/&SBSD) OBJTYPE(*SBSD)
             MONMSG     MSGID(CPF9801) EXEC(DO)
               RCVMSG     MSGQ(*PGMQ) RMV(*NO)
               /* MSG: SBSD      IN LIBRARY NOT FOUND */
               SNDPGMMSG  MSGID(CPF9801) MSGF(QCPFMSG) +
                          MSGDTA(&SBSDANDLIB) MSGTYPE(*ESCAPE)
             ENDDO

             RTVOBJD    OBJ(&SBSDLIB/&SBSD) OBJTYPE(*SBSD) +
                          RTNLIB(&RTNSBSDLIB)
             CHGVAR     VAR(%SST(&SBSDANDLIB 11 10)) VALUE(&RTNSBSDLIB)

             ENDDO

             CHGVAR     VAR(%BIN(&NBRTORTN)) VALUE(2)
     /* 0101 -- Ststus as WRKACTJOB */
             CHGVAR     VAR(%BIN(&KEY1     )) VALUE(0101)
     /* 1906 -- Subsystem */
             CHGVAR     VAR(%BIN(&KEY2     )) VALUE(1906)
             CHGVAR     VAR(&KEYSTORTN) VALUE(&KEY1 *CAT &KEY2)

             CHGVAR     VAR(&USP_NAME) VALUE('CHKJOBNAME')
             CHGVAR     VAR(&USP_LIB)  VALUE('QTEMP')
             CHGVAR     VAR(&USP_QUAL) VALUE(&USP_NAME *CAT +
                          &USP_LIB)
             CHGVAR     VAR(&USP_TYPE) VALUE('MYTYPE')
             CHGVAR     VAR(%BIN(&USP_SIZE)) VALUE(128000)
             CHGVAR     VAR(&USP_FILL) VALUE(' ')
             CHGVAR     VAR(&USP_AUT)  VALUE('*USE')
             CHGVAR     VAR(&USP_TEXT) VALUE('my user space')

             DLTUSRSPC  USRSPC(&USP_LIB/&USP_NAME)
             MONMSG CPF0000

             CALL       PGM(QUSCRTUS) PARM(&USP_QUAL &USP_TYPE +
                          &USP_SIZE &USP_FILL &USP_AUT &USP_TEXT)

             CHGVAR     VAR(&API_USQUAL) VALUE(&USP_QUAL)
             CHGVAR     VAR(&API_JBNAM)  VALUE(&MYJOBNAME)
     /*      CHGVAR     VAR(&API_USER)   VALUE('*ALL')      */
             CHGVAR     VAR(&API_USER)   VALUE(&JOBUSER)
             CHGVAR     VAR(&API_JOBNR)  VALUE('*ALL')
             CHGVAR     VAR(&API_STATUS) VALUE('*ACTIVE')
             CHGVAR     VAR(&API_JBQUAL) VALUE(&API_JBNAM *CAT +
                          &API_USER *CAT &API_JOBNR)

             CALL       PGM(QUSLJOB) PARM(&API_USQUAL 'JOBL0200' +
                          &API_JBQUAL &API_STATUS X'00000000' +
                          &TYPE &NBRTORTN &KEYSTORTN)

             CHGVAR     VAR(%BIN(&STARTPOS)) VALUE(1)
             CHGVAR     VAR(%BIN(&DATALEN))  VALUE(140)

             CALL       PGM(QUSRTVUS) PARM(&API_USQUAL &STARTPOS +
                          &DATALEN &HEADER)

             CHGVAR     VAR(&LST_OFFSET) VALUE(%BIN(&HEADER 125 4))
             CHGVAR     VAR(&LST_SIZE)   VALUE(%BIN(&HEADER 129 4))
             CHGVAR     VAR(&LST_NBR)    VALUE(%BIN(&HEADER 133 4))
             CHGVAR     VAR(&LST_LEN)    VALUE(%BIN(&HEADER 137 4))

             CHGVAR     VAR(%BIN(&LST_POSBIN)) VALUE(&LST_OFFSET + 1)
             CHGVAR     VAR(&LST_LENBIN) VALUE(%SST(&HEADER 137 4))

             CHGVAR     VAR(&LST_COUNT) VALUE(0)
             CHGVAR     VAR(&EXC_COUNT) VALUE(0)

             IF (&LST_NBR *EQ 0) DO

             IF (&JOBUSER *EQ '*ALL') DO
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Job' +
                          *BCAT &MYJOBNAME *BCAT 'was not found!') +
                          MSGTYPE(*ESCAPE)
             ENDDO
             ELSE DO
             ENDDO
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +
                          MSGDTA('User' *BCAT &JOBUSER *BCAT +
                                 'run job' *BCAT &MYJOBNAME *BCAT +
                                 'was not found!') +
                          MSGTYPE(*ESCAPE)

             ENDDO

 LST_LOOP:   IF         COND(&LST_COUNT *EQ &LST_NBR) THEN(GOTO +
                          CMDLBL(LST_END))

             CALL       PGM(QUSRTVUS) PARM(&API_USQUAL &LST_POSBIN +
                          &LST_LENBIN &LST_DATA)

             CHGVAR     VAR(&JOBNAME) VALUE(%SST(&LST_DATA 1 10))
             CHGVAR     VAR(&USER)    VALUE(%SST(&LST_DATA 11 10))
             CHGVAR     VAR(&JOBNBR)  VALUE(%SST(&LST_DATA 21 6))
             CHGVAR     VAR(&STATUS)  VALUE(%SST(&LST_DATA 43 10))
             CHGVAR     VAR(&JOBTYPE) VALUE(%SST(&LST_DATA 53 1))
             CHGVAR     VAR(&SUBTYPE) VALUE(%SST(&LST_DATA 54 1))
      /* for status */
             CHGVAR     VAR(&WRKSTS ) VALUE(%SST(&LST_DATA 81 4))
      /* for subsystem */
             CHGVAR     VAR(&SBSSYS ) VALUE(%SST(&LST_DATA 101 20))

             IF         COND(&MYJOBNAME *EQ '*ALL'   *OR +
                             &JOBNAME *EQ &MYJOBNAME) THEN(DO)

             IF  ((&SBSD *EQ '*ALL') *OR +
                  (&SBSDANDLIB *EQ &SBSSYS)) DO

             CHGVAR &JOBWRKSTS %SST(&JOBSTS 2 4)

             IF  ((&JOBSTS *EQ '*ALL') *OR +
                  (&JOBWRKSTS *EQ &WRKSTS))  DO

             IF (&ACTION *NE '*CMD') DO
             IF (&ACTION  *EQ '*CHG') +
                CHGVAR &CMDSTR 'CHGJOB'
             IF (&ACTION  *EQ '*END') +
                CHGVAR &CMDSTR 'ENDJOB'
             IF (&ACTION  *EQ '*HLD') +
                CHGVAR &CMDSTR 'HLDJOB'
             IF (&ACTION  *EQ '*RLS') +
                CHGVAR &CMDSTR 'RLSJOB'
             IF (&ACTION  *EQ '*DSP') DO
                CHGVAR &CMDSTR 'DSPJOB'
                CHGVAR &JOBOPT 'OPTION(*ALL) OUTPUT(*PRINT)'
             ENDDO

             CHGVAR  &CMDSTR (&CMDSTR *BCAT 'JOB(' *TCAT +
                              &JOBNBR *TCAT '/' *CAT +
                              &USER   *TCAT '/' *CAT +
                              &JOBNAME *TCAT ')' *BCAT &JOBOPT)


             ENDDO
             ELSE DO
             CHGVAR  &CMDSTR &CMD
             ENDDO

             CHGVAR     VAR(&EXC_COUNT) VALUE(&EXC_COUNT + 1)

             IF (&ACTION  *EQ '*MSG') DO
                SNDPGMMSG MSG('Job' *BCAT +
                                &JOBNBR *TCAT '/' *CAT +
                                &USER   *TCAT '/' *CAT +
                                &JOBNAME *BCAT 'status is' *BCAT +
                                &WRKSTS *TCAT '.') +
                                TOUSR(&TOUSR)
             ENDDO
             ELSE   DO
             CHGVAR     VAR(&CMDLEN) VALUE(3000)
             CALL       PGM(QCMDEXC) PARM(&CMDSTR &CMDLEN)
             MONMSG     MSGID(CPF1346 CPF1349)
             IF (&ACTION  *EQ '*DSP') DO
             CHGVAR  &CMDSTR ('DSPJOB' *BCAT 'JOB(' *TCAT +
                              &JOBNBR  *TCAT '/' *CAT +
                              &USER    *TCAT '/' *CAT +
                              &JOBNAME *TCAT ')' *BCAT  +
                              'OPTION(*JOBLOG) OUTPUT(*PRINT)')
             CHGVAR     VAR(&CMDLEN) VALUE(3000)
             CALL       PGM(QCMDEXC) PARM(&CMDSTR &CMDLEN)
             MONMSG     MSGID(CPF1346 CPF1349)
             ENDDO

             ENDDO

             ENDDO  /* ENDDO JOBSTS  */

             ENDDO  /* ENDDO SBSD    */

             ENDDO  /* ENDDO JOBNAME */

             CHGVAR     VAR(&LST_COUNT) VALUE(&LST_COUNT + 1)
             CHGVAR     VAR(%BIN(&LST_POSBIN)) +
                          VALUE(%BIN(&LST_POSBIN) + &LST_LEN)
             GOTO       CMDLBL(LST_LOOP)

 LST_END:
             IF (&EXC_COUNT *EQ 0) DO
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +
                  MSGDTA('User' *BCAT &JOBUSER *BCAT +
                         'run job' *BCAT &MYJOBNAME *BCAT +
                         'under subsystem' *BCAT +
                         &RTNSBSDLIB *TCAT '/' *CAT &SBSD *BCAT +
                         'was not found!') +
                  MSGTYPE(*ESCAPE)
             ENDDO

             DLTUSRSPC  USRSPC(&USP_LIB/&USP_NAME)

             Return

/*  ===============================================================  */
/*  = Error routine                                               =  */
/*  ===============================================================  */

Error:

  RcvMsg     MsgType( *Excp )                                         +
             MsgDta( &MsgDta )                                        +
             MsgID( &MsgID )                                          +
             MsgF( &MsgF )                                            +
             MsgFLib( &MsgFLib )
  MonMsg     ( CPF0000 MCH0000 )

SndMsg:

  SndPgmMsg  MsgID( &MsgID )                                          +
             MsgF( &MsgFLib/&MsgF )                                   +
             MsgDta( &MsgDta )                                        +
             MsgType( *Escape )
  MonMsg     ( CPF0000 MCH0000 )

/*  ===============================================================  */
/*  = End of program                                              =  */
/*  ===============================================================  */

ENDPGM



File  : QCMDSRC
Member: CHKACTJOB
Type  : CMD
Usage : CRTCMD CMD(lib/CHKACTJOB) PGM(lib/CHKACTJOB)
        

/*  ===============================================================  */
/*  = Command....... ChkJob                                       =  */
/*  = CPP........... ChkJob                                       =  */
/*  = Description... Check Job by job name and subsystem          =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( ChkJob )                                   =  */
/*  =             Pgm( ChkJob )                                   =  */
/*  =             SrcFile( YourSourceFile )                       =  */
/*  ===============================================================  */
/*  = Date  : 2007/06/04                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */
/*  = Date  : 2007/06/21                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  =         Added  on ACTION *MSG to send status message to user=  */
/*  ===============================================================  */
/*  = Date  : 2007/08/08                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  =         Added  on JOBSTS keyword to limit job processing    =  */
/*  ===============================================================  */
/*  = Date  : 2007/08/14                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  =         Added on ACTION *DSP to display job information     =  */
/*  =               DSPJOB OPTION(*ALL) OUTPUT(*PRINT)            =  */
/*  =               DSPJOB OPTION(*JOBLOG) OUTPUT(*PTINT)         =  */
/*  ===============================================================  */
             CMD        PROMPT('Check Job')

             PARM       KWD(JOBNAME) TYPE(*NAME) SPCVAL((*ALL)) +
                          MIN(1) PROMPT('Job name')

             PARM       KWD(JOBUSER) TYPE(*NAME) SPCVAL((*ALL)) +
                          MIN(1) PROMPT('Job user')

             PARM       KWD(SBS) TYPE(SBSD) MIN(1) PROMPT('Job +
                          running under subsystem')

             PARM       KWD(JOBSTS) TYPE(*CHAR) LEN(5) RSTD(*YES) +
                          DFT(*ALL) VALUES(*ALL *MSGW) PROMPT('Job +
                          selection by ACTJOB status')

             PARM       KWD(ACTION) TYPE(*CHAR) LEN(5) RSTD(*YES) +
                          DFT(*MSG) VALUES(*DSP *CHG *END *HLD *RLS +
                          *MSG *CMD) EXPR(*YES) PROMPT('Action')

             PARM       KWD(JOBOPT) TYPE(*CHAR) LEN(3000) +
                          PMTCTL(IFPGM) PROMPT('Job command option +
                          DSP,CHG,END')

             PARM       KWD(TOUSR) TYPE(*NAME) LEN(10) +
                          SPCVAL((*SYSOPR)) PMTCTL(IFTOUSR) +
                          PROMPT('Send status message to user')

             PARM       KWD(CMD) TYPE(*CMDSTR) LEN(3000) +
                          PMTCTL(IFCMD) PROMPT('Command to run')

 SBSD:       QUAL       TYPE(*NAME) LEN(10) SPCVAL((*ALL)) EXPR(*YES)
             QUAL       TYPE(*NAME) LEN(10) DFT(*LIBL) +
                          SPCVAL((*LIBL) (*CURLIB)) EXPR(*YES) +
                          PROMPT('Library')

 IFPGM:      PMTCTL     CTL(ACTION) COND((*EQ *CHG))
             PMTCTL     CTL(ACTION) COND((*EQ *END)) LGLREL(*OR)

 IFTOUSR:    PMTCTL     CTL(ACTION) COND((*EQ *MSG))

 IFCMD:      PMTCTL     CTL(ACTION) COND((*EQ *CMD))

             DEP        CTL(&ACTION *EQ *CHG) PARM((JOBOPT))
             DEP        CTL(&ACTION *EQ *END) PARM((JOBOPT))
             DEP        CTL(&ACTION *EQ *MSG) PARM((TOUSR))
             DEP        CTL(&ACTION *EQ *CMD) PARM((CMD))


File  : QCLSRC
Member: CHKACTJOBT
Type  : CLP
Usage : CRTCLPGM PGM(lib/CHKACTJOBT)
        CALL CHKACTJOBT
                                                      
PGM

             DCL &MSGTXT *CHAR 256

             CHKACTJOB  JOBNAME(QSYSSCD) JOBUSER(QPGMR) SBS(QINTER) +
                          ACTION(*CHG) JOBOPT('RUNPTY(10)')
             MONMSG     CPF9898  EXEC(DO)
             RCVMSG     MSGTYPE(*EXCP) MSG(&MSGTXT)
             DMPCLPGM
             ENDDO

             CHKACTJOB  JOBNAME(QSYSSCD) JOBUSER(QPGMR) SBS(QCTL) +
                          ACTION(*MSG) TOUSR(*SYSOPR)
             MONMSG     CPF9898  EXEC(DO)
             RCVMSG     MSGTYPE(*EXCP) MSG(&MSGTXT)
             DMPCLPGM
             ENDDO

             CHKACTJOB  JOBNAME(QSYSSCD) JOBUSER(QPGMR) SBS(QCTL) +
                          JOBSTS(*MSGW) ACTION(*MSG) TOUSR(*SYSOPR)
             MONMSG     CPF9898  EXEC(DO)
             RCVMSG     MSGTYPE(*EXCP) MSG(&MSGTXT)
             DMPCLPGM
             ENDDO

             CHKACTJOB  JOBNAME(QSYSSCD) JOBUSER(QPGMR) SBS(QCTL) +
                          JOBSTS(*MSGW) ACTION(*MSG) TOUSR(*SYSOPR)
             MONMSG     CPF9898             

ENDPGM


回應
AS/400 系統應用電子報





Powered by Xuite
    沒有新回應!
平均分數:0 顆星
投票人數:0
我要評分:
關鍵字
IBM 最佳夥伴
AS/400 非官方網站