midrange.com code scratchpad
Name:
Command: RTVMSGWJL
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
05/16/2008 04:08:43 am
IP:
Logged
Description:
Retrieve MSGW Job Error Log and Send Error Text to User
Code:
  1. CPP RTVMSGWJLR RPGLE
  2.  
  3.      H DFTACTGRP(*NO) ACTGRP(*CALLER) BNDDIR('QC2LE') EXPROPTS(*RESDECPOS)
  4.      H DATFMT(*ISO)   TIMFMT(*ISO)    DEBUG
  5.      H OPTION(*SRCSTMT:*NODEBUGIO)
  6.       *----------------------------------------------------------------
  7.       * RTVMSGWJL  Retrieve Job MSGW ErrMsg from Job Log
  8.       * Copyright (C) 04/03/2008  Vengoal Chang    <vengoal@ddsc.com.tw>
  9.       * This program is free software, you can redistribute it and/or modify it under the terms
  10.       * of the GNU General Public License as published by the Free Software Foundation.
  11.       *
  12.       *----------------------------------------------------------------
  13.       * This program retrieve specified job job's log and send err log
  14.       * to specified MSGQ, you could modify for checking message
  15.       * type or message id as your request.
  16.       *----------------------------------------------------------------
  17.       * api (application program interfaces) used:
  18.       * quscrtus  create user space
  19.       * qusptrus  retrieve pointer to user space
  20.       * qmhljobl  list job log messages
  21.       * qezsndmg  send message to user
  22.       *----------------------------------------------------------------
  23.      D uSpaceName      s             20    inz('RTVMSGWJL QTEMP     ')
  24.      D msgtxt          s            768
  25.      D msgtxt494       s            494
  26.      D msgtxt06        s            256
  27.      D msgtxt15        s            256
  28.      D msgtxt17        s            256
  29.      D QUSLIB          s             10
  30.  
  31.      D MsgQDs          Ds
  32.      D  MsgQEntSize                   4B 0
  33.      D  MsgQEntStr                   20    Dim( 20 )
  34.      D Idx             S              2  0
  35.      D AryIdx          S             10I 0
  36.      D QualMsgq        DS
  37.      D   MsgQ                        10
  38.      D   MsgQLib                     10
  39.  
  40.       *Array for contain MsgQStr
  41.      D MsgQUsrDs       Ds
  42.      D MsgQUsrAry                    10    Dim( 20 )
  43.      D                                     Inz( *HiVal )    Ascend
  44.       *  -------------------------------------------------------------------
  45.       *  -  User space attributes data structure                           -
  46.       *  -------------------------------------------------------------------
  47.  
  48.      D QUSAttr         DS
  49.      D  QUSNumRec                    10I 0 Inz( 1 )
  50.      D  QUSKey                       10I 0 Inz( 3 )
  51.      D  QUSRecLen                    10I 0 Inz( 1 )
  52.      D  QUSRecData                    1A   Inz( '1' )
  53.  
  54.       *----------------------------------------------------------------
  55.       * Get user space list info from header section.
  56.       *----------------------------------------------------------------
  57.      D                 ds                  based(uHeadPtr)
  58.      D uOffSetToList         125    128i 0
  59.      D uNumOfEntrys          133    136i 0
  60.      D uSizeOfEntry          137    140i 0
  61.       *
  62.      D uListEntry1     ds                  Based(uListPtr )
  63.      D uOffsetToNext                 10i 0 overlay(uListEntry1:1)
  64.      D uOffsetToFlds                 10i 0 overlay(uListEntry1:5)
  65.      D uNumFldsRetrnd                10i 0 overlay(uListEntry1:9)
  66.      D uMsgSeverity                  10i 0 overlay(uListEntry1:12)
  67.      D uMsgId                         7a   overlay(uListEntry1:17)
  68.      D uMsgType                       2a   overlay(uListEntry1:24)
  69.      D uMsgKey                        4a   overlay(uListEntry1:26)
  70.      D uMsgFile                      20a   overlay(uListEntry1:30)
  71.      D uMsgFileName                  10a   overlay(uListEntry1:30)
  72.      D uMsgFileLib                   10a   overlay(uListEntry1:40)
  73.       * these fields repeat for each key selected.
  74.      D uListEntry2     ds                  Based(uListPtr2)
  75.      D u2OffsetToNext                10i 0
  76.      D u2LengthOfFlds                10i 0
  77.      D u2IdentifierF                 10i 0
  78.      D u2TypeOfData                   1a
  79.      D u2StatOfData                   1a
  80.      D u2Reserved                    14a
  81.      D u2LengthOfData                10i 0
  82.      D u2Data                       500
  83.       *----------------------------------------------------------------
  84.       * Error return code parm for APIs.
  85.       *----------------------------------------------------------------
  86.      D vApiErrDs       ds
  87.      D  vbytpv                       10i 0 inz(%size(vApiErrDs))
  88.      D  vbytav                       10i 0 inz(0)
  89.      D  vmsgid                        7a
  90.      D  vresvd                        1a
  91.      D  vrpldta                      50a
  92.       *
  93.       *----------------------------------------------------------------
  94.       * Message selection data structure.
  95.       *
  96.       *                               Retrieve JOB Log direction
  97.       *-----------------------------|-------------|--------------------
  98.       * Parameter                   | From Top    | From Bottom
  99.       *-----------------------------|-------------|--------------------
  100.       * msListDirection             | *NEXT       | *PRV
  101.       * msStartingMessageKey        | X'00000000' | X'FFFFFFFF'
  102.       *----------------------------------------------------------------
  103.      D MsgSelectDS     ds
  104.      D  msMaxMsgRequested...
  105.      D                               10i 0 inz(-1)     overlay(msgSelectDS:1)   num of msg requested
  106.      D  msListDirection...
  107.      D                               10a   inz('*NEXT') overlay(msgSelectDS:5)   List direction
  108.      D  msQualifiedJobName...
  109.      D                               10a   inz('*')    overlay(msgSelectDS:15)     * = current job
  110.      D  msQualifiedUserName...
  111.      D                               10a   inz(' ')    overlay(msgSelectDS:25)       = current job
  112.      D  msQualifiedJobNumber...
  113.      D                                6a   inz(' ')    overlay(msgSelectDS:35)       = current job
  114.      D  msInternalJobIdentifier...
  115.      D                               16a   inz(' ')    overlay(msgSelectDS:41)       = current job
  116.      D  msStartingMessageKey...
  117.      D                                4a   inz(x'00000000')                     start newest message
  118.      D                                                 overlay(msgselectDS:57)
  119.      D  msMaxMsgLength...
  120.      D                               10i 0 inz(500)    overlay(msgSelectDS:61)  id 301,302 lengths
  121.      D  msMaxMsgHelpLength...
  122.      D                               10i 0 inz(100)    overlay(msgSelectDS:65)  id 401,402,403,404
  123.      D  msOffsetToIdentifiersOfFieldstoReturn...
  124.      D                               10i 0 inz(84)     overlay(msgSelectDS:69)  to start of array
  125.      D  msNumberOfFieldsToReturn...
  126.      D                               10i 0 inz(1)      overlay(msgSelectDS:73)
  127.      D  msOffsetToCallMsgQname...
  128.      D                               10i 0 inz(88)     overlay(msgSelectDS:77)
  129.      D  msLengthOfCallMsgQname...
  130.      D                               10i 0 inz(1)      overlay(msgSelectDS:81)
  131.      D  msIndentifiersOfFieldsToReturn...
  132.      D                               10i 0 inz(0302)   overlay(msgSelectDS:85)
  133.      D  msCallMessageQueueName...
  134.      D                                1a   inz('*')    overlay(msgSelectDS:89)
  135.       *----------------------------------------------------------------
  136.       * Create Prototypes for calls
  137.       * --------------------------------------------------------------------
  138.       *  -  QusCrtUs  - Create User Space API                              -
  139.       *  -                                                                 -
  140.       *  -  Usage      Length   Type         Parameter Description         -
  141.       *  -                                                                 -
  142.       *  -  Input          20   Character    Qualified user space name     -
  143.       *  -  Input          10   Character    Extended attribute            -
  144.       *  -  Input         4 0   Binary       Initial size                  -
  145.       *  -  Input           1   Character    Initial value                 -
  146.       *  -  Input          10   Character    Public authority              -
  147.       *  -  Input          50   Character    Text description              -
  148.       *  -  Replace        10   Character    Replace                       -
  149.       * --------------------------------------------------------------------
  150.      D quscrtus        PR                  ExtPgm('QUSCRTUS')
  151.      D                               20
  152.      D                               10    const
  153.      D                               10i 0 const
  154.      D                                1    const
  155.      D                               10    const
  156.      D                               50    const
  157.      D                               10    const
  158.      Db                                    like(vApiErrDS)
  159.       *  -------------------------------------------------------------------
  160.       *  -  Qusptrus      - Get user space pointer       API               -
  161.       *  -                                                                 -
  162.       *  -  Usage      Length   Type         Parameter Description         -
  163.       *  -                                                                 -
  164.       *  -  Input          20   Character    Qualified user space name     -
  165.       *  -  Output          *   Pointer      UserSpace Pointer             -
  166.       *  -  Output                           Error Code                    -
  167.       *  - -----------------------------------------------------------------
  168.      D qusptrus        PR                  ExtPgm('QUSPTRUS')                   retrieve pointer
  169.      D                               20                                         Space Name
  170.      D                                 *                                        pointer
  171.      Db                                    like(vApiErrDS)                      error parm
  172.       *  -------------------------------------------------------------------
  173.       *  -  Quscusat      - Change User Space Attributes API               -
  174.       *  -                                                                 -
  175.       *  -  Usage      Length   Type         Parameter Description         -
  176.       *  -                                                                 -
  177.       *  -  Output         10   Character    Returned library              -
  178.       *  -  Input          20   Character    Qualified user space name     -
  179.       *  -  Input          13   Character    Attribute structure           -
  180.       *  -  Output                           Error code                    -
  181.       *  -------------------------------------------------------------------
  182.      D quscusat        PR                  ExtPgm( 'QUSCUSAT' )
  183.      D                               10A   Const
  184.      D                               20A   Const
  185.      D                               13A   Const
  186.      Db                                    like(vApiErrDS)
  187.       *  ---------------------------------------------------------------
  188.      D system          PR            10I 0 extproc('system')
  189.      D  i_cmd                          *   value options(*string)
  190.       *
  191.      D EXCP_MSGID      S              7A   import('_EXCP_MSGID')
  192.       *  --------------------------------------------------------------
  193.      D qmhljobl        PR                  ExtPgm('QMHLJOBL ')
  194.      D                               20
  195.      D                                8    const
  196.      Db                                    like(MsgSelectDS)
  197.      D                               10i 0 const
  198.      D                                8    const
  199.      Db                                    like(vApiErrDS)
  200.       *  --------------------------------------------------------------
  201.      D qmhsndm         PR                  ExtPgm('QMHSNDM')
  202.      D  msgid                         7    const
  203.      D  msgfil                       20    const
  204.      D  msgtxt                      256    const
  205.      D  msglen                       10i 0 const
  206.      D  msgtype                      10    const
  207.      D  msgq                         10    const
  208.      D  msgq#                        10i 0 const
  209.      D  rpymq                        20    const
  210.      D  msgkey                        4    const
  211.      Db                                    like(vApiErrDS)
  212.       *  --------------------------------------------------------------
  213.      D QEZSNDMG        PR                  ExtPgm('QEZSNDMG')
  214.      D   Msgtype                     10A   const
  215.      D   DelivMode                   10A   const
  216.      D   MsgTxt                   32767A   const options(*varsize)
  217.      D   MsgLen                      10I 0 const
  218.      D   MsgQ                        10A   const
  219.      D                                     dim(32767) options(*varsize)
  220.      D   NumMsgQ                     10I 0 const
  221.      D   MsgSent                     10I 0
  222.      D   FuncReq                     10I 0
  223.      D   ErrorCode                32767A   options(*varsize)
  224.      D   DspScrn                      1A   const options(*nopass)
  225.      D   ReplyQ                      20A   const options(*nopass)
  226.      D   NameType                     4A   const options(*nopass)
  227.      D   CCSID                       10I 0 const options(*nopass)
  228.  
  229.      D ErrorCode       DS
  230.      D   BytesProv                   10I 0 inz(0)
  231.      D   BytesAvail                  10I 0 inz(0)
  232.  
  233.      D msgTypeA        s             10
  234.      D sentcode        s             10I 0
  235.      D funccode        s             10I 0
  236.  
  237.      D main            PR                  extpgm('RTVMSGWJLR')
  238.      D  jobname                      10
  239.      D  jobuser                      10
  240.      D  jobnumber                     6
  241.      D  msgtype                       5
  242.      D  msgQDsInput                        like(MsgQDs)
  243.  
  244.      D main            PI
  245.      D  jobname                      10
  246.      D  jobuser                      10
  247.      D  jobnumber                     6
  248.      D  msgtype                       5
  249.      D  msgQDsInput                        like(MsgQDs)
  250.  
  251.       *----------------------------------------------------------------
  252.       * Main Process
  253.       *----------------------------------------------------------------
  254.      C                   eval      *inlr = *on
  255.  
  256.      C                   eval      msQualifiedJobName   = jobname
  257.      C                   eval      msQualifiedUserName  = jobuser
  258.      C                   eval      msQualifiedJobNumber = jobnumber
  259.      c                   eval      msgTypeA = MsgType
  260.      C                   eval      msgQDs  = msgQDsInput
  261.  
  262.      C                   Eval      Idx = 0
  263.      C                   Eval      AryIdx = 0
  264.      C                   DoW       Idx < MsgQEntSize
  265.      C                   Eval      Idx = Idx + 1
  266.      C                   Eval      QualMsgQ  = MsgQEntStr(Idx)
  267.       * only msgq show onec
  268.       * regardless of number times used.
  269.      C                   If        AryIdx = 0  or
  270.      C                             %lookup(MsgQ :MsgQUsrAry:1:AryIdx) = 0
  271.      C                   Eval      AryIdx = AryIdx + 1
  272.      C                   Eval      MsgQUsrAry(AryIdx)  = MsgQ
  273.      C                   EndIf
  274.  
  275.      C                   EndDo
  276.  
  277.       *----------------------------------------------------------------
  278.       * Create user space
  279.      C                   callp     QUSCRTUS(
  280.      C                             uSpaceName:
  281.      C                             'TEST':
  282.      C                             1500000:
  283.      C                             x'00':
  284.      C                             '*ALL':
  285.      C                             'User Space CHKJOBLOG' :
  286.      C                             '*YES':
  287.      C                             vApiErrDs)
  288.       * set UserSpace to autoextended
  289.      C                   CallP     QUSCUSAT( QUSLib     :
  290.      C                                       uSpaceName :
  291.      C                                       QUSAttr    :
  292.      C                                       vApiErrDs  )
  293.       * Get pointer to user space
  294.      C                   callp     QUSPTRUS(
  295.      C                             uSpaceName:
  296.      C                             uHeadPtr:
  297.      C                             vApiErrDs)
  298.       * call api to load job log into user space.
  299.      C                   callp     QMHLJOBL(
  300.      C                             uSpaceName:
  301.      C                             'LJOB0100':
  302.      C                             MsgSelectDS:
  303.      C                             %len(MsgSelectDS):
  304.      C                             'JSLT0100':
  305.      C                             vApiErrDs)
  306.       * Process elements
  307.       *
  308.      C                   eval      uListPtr  = uHeadPtr + uOffSetToList
  309.  1B  C                   do        uNumOfEntrys
  310.  
  311.       * Message Type                                              Example
  312.       * 15  Escape, exception already handled when API is called  MCH1211
  313.       * 17  Escape, exception not handled when API is called      CPF9999
  314.       * 06  Sender's copy                                         RNQ0102
  315.       *
  316.       * Example Error: divide by zero
  317.       * Job log sequence : MCH1211 Attempt made to divide by zero
  318.       *                            for fixed point operation.
  319.       *                    CPF9999 Function check. MCH1211
  320.       * unmonitored by TESTERR at statement 0000000007, instruction X'0000'
  321.       *    reply message=> RNQ0102 Attempt to divide by zero (C G D F).
  322.  
  323.      C                   If        uMsgType = '06' or
  324.      C                             uMsgType = '15' or
  325.      C                             uMsgType = '17'
  326.      C                   eval      uListPtr2 = uHeadPtr + uOffsetToFlds
  327.      C                   If        uMsgType = '15'
  328.      C                   eval      msgtxt15 =
  329.      C                                      %subst(u2Data:1:U2LengthOfData)
  330.      C                   EndIf
  331.      C                   If        uMsgType = '17'
  332.      C                   eval      msgtxt17 =
  333.      C                                      %subst(u2Data:1:U2LengthOfData)
  334.      C                   EndIf
  335.      C                   If        uMsgType = '06'
  336.      C                   eval      msgtxt06 =
  337.      C                                      %subst(u2Data:1:U2LengthOfData)
  338.      C                   EndIf
  339.  
  340.  
  341.      C                   EndIf
  342.  
  343.      C                   eval      uListPtr  = uHeadPtr  + uOffsetToNext
  344.  1E  C                   enddo
  345.  
  346.      C                   eval      msgtxt = '*** Job MSGW Error Message' +
  347.      C                                      ' *** ' +
  348.      C                                      'Job ' +
  349.      C                                      %trim(jobnumber) + '/' +
  350.      C                                      %trim(jobuser)   + '/' +
  351.      C                                      %trim(jobname)   + ' ' +
  352.      C                                      'error text:'    + ' ' +
  353.      C                                      %trim(msgtxt15) + ' ' +
  354.      C                                      %trim(msgtxt17) + ' ' +
  355.      C                                      %trim(msgtxt06)
  356.      C                   eval      msgtxt494 = msgtxt
  357.      C                   if        %len(%trim(msgtxt15) +
  358.      C                                  %trim(msgtxt17) +
  359.      C                                  %trim(msgtxt06)) > 0
  360.      C                   exsr      SndEzMsg
  361.      C                   EndIf
  362.  
  363.      C                   return
  364.       **********************************************************************
  365.      C     SndEzMsg      BegSr
  366.      C                   callp     QEZSNDMG( msgTypeA
  367.      C                                     : '*BREAK'
  368.      C                                     : msgtxt494
  369.      C                                     : %len(msgtxt494)
  370.      C                                     : MsgQUsrAry
  371.      C                                     : AryIdx
  372.      C                                     : sentcode
  373.      C                                     : funccode
  374.      C                                     : ErrorCode
  375.      C                                     : 'N'
  376.      C                                     : *blanks
  377.      C                                     : '*USR'
  378.      C                                     : 0 )
  379.      C                   EndSr
  380.  
  381. Command Source RTVMSGWJL CMD
  382.  
  383. /*  ===============================================================  */
  384. /*  =  Command....... RtvMsgwJL                                   =  */
  385. /*  =  Source type... CMD                                         =  */
  386. /*  =  Description... Retrieve MSGW Job ErrMsg from Job Log       =  */
  387. /*  =                                                             =  */
  388. /*  =  CPP........... RtvMsgwJLR                                  =  */
  389. /*  =                                                             =  */
  390. /*  ===============================================================  */
  391. /*  = Date  : 2008/03/21                                          =  */
  392. /*  = Author: Vengoal Chang                                       =  */
  393. /*  ===============================================================  */
  394. /*  = Create strp:                                                =  */
  395. /*  =  CRTBNDRPG PGM(RtvMsgwJLR) SRCFILE(LIB/QRPGLESRC)           =  */
  396. /*  =  CRTCMD    CMD(RtvMsgwJL)  PGM(RtvMsgwJLR) +                =  */
  397. /*  =                            SRCFILE(LIB/QCMDSRC)             =  */
  398. /*  ===============================================================  */
  399.       /*------------------------------------------------*/
  400.       /*  Command Definition                            */
  401.       /*------------------------------------------------*/
  402.  
  403.              CMD        PROMPT('RTV MSGW Job Log and Send')
  404.              PARM       KWD(JOB) TYPE(*SNAME) LEN(10) MIN(1) +
  405.                           PROMPT('Job name')
  406.              PARM       KWD(USER) TYPE(*SNAME) LEN(10) MIN(1) +
  407.                           PROMPT('User name')
  408.              PARM       KWD(JOBNBR) TYPE(*CHAR) LEN(6) RANGE(000000 +
  409.                           999999) MIN(1) PROMPT('Job number')
  410.              PARM       KWD(MSGTYPE) TYPE(*CHAR) LEN(5) RSTD(*YES) +
  411.                           DFT(*INFO) VALUES(*INFO *INQ) +
  412.                           PROMPT('Message type')
  413.              PARM       KWD(TOMSGQ) TYPE(MSGQ) MAX(20) PROMPT('Send +
  414.                           log to message queue')
  415.  
  416.  MSGQ:       QUAL       TYPE(*NAME) LEN(10) SPCVAL((QSYSOPR)) +
  417.                           EXPR(*YES)
  418.              QUAL       TYPE(*NAME) LEN(10) DFT(*LIBL) +
  419.                           SPCVAL((*LIBL) (*CURLIB)) EXPR(*YES) +
  420.                           PROMPT(Library)
  421.  
  422.  
© 2004-2019 by midrange.com generated in 0.009s valid xhtml & css