星期二, 11月 07, 2023

2006-12-20 如何擷取某工作 Joblog 中某一 MsgID 的訊息內容是否包含指定字串?(Command SCNJOBLOG)


如何擷取某工作 Joblog 中某一 MsgID 的訊息內容是否包含指定字串?(Command SCNJOBLOG)

File  : QRPGLESRC
Member: SCNJOBMSGR
Type  : RPGLE
Usage : CRTBNDRPG SCNJOBMSGR

     H DFTACTGRP(*NO) ACTGRP(*CALLER) BNDDIR('QC2LE') EXPROPTS(*RESDECPOS)
     H DATFMT(*ISO)   TIMFMT(*ISO)    OPTION(*NODEBUGIO) DEBUG
      *----------------------------------------------------------------
      * SCNJOBLOG  Scan specified job's job log by MSGID to
      * search some string in job log
      * Copyright (C) 12/12/2006  Vengoal Chang    
      * This program is free software, you can redistribute it and/or modify it under the terms
      * of the GNU General Public License as published by the Free Software Foundation.
      *
      *----------------------------------------------------------------
      * This program retrieve specified job job's log and return found
      * search string or not.
      *
      * CRTBNDRPG with target release V5R1 and later
      *
      *----------------------------------------------------------------
      * api (application program interfaces) used:
      * quscrtus  create user space
      * qusptrus  retrieve pointer to user space
      * qmhljobl  list job log messages
      * qmhsndm   send non-program messages
      *----------------------------------------------------------------
     D uSpaceName      s             20    inz('RTVJOBLOG QTEMP     ')
     D msgtxt          s            256
     D QUSLIB          s             10

      *  -------------------------------------------------------------------
      *  -  User space attributes data structure                           -
      *  -------------------------------------------------------------------

     D QUSAttr         DS
     D  QUSNumRec                    10I 0 Inz( 1 )
     D  QUSKey                       10I 0 Inz( 3 )
     D  QUSRecLen                    10I 0 Inz( 1 )
     D  QUSRecData                    1A   Inz( '1' )
      *----------------------------------------------------------------
     D struct          DS
     D  msgdln                       10I 0
     D  msgq#                        10I 0
     D  msgkey                        4
     D  msgq                         20    INZ('QSYSOPR   *LIBL     ')
      *
      *----------------------------------------------------------------
      * Get user space list info from header section.
      *----------------------------------------------------------------
     D                 ds                  based(uHeadPtr)
     D uOffSetToList         125    128i 0
     D uNumOfEntrys          133    136i 0
     D uSizeOfEntry          137    140i 0
      *
     D uListEntry1     ds                  Based(uListPtr )
     D uOffsetToNext                 10i 0 overlay(uListEntry1:1)
     D uOffsetToFlds                 10i 0 overlay(uListEntry1:5)
     D uNumFldsRetrnd                10i 0 overlay(uListEntry1:9)
     D uMsgSeverity                  10i 0 overlay(uListEntry1:12)
     D uMsgId                         7a   overlay(uListEntry1:17)
     D uMsgType                       2a   overlay(uListEntry1:24)
     D uMsgKey                        4a   overlay(uListEntry1:26)
     D uMsgFile                      20a   overlay(uListEntry1:30)
     D uMsgFileName                  10a   overlay(uListEntry1:30)
     D uMsgFileLib                   10a   overlay(uListEntry1:40)
      * these fields repeat for each key selected.
     D uListEntry2     ds                  Based(uListPtr2)
     D u2OffsetToNext                10i 0
     D u2LengthOfFlds                10i 0
     D u2IdentifierF                 10i 0
     D u2TypeOfData                   1a
     D u2StatOfData                   1a
     D u2Reserved                    14a
     D u2LengthOfData                10i 0
     D u2Data                       500
      *----------------------------------------------------------------
      * Error return code parm for APIs.
      *----------------------------------------------------------------
     D vApiErrDs       ds
     D  vbytpv                       10i 0 inz(%size(vApiErrDs))
     D  vbytav                       10i 0 inz(0)
     D  vmsgid                        7a
     D  vresvd                        1a
     D  vrpldta                      50a
      *
      *----------------------------------------------------------------
      * Message selection data structure.
      *
      *                               Retrieve JOB Log direction
      *-----------------------------|-------------|--------------------
      * Parameter                   | From Top    | From Bottom
      *-----------------------------|-------------|--------------------
      * msListDirection             | *NEXT       | *PRV
      * msStartingMessageKey        | X'00000000' | X'FFFFFFFF'
      *----------------------------------------------------------------
     D MsgSelectDS     ds
     D  msMaxMsgRequested...
     D                               10i 0 inz(-1)     overlay(msgSelectDS:1)   num of msg requested
     D  msListDirection...
     D                               10a   inz('*NEXT') overlay(msgSelectDS:5)   List direction
     D  msQualifiedJobName...
     D                               10a   inz('*')    overlay(msgSelectDS:15)     * = current job
     D  msQualifiedUserName...
     D                               10a   inz(' ')    overlay(msgSelectDS:25)       = current job
     D  msQualifiedJobNumber...
     D                                6a   inz(' ')    overlay(msgSelectDS:35)       = current job
     D  msInternalJobIdentifier...
     D                               16a   inz(' ')    overlay(msgSelectDS:41)       = current job
     D  msStartingMessageKey...
     D                                4a   inz(x'00000000')                     start newest message
     D                                                 overlay(msgselectDS:57)
     D  msMaxMsgLength...
     D                               10i 0 inz(500)    overlay(msgSelectDS:61)  id 301,302 lengths
     D  msMaxMsgHelpLength...
     D                               10i 0 inz(100)    overlay(msgSelectDS:65)  id 401,402,403,404
     D  msOffsetToIdentifiersOfFieldstoReturn...
     D                               10i 0 inz(84)     overlay(msgSelectDS:69)  to start of array
     D  msNumberOfFieldsToReturn...
     D                               10i 0 inz(1)      overlay(msgSelectDS:73)
     D  msOffsetToCallMsgQname...
     D                               10i 0 inz(88)     overlay(msgSelectDS:77)
     D  msLengthOfCallMsgQname...
     D                               10i 0 inz(1)      overlay(msgSelectDS:81)
     D  msIndentifiersOfFieldsToReturn...
     D                               10i 0 inz(0302)   overlay(msgSelectDS:85)
     D  msCallMessageQueueName...
     D                                1a   inz('*')    overlay(msgSelectDS:89)
      *----------------------------------------------------------------
      * Create Prototypes for calls
      * --------------------------------------------------------------------
      *  -  QusCrtUs  - Create User Space API                              -
      *  -                                                                 -
      *  -  Usage      Length   Type         Parameter Description         -
      *  -                                                                 -
      *  -  Input          20   Character    Qualified user space name     -
      *  -  Input          10   Character    Extended attribute            -
      *  -  Input         4 0   Binary       Initial size                  -
      *  -  Input           1   Character    Initial value                 -
      *  -  Input          10   Character    Public authority              -
      *  -  Input          50   Character    Text description              -
      * --------------------------------------------------------------------
     D quscrtus        PR                  ExtPgm('QUSCRTUS')
     D                               20
     D                               10    const
     D                               10i 0 const
     D                                1    const
     D                               10    const
     D                               50    const
     D                               10    const
     Db                                    like(vApiErrDS)
      *  -------------------------------------------------------------------
      *  -  Qusptrus      - Get user space pointer       API               -
      *  -                                                                 -
      *  -  Usage      Length   Type         Parameter Description         -
      *  -                                                                 -
      *  -  Input          20   Character    Qualified user space name     -
      *  -  Output          *   Pointer      UserSpace Pointer             -
      *  -  Output                           Error Code                    -
      *  - -----------------------------------------------------------------
     D qusptrus        PR                  ExtPgm('QUSPTRUS')                   retrieve pointer
     D                               20                                         Space Name
     D                                 *                                        pointer
     Db                                    like(vApiErrDS)                      error parm
      *  -------------------------------------------------------------------
      *  -  Quscusat      - Change User Space Attributes API               -
      *  -                                                                 -
      *  -  Usage      Length   Type         Parameter Description         -
      *  -                                                                 -
      *  -  Output         10   Character    Returned library              -
      *  -  Input          20   Character    Qualified user space name     -
      *  -  Input          13   Character    Attribute structure           -
      *  -  Output                           Error code                    -
      *  -------------------------------------------------------------------
     D quscusat        PR                  ExtPgm( 'QUSCUSAT' )
     D                               10A   Const
     D                               20A   Const
     D                               13A   Const
     Db                                    like(vApiErrDS)
      *  ---------------------------------------------------------------
     D system          PR            10I 0 extproc('system')
     D  i_cmd                          *   value options(*string)
      *
     D EXCP_MSGID      S              7A   import('_EXCP_MSGID')
      *  --------------------------------------------------------------
     D qmhljobl        PR                  ExtPgm('QMHLJOBL ')
     D                               20
     D                                8    const
     Db                                    like(MsgSelectDS)
     D                               10i 0 const
     D                                8    const
     Db                                    like(vApiErrDS)
      *  --------------------------------------------------------------
     D SNDPGMMSG       PR                  EXTPGM('QMHSNDPM')
     D   MESSAGEID                    7A   CONST
     D   QUALMSGF                    20A   CONST
     D   MSGDATA                    256A   CONST
     D   MSGDTALEN                   10I 0 CONST
     D   MSGTYPE                     10A   CONST
     D   CALLSTKENT                  10A   CONST
     D   CALLSTKCNT                  10I 0 CONST
     D   MESSAGEKEY                   4A
     D   ERRORCODE                32766A   OPTIONS(*VARSIZE)
      *  --------------------------------------------------------------

     D main            PR                  extpgm('SCNJOBLOGR')
     D  jobname                      10
     D  jobuser                      10
     D  jobnumber                     6
     D  msgId                         7
     D  searchStr                    48
     D  includeQuote                  4
     D  StrFound                      1

     D main            PI
     D  jobname                      10
     D  jobuser                      10
     D  jobnumber                     6
     D  msgId                         7
     D  searchStr                    48
     D  includeQuote                  4
     D  StrFound                      1

     D  searchString   S             50
     D  strpos         S              5I 0
     D  quote          S              1    Inz('''')
     D WWMSGLEN        S             10I 0
     D WWTHEKEY        S              4A
      *----------------------------------------------------------------
     C                   eval      msQualifiedJobName   = jobname
     C                   eval      msQualifiedUserName  = jobuser
     C                   eval      msQualifiedJobNumber = jobnumber
     C                   If        includeQuote = '*YES'
     C                   eval      searchString  = quote + %trim(searchStr) +
     C                                             quote
     C                   Else
     C                   eval      searchString  = %trim(searchStr)
     C                   EndIf
     C                   eval      StrFound = '0'
      *----------------------------------------------------------------
      * Create user space
     C                   callp     QUSCRTUS(
     C                             uSpaceName:
     C                             'TEST':
     C                             1500000:
     C                             x'00':
     C                             '*ALL':
     C                             'User Space RTVJOBLOG' :
     C                             '*NO':
     C                             vApiErrDs)
      * set UserSpace to autoextended
     C                   CallP     QUSCUSAT( QUSLib     :
     C                                       uSpaceName :
     C                                       QUSAttr    :
     C                                       vApiErrDs  )
      * Get pointer to user space
     C                   callp     QUSPTRUS(
     C                             uSpaceName:
     C                             uHeadPtr:
     C                             vApiErrDs)
      * call api to load job log into user space.
     C                   callp     QMHLJOBL(
     C                             uSpaceName:
     C                             'LJOB0100':
     C                             MsgSelectDS:
     C                             %len(MsgSelectDS):
     C                             'JSLT0100':
     C                             vApiErrDs)
      * Process elements
      *
     C                   If        vbytav = 0
     C                   eval      uListPtr  = uHeadPtr + uOffSetToList
 1B  C                   do        uNumOfEntrys

     C                   If        uMsgId = msgId
     C                   eval      uListPtr2 = uHeadPtr + uOffsetToFlds

     C                   eval      msgtxt = %subst(u2Data:1:U2LengthOfData)
     C                   eval      strPos = %scan(%trim(searchString) : msgtxt)
     C                   If        strPos > 0
     C                   eval      StrFound = '1'
     C                   leave
     C                   EndIf

     C                   EndIf

     C                   eval      uListPtr  = uHeadPtr  + uOffsetToNext
 1E  C                   enddo
     C                   Else
     C                   eval      msgtxt = 'API Error: ' + vmsgid +
     C                                 '. Please see job log for detail'
     C                   eval      WWMSGLEN = %len(%trimr(msgtxt))
     C                   CALLP     SNDPGMMSG('CPF9897': 'QCPFMSG   *LIBL':
     C                               msgtxt:WWMSGLEN: '*ESCAPE':
     C                               '*PGMBDY': 1: WWTHEKEY: vApiErrDs)
     C                   EndIf

     C                   eval      *inlr = *on
     C                   return




File  : QCMDSRC
Member: SCNJOBMSG
Type  : CMD
Usage : CRTCMD     CMD(lib/SCNJOBLOG) PGM(lib/SCNJOBLOGR) ALLOW(*IPGM *BPGM)  

/********************************************************************/
/*   Title:      SCNJOBLOG: Scan jobs log                           */
/*                                                                  */
/*   Description - This command performs job log scaned by MSGID    */
/*                                                                  */
/*   The Create Command command should include the following:       */
/*                                                                  */
/*           CRTCMD     CMD(SCNJOBLOG) PGM(SCNJOBLOGR)              */
/*                      ALLOW(*IPGM *BPGM)                          */
/********************************************************************/
/*  =============================================================== */
/*  = Date  : 2006/12/20                                          = */
/*  = Author: Vengoal Chang                                       = */
/*  =============================================================== */
      /*------------------------------------------------*/
      /*  Command Definition                            */
      /*------------------------------------------------*/

             CMD        PROMPT('Scan Job Log by MSGID')
             PARM       KWD(JOB) TYPE(*SNAME) LEN(10) MIN(1) +
                          PROMPT('Job name')
             PARM       KWD(USER) TYPE(*SNAME) LEN(10) MIN(1) +
                          PROMPT('User name')
             PARM       KWD(JOBNBR) TYPE(*CHAR) LEN(6) RANGE(000000 +
                          999999) MIN(1) PROMPT('Job number')
             PARM       KWD(MSGID) TYPE(*CHAR) LEN(7) SPCVAL((*ALL)) +
                          MIN(1) PROMPT('Message ID to be searched')
             PARM       KWD(SCHSTR) TYPE(*CHAR) LEN(50) +
                          PROMPT('String searched in MSGID Text')
             PARM       KWD(QUOTE) TYPE(*CHAR) LEN(4) RSTD(*YES) +
                          DFT(*NO) VALUES(*YES *NO) PROMPT('Include +
                          quote between SCHSTR')
             PARM       KWD(FOUND) TYPE(*CHAR) LEN(1) RTNVAL(*YES) +
                          PROMPT('CL var for String found (1)')


File  : QCLSRC
Member: SCNJOBLOGT
Type  : CLP
Usage : 指定 job, usr, jobnbr, search-msgid, search-string 取代小寫部分
        CRTCLPGM SCNJOBLOGT
        CALL SCNJOBLOGT


PGM
             DCL &RC *CHAR 1 /* RC=1 found, RC <> 1 not found */
             SCNJOBLOG  JOB(job) USER(usr) JOBNBR(jobnbr) +
                          MSGID(search-msgid) SCHSTR(search-string) FOUND(&RC)
             MONMSG CPF9897
ENDPGM




沒有留言: