星期四, 11月 09, 2023

2016-10-04 Check MQ Job by APPLTYPE USER or SYSTEM(CHKMQJOB) with StrMqmMqsc command output


Check MQ Job by APPLTYPE USER or SYSTEM(CHKMQJOB) with StrMqmMqsc command output

File  : QCLSRC
Member: CHKMQJOBC
Type  : CLP
Usage : CRTCLPGM PGM(CHKMQJOBC)		
        




/*-------------------------------------------------------------------*/
/*                                                                   */
/*  Program . . : CHKMQJOB                                           */
/*  Description : Check MQ User Job                                  */
/*  Author  . . : Vengoal Chang                                      */
/*  Published . : AS400ePaper                                        */
/*  Date  . . . : July 25, 2016                                      */
/*                                                                   */
/*  Program function:  CHKMQJOB command processing program           */
/*                                                                   */
/*                                                                   */
/*  Programmer's notes:                                              */
/*    CRTSRCPF FILE(QGPL/MQSRC) TEXT('MQ CMD SRC')                   */
/*    Put following line to file QGPL/MQSRC menber CHKMQJOB          */
/*    DISPLAY CONN(*) TYPE(CONN) APPLTAG APPLTYPE                    */
/*                                                                   */
/*  Compile options:                                                 */
/*    CrtClPgm   Pgm( CHKMQJOB )                                     */
/*               SrcFile( QCLSRC )                                   */
/*               SrcMbr( *PGM )                                      */
/*                                                                   */
/*-------------------------------------------------------------------*/
     Pgm      ( &Qmgr                  +
                &ApplType              +
                &JobAction             +
              )

/*-- Parameters:  ---------------------------------------------------*/
     Dcl        &Qmgr        *Char    48
     Dcl        &ApplType    *Char    10
     Dcl        &JobAction   *Char    10
     Dcl        &MqSrcFile   *Char    10    'MQSRC'
     Dcl        &MqSrcLib    *Char    10    'QGPL'
     Dcl        &MqSrcMbr    *Char    10    'CHKMQJOB'

/*-- Global error monitoring:  --------------------------------------*/
     MonMsg     CPF0000      *N        GoTo Error

     DltF       File(Qtemp/MqJobLst)
     MonMsg     CPF2105

     CrtPf      File(Qtemp/MqJobLst) RcdLen(133) IgcDta(*Yes)

     StrMqmMqsc SrcMbr(&MqSrcMbr) SrcFile(&MqSrcLib/&MqSrcFile) +
                          MqmName(&Qmgr)

     CpySplf    File(QsysPrt) ToFile(Qtemp/MqJobLst) SplNbr(*Last)

     Call       ChkMqJobR (&Qmgr &ApplType &JobAction)
     MonMsg     CPF9898

     DltSplF    File(QsysPrt) SplNbr(*Last)

 Return:
     Return

/*-- Error handling:  -----------------------------------------------*/
 Error:
     Call      QMHMOVPM    ( '    '                                  +
                             '*DIAG'                                 +
                             x'00000001'                             +
                             '*PGMBDY'                               +
                             x'00000001'                             +
                             x'0000000800000000'                     +
                           )

     Call      QMHRSNEM    ( '    '                                  +
                             x'0000000800000000'                     +
                           )

 EndPgm:
     EndPgm



File  : QRPGLESRC
Member: CHKMQJOBR
Type  : RPGLE
Usage : CRTBNDRPG PGM(CHKMQJOBR)		

       


     H DEBUG  OPTION(*SRCSTMT:*NODEBUGIO) dftactgrp(*NO)

     FMQJOBLST  IF   F  133        DISK

     **-- API error information:
     D ERRC0100        Ds                  Qualified
     D  BytPro                       10i 0 Inz( %Size( ERRC0100 ))
     D  BytAvl                       10i 0
     D  MsgId                         7a
     D                                1a
     D  MsgDta                      256a
     **-- Global variables:
     D MsgKey          s              4a

     **-- Send program message:
     D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
     D  SpMsgId                       7a   Const
     D  SpMsgFq                      20a   Const
     D  SpMsgDta                    128a   Const
     D  SpMsgDtaLen                  10i 0 Const
     D  SpMsgTyp                     10a   Const
     D  SpCalStkE                    10a   Const  Options( *VarSize )
     D  SpCalStkCtr                  10i 0 Const
     D  SpMsgKey                      4a
     D  SpError                   32767a          Options( *VarSize )

     **-- Send completion message:
     D SndCmpMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying
     **-- Send escape message:
     D SndEscMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying

     D ParseInput      PR

     D GetAtrValue     PR           512    Varying
     D  inputStr                    512    Const Varying
     D  atrName                      64    Const Varying

     **-- Execute command:
     D RunCmd          Pr                  ExtPgm( 'QCMDEXC' )
     D  CmdStr                     4096a   Const  Options( *VarSize )
     D  CmdLen                       15p 5 Const
     D  CmdIGC                        3a   Const  Options( *NoPass )

     D InputData       DS
     D   saInput                    133A

     D APPLTAGDS       DS                  dim(100) qualified
     D  CONNID                       16
     D  APPLTAG                      28
     D  APPLTYPE                     10

     D idx             S             10I 0
     D jobCount        S             10I 0
     D jobCmd          S            128
     D mqJob           S             52
     D AtrValue        S            512a   Varying

     C     *Entry        Plist
     C                   Parm                    pMqmName         48
     C                   Parm                    pApplType        10
     C                   Parm                    pJobAction       10

     C                   READ      MQJOBLST      InputData                LR
     C                   DOW       *INLR = *OFF
     C                   CALLP     ParseInput
     C                   READ      MQJOBLST      InputData                LR
     C                   ENDDO

     C                   eval      jobCount = idx
     C
     C                   For       idx = 1 to jobCount
1B   C                   If        pApplType='USER'
2B   C                   If        %trim(APPLTAGDS(idx).APPLTYPE) = 'USER'
 3b  C                   If        pJobAction = '*DSP'
     C                   eval      mqJob = APPLTAGDS(idx).APPLTYPE +
     C                                     APPLTAGDS(idx).APPLTAG
     C                   callp     SndCmpMsg('DISPLAY ' + mqJob)
 3x  C                   Else
  4b C                   If        pJobAction = '*ENDJOB'
     C                   eval      jobCmd = 'ENDJOB JOB(' +
     C                                      %trim(APPLTAGDS(idx).APPLTAG) +
     C                                      ') OPTION(*IMMED)'
     C                   callp(e)  RunCmd(%Trim(jobCmd):%Len(%Trim(jobcmd)))
  4e C                   EndIf
  4b C                   If        pJobAction = '*ENDCNN'
     C                   eval      jobCmd = 'ENDMQMCONN CONN(' +
     C                                      %trim(APPLTAGDS(idx).CONNID) +
     C                                      ') MQMNAME(' +
     C                                      %trim(pMqmName) + ')'
     C                   callp(e)  RunCmd(%Trim(jobCmd):%Len(%Trim(jobcmd)))
  4e C                   EndIf
  4b C                   If        %error
     C                   Callp     SndEscMsg ('Command Error:' +
     C                                         %trim(jobCmd)   +
     C                                        ', please see joblog'
     C                                       )
     C                   Else
     C                   Callp     SndCmpMsg ('Command :' +
     C                                         %trim(jobCmd)   +
     C                                        ' completed.'
     C                                       )
  4e C                   EndIf
 3e  C                   EndIf
2e   C                   EndIf
1X   C                   Else
2b   C                   If        %trim(APPLTAGDS(idx).APPLTYPE) <>'USER'
     C                   eval      mqJob = APPLTAGDS(idx).APPLTYPE +
     C                                     APPLTAGDS(idx).APPLTAG
     C                   callp     SndCmpMsg('DISPLAY ' + mqJob)
2e   C                   EndIf
1e   C                   EndIf
     C
     C                   EndFor

      **********************************************************************

     P ParseInput      B

     D ParseInput      PI

     C                   eval      AtrValue=
     C                               %trim(GetAtrValue(saInput: 'CONN'))
     C                   If        %len(%trim(AtrValue)) = 16
     C                   eval      idx = idx + 1
     C                   eval      APPLTAGDS(idx).CONNID  = %trim(AtrValue)
     C                   EndIf

     C                   eval      AtrValue=
     C                               %trim(GetAtrValue(saInput: 'APPLTAG'))
     C                   If        %len(%trim(AtrValue)) > 0
     C                   eval      APPLTAGDS(idx).APPLTAG = %trim(AtrValue)
     C                   eval      AtrValue=
     C                               %trim(GetAtrValue(saInput: 'APPLTYPE'))
     C                   eval      APPLTAGDS(idx).APPLTYPE=%trim(AtrValue)
     C                   EndIf

     P ParseInput      E


     P GetAtrValue     B

     D GetAtrValue     PI           512    Varying
     D  pInputStr                   512a   Const  Varying
     D  pAtrName                     64a   Const  Varying

     D  AtrName        S            512a
     D  AtrValue       S            512a   Varying

     C                   eval      AtrValue = ''
     C                   z-add     0             Str               5 0
     C                   z-add     0             End               5 0
     C                   Eval      AtrName = %trim(pAtrName)+ '('
     C                   Eval      Str=%Scan(%trim(AtrName): pInputStr: 1)
     C                   If        Str > 0
     C                   Eval      End=%Scan(%trim(')'):saInput: Str)
     C                   Eval      AtrValue =
     C                              %SubSt(pInputStr:
     C                                     str+%len(%trim(AtrName)):
     C                                     End-(str+%len(%trim(AtrName))))
     C                   EndIf

     C                   Return            AtrValue

     P GetAtrValue     E
     **-- Send escape message:  ----------------------------------------------**
     P SndEscMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying

      /Free

        SndPgmMsg( 'CPF9898'
                 : 'QCPFMSG   *LIBL'
                 : PxMsgDta
                 : %Len( PxMsgDta )
                 : '*ESCAPE'
                 : '*PGMBDY'
                 : 1
                 : MsgKey
                 : ERRC0100
                 );

        If  ERRC0100.BytAvl > *Zero;
          Return  -1;

        Else;
          Return  0;

        EndIf;

      /End-Free

     P SndEscMsg       E
     **-- Send completion message:  ------------------------------------------**
     P SndCmpMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying

      /Free

        SndPgmMsg( 'CPF9897'
                 : 'QCPFMSG   *LIBL'
                 : PxMsgDta
                 : %Len( PxMsgDta )
                 : '*COMP'
                 : '*PGMBDY'
                 : 1
                 : MsgKey
                 : ERRC0100
                 );

        If  ERRC0100.BytAvl > *Zero;
          Return  -1;

        Else;
          Return  0;

        EndIf;

      /End-Free

     **
     P SndCmpMsg       E



File  : QCMDSRC
Member: CHKMQJOB
Type  : CMD
Usage : CrtCmd Cmd( CHKMQJOB  )
               Pgm( CHKMQJOBC )
               SrcMbr( CHKMQJOB  )			   
			   
        CRTSRCPF FILE(QGPL/MQSRC) TEXT('MQ CMD SRC')                   
        Put following line to file QGPL/MQSRC menber CHKMQJOB          
        DISPLAY CONN(*) TYPE(CONN) APPLTAG APPLTYPE                    

        

						
/*-------------------------------------------------------------------*/
/*                                                                   */
/*  Compile options:                                                 */
/*                                                                   */
/*    CrtCmd Cmd( CHKMQJOB  )                                        */
/*           Pgm( CHKMQJOBC )                                        */
/*           SrcMbr( CHKMQJOB  )                                     */
/*                                                                   */
/*-------------------------------------------------------------------*/
             Cmd      Prompt( 'Check MQ Job')

             Parm       QMNAME       *Char      48         +
                        Min(1)                             +
                        Prompt('Queue manager name')

             PARM       ApplType     *Char      10         +
                        Rstd(*YES)                         +
                        Dft(USER)                          +
                        Values(USER SYSTEM)                +
                        Prompt('Application type')

             PARM       JobAction    *Char      10         +
                        Rstd(*YES)                         +
                        Dft(*DSP)                          +
                        Values(*DSP *ENDCNN *ENDJOB)       +
                        PmtCtl( P0001 )                              +
                        Prompt('Job action')

 P0001:      PmtCtl     Ctl( APPLTYPE )                              +
                        Cond(( *EQ 'SYSTEM' ))

             DEP        Ctl(&APPLTYPE *EQ 'SYSTEM')                  +
                        Parm((&JOBACTION *EQ '*DSP'))                +
                        NbrTrue( *EQ  1 )


Command sample:
                             Check MQ Job (CHKMQJOB)                            
                                                                                
 Type choices, press Enter.                                                     
                                                                                
 Queue manager name . . . . . . .                                               
                                                                                
 Application type . . . . . . . .   USER          USER, SYSTEM                  
 Job action . . . . . . . . . . .   *DSP          *DSP, *ENDCNN, *ENDJOB        

Note: 
*DSP    => display MQ job info
*ENDCNN => end MQ USER connection handle
*ENDJOB => end MQ USER connection job


參照: Start IBM MQ Commands (STRMQMMQSC)

參照: DISPLAY CONN




沒有留言: