星期三, 11月 08, 2023

2008-09-09 如何從 Message Queue 中自動回覆訊息? (Command: AUTORPY with Message Handling APIs)


如何從 Message Queue 中自動回覆訊息? (Command: AUTORPY with Message Handling APIs)

可以使用 WRKRPYLE, ADDRPYLE, RMVRPYLE 新增,移除系統自動回覆訊息 Id。

當所執行的工作環境參數值為 INQMSGRPY(*SYSRPYL)時,一有需要回覆的訊息產生時,
系統會先去自動回覆訊息表列(reply list entry),尋找所要回覆訊息 ID 是否存在,
若存在,立即以所指定的回應值回覆。若不存在,就需要手動回覆。

工作環境參數值為 INQMSGRPY(*RQD)時,需要手動回覆。

若要針對需要手動回覆的訊息,作自動回覆時,可以 AUTORPY 來回覆。


                             Auto Reply (AUTORPY)                              
                                                                               
Type choices, press Enter.                                                     
                                                                               
Message queue  . . . . . . . . . >               Name                          
  Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB          
Reply message id . . . . . . . . >               Character value               
Reply  . . . . . . . . . . . . . >                                             
Reply to job . . . . . . . . . .                 Name                          
                                                                               




File   : QRPGLESRC
Member : AUTORPY
Type   : RPGLE
Usage  : CRTBNDRPG PGM(AUTORPY) TGTRLS(V5R1M0)

     **
     **  Program . . : AUTORPY
     **  Description : Auto Reply Message - CPP
     **  Author  . . : Vengoal Chang
     **  Date  . . . : 2008/09/09
     **
     **
     **
     **  Program summary
     **  ---------------
     **
     **  Message handling API:
     **    QMHLSTM       List Nonprogram Messages
     **
     **    QMHSNDRM      Send Reply Message
     **
     **    QMHRTVM       Retrieve message
     **
     **    QMHSNDPM      Send program message
     **
     **
     **
     **  Compile options:
     **    CrtBndRpg Pgm( AUTORPY )
     **              TgtRls( V5R1M0 )
     **
     **
     **-- Header specifications:  --------------------------------------------**
     H Debug  Option(*Srcstmt:*NoDebugIO) DftActGrp(*NO) ActGrp(*Caller)

     **-- Retrieve message:  ------------------------------------------
     D GetMsg          Pr                  ExtPgm( 'QMHRTVM' )
     D  RtRcvVar                  32767a          Options( *VarSize )
     D  RtRcvVarLen                  10i 0 Const
     D  RtFmtNam                     10a   Const
     D  RtMsgId                       7a   Const
     D  RtMsgFq                      20a   Const
     D  RtMsgDta                    512a   Const  Options( *VarSize )
     D  RtMsgDtaLen                  10i 0 Const
     D  RtRplSubVal                  10a   Const
     D  RtRtnFmtChr                  10a   Const
     D  RtError                   32767a          Options( *VarSize )

     D GetSize         ds
     D  GetBytRtn                    10i 0
     D  GetBytAvl                    10i 0
     D Fmt0400         ds                  based(FmtPtr)
     D  BytRtn                       10i 0
     D  BytAvl                       10i 0
     D  OffDftRpy             53     56i 0
     D  LenDftRpyR            57     60i 0
     D  RpyType              105    114
     D  MaxRpyLen            117    120i 0
     D  OffVldRpy            125    128i 0
     D  NbrVldRpyR           129    132i 0
     D  LenVldRpyR           133    136i 0
     D  LenVldRpyA           137    140i 0
     D  LenVldRpyE           141    144i 0

     D Upper           C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     D Lower           C                   'abcdefghijklmnopqrstuvwxyz'

     D DftRpy          S             32
     D DftRpyE         S             32    based(DftRpyPtr)
     D VldRpyE         S             32    based(VldRpyPtr)
     D VldRpyAryStr    S            320
     D VldRpyAry       S             32    Dim(10)
     D VldRpyAryIdx    S              3i 0

     D ErrorNull       Ds
     D    BytesProv                  10i 0 inz(0)
     D    BytesAvaile                10i 0 inz(0)

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

     **-- Send program message:
     D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
     D  MsgId                         7a   Const
     D  MsgFq                        20a   Const
     D  MsgDta                      128a   Const
     D  MsgDtaLen                    10i 0 Const
     D  MsgTyp                       10a   Const
     D  CalStkE                      10a   Const  Options( *VarSize )
     D  CalStkCtr                    10i 0 Const
     D  MsgKey                        4a
     D  Error                      1024a          Options( *VarSize )

      * Prototypes
     D CrtUsrSpc       PR                  ExtPgm( 'QUSCRTUS' )
     D  QlSpcName                    20    Const
     D  ExtAttr                      10    Const
     D  SizeInBytes                  10I 0 Const
     D  InitVal                       1    Const
     D  PublicAut                    10    Const
     D  TextDesc                     50    Const
     D  Replace                      10    Const
     D   ReplaceYes    C                   '*YES'
     D   ReplaceNo     C                   '*NO'
     D  ApiErrInfo                         Like( ApiErr )

     D ChgUsrSpcAttr   PR                  ExtPgm( 'QUSCUSAT' )
     D  RetdLibName                  10
     D  QlUsrSpcName                 20    Const
     D  AttrToChg                          Like( EnableAutoExtendDs )
     D                                     Const
     D  ApiErrInf                          Like( ApiErr )

     D DltUsrSpc       PR                  ExtPgm( 'QUSDLTUS' )
     D  QlUsrSpcName                 20    Const
     D  ApiErrInfo                         Like( ApiErr )

     D AddrOfUsrSpc    PR                  ExtPgm( 'QUSPTRUS' )
     D  QlUsrSpcName                 20    Const
     D  PtrToUsrSpc                    *
     D  ApiErrInfo                         Like( ApiErr )

     D As400ObjFound   PR              N
     D  QlObjName                    20    Value
     D  ObjType                      10    Value

     D SndRpyMsg       PR                  ExtPgm( 'QMHSNDRM' )
     D  SndMsgKey                     4    Const
     D  SndQualMsgq                  20    Const
     D  SndRpyMsgTxt                100    Const
     D  SndRpyMsgLen                 10I 0 Const
     D  SndRmvMsg                    10    Const
     D  ApiErrInf                          Like( ApiErr )

     D LstMsgsFrmQ     PR                  ExtPgm( 'QMHLSTM' )
     D  QlUsrSpcName                 20    Const
     D  FmtName                       8    Const
     D   LSTM0100      C                   'LSTM0100'
     D  MsgSltInf                          Like( MsgSltInfo )
     D                                     Const
     D  SizeOfMsgSltInf...
     D                               10I 0 Const
     D  FmtOfMsgSltInf...
     D                                8    Const
     D   MSLT0100      C                   'MSLT0100'
     D  ApiErrInf                          Like( ApiErr )

      * Other program data
     D RetdLibName     S             10

     D EnableAutoExtendDs...
     D                 DS
     D  NumFlds                      10I 0 Inz( 1 )
     D  KeyForAutoExtend...
     D                               10I 0 Inz( 3 )
     D  LengthOfData                 10I 0 Inz( 1 )
     D  AutoExtendVal                 1    Inz( '1' )

     D ApiErr          DS
     D  AeBytesProv                  10I 0 Inz( %Size( ApiErr ) )
     D  AeBytesAvl                   10I 0
     D  AeMsgId                       7
     D                                1
     D  AeMsgDta                    256

     D MsgSltInfo      DS
     D  MsiMaxMsgsReq                10I 0 Inz( -1 )
     D  MsiListDirection...
     D                               10    Inz( '*NEXT' )
     D  MsiSelectionCriterion...
     D                               10    Inz( '*MNR' )
     D  MsiSevCriterion...
     D                               10I 0 Inz( *Zero )
     D  MsiMaxMsgLen                 10I 0 Inz( 112 )
     D  MsiMaxHlpLen                 10I 0 Inz( 4 )
     D  MsiOffstToQlMsgqName...
     D                               10I 0
     D  MsiOffstToStrMsgKey...
     D                               10I 0
     D  MsiNumMsgQs                  10I 0 Inz( 1 )
     D  MsiOffstToFldRetdId...
     D                               10I 0
     D  MsiNumFldsToReturn...
     D                               10I 0 Inz( 3 )
     D  MsiQlMsgqName                20
     D  MsiStrMsgKey                  4    Inz( X'00000000' )
     D  MsiFldRetdId                 10I 0 Inz( 302 )
     D  MsiFldRetdId1                10I 0 Inz( 601 )
     D  MsiFldRetdId2                10I 0 Inz(1001 )

     D UsrSpcHdr       DS                  Based( SpcPtr )
     D  OffstTo1stSpcEntry...
     D                       125    128I 0
     D  NumberOfMsgs         133    136I 0

     D UsrSpcEntry     DS                  Based( UsePtr )
     D  UseOffstToNxtEntry...
     D                         1      4I 0
     D  UseOffstToFldsReturned...
     D                         5      8I 0
     D  UseMsgId              17     23
     D  UseMsgType            24     25
     D  UseMsgKey             26     29
     D  UseMsgF               30     39
     D  UseMsgFLib            40     49
     D  UseMsgQ               50     59
     D  UseMsgQLib            60     69

     D RetdFldsDs      DS                  Based( RetdFldsDsPtr )
     D  NextFldRtnOfs          1      4I 0
     D  Rf1stLvlTxtLen...
     D                        29     32I 0
     D  Rf1stLvlTxt           33    144

     D ScMsgId         S              7
     D ScMsgType       S              2
     D ScMsgKey        S              4
     D ScJob           S             10
     D ScUsr           S             10
     D ScNbr           S              6
     D ScJobSts        S             10
     D ScRpySts        S              1
     D Sc1stLvl        S            112
     D dftRpyValueErr  S               N

     D main            PR                  ExtPgm('AUTORPY')
     D  qualMsgqName                 20
     D  rpyMsgid                      7
     D  rpyMsgValue                  32
     D  rpyToJob                     10

     D main            PI
     D  qualMsgqName                 20
     D  rpyMsgid                      7
     D  rpyMsgValue                  32
     D  rpyToJob                     10

     C                   Eval      MsiQlMsgqName = qualMsgQName
     C                   CallP     As400ObjFound( MsiQlMsgqName:
     C                                                '*MSGQ' )

      * Set offset fields in the Msi data structure
     C                   Eval      MsiOffstToQlMsgqName
     C                             =   %Addr( MsiQlMsgqName )
     C                               - %Addr( MsgSltInfo    )
     C                   Eval      MsiOffstToStrMsgKey
     C                             =   %Addr( MsiStrMsgKey  )
     C                               - %Addr( MsgSltInfo    )
     C                   Eval      MsiOffstToFldRetdId
     C                             =   %Addr( MsiFldRetdId  )
     C                               - %Addr( MsgSltInfo    )

     C                   ExSr      LoadUsrSpc

     C                   ExSr      ProcessMsgs

     C                   Eval      *INLR = *On

      * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
      * LoadUsrSpc - Creates and then loads the user space with the
      *              1st level text of all messages in the specified
      *              message queue.
     C     LoadUsrSpc    BegSr

      * Just to be on the safe side, delete the user space before
      * attempting to create it.
     C                   CallP     DltUsrSpc( 'MSGSPC    QTEMP': ApiErr )

     C                   CallP     CrtUsrSpc( 'MSGSPC    QTEMP':
     C                                        *Blank:
     C                                        25000:
     C                                        X'00':
     C                                        '*ALL':
     C                                        *Blank:
     C                                        ReplaceYes:
     C                                        ApiErr )

      * If there was an error in the API, terminate the subroutine
     C                   If        AeBytesAvl > *Zero
     C                   CallP     SndEscMsg( AeMsgId
     C                                : 'QCPFMSG'
     C                                : %Subst( AeMsgDta: 1: AeBytesAvl-16 )
     C                                       )
     C                   LeaveSr
     C                   EndIf

      * Turn on the autoextend attribute for this user space
     C                   CallP     ChgUsrSpcAttr( RetdLibName:
     C                                            'MSGSPC    QTEMP':
     C                                            EnableAutoExtendDs:
     C                                            ApiErr )

      * If there was an error in the API, terminate the subroutine
     C                   If        AeBytesAvl > *Zero
     C                   LeaveSr
     C                   EndIf

      * Populate the user space with the messages
     C                   CallP     LstMsgsFrmQ( 'MSGSPC    QTEMP':
     C                                          LSTM0100:
     C                                          MsgSltInfo:
     C                                          %Size( MsgSltInfo ):
     C                                          MSLT0100:
     C                                          ApiErr )

      * If there was an error in the API, terminate the subroutine
     C                   If        AeBytesAvl > *Zero
     C                   CallP     SndEscMsg( AeMsgId
     C                                : 'QCPFMSG'
     C                                : %Subst( AeMsgDta: 1:AeBytesAvl- 16 )
     C                                       )
     C                   LeaveSr
     C                   EndIf

      * Get a pointer to the user space
     C                   CallP     AddrOfUsrSpc( 'MSGSPC    QTEMP':
     C                                           SpcPtr:
     C                                           ApiErr )

      * If there was an error in the API, terminate the subroutine
     C                   If        AeBytesAvl > *Zero
     C                   CallP     SndEscMsg( AeMsgId
     C                                : 'QCPFMSG'
     C                                : %Subst( AeMsgDta: 1: AeBytesAvl-16 )
     C                                       )
     C                   LeaveSr
     C                   EndIf

     C                   EndSr

      * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
      * ProcessMsgs  -- Process messages in the specified message queue
     C     ProcessMsgs   BegSr

      * Set the basing pointer for the User Space Entry for the first
      * message in the subfile.
     C                   Eval        UsePtr
     C                             = SpcPtr + OffstTo1stSpcEntry
     C                   Do        NumberOfMsgs
      * move user space values to screen
     C                   Eval      ScMsgId  = UseMsgId
     C                   Eval      ScMsgType = UseMsgType
     C                   Eval      ScMsgKey = UseMsgKey
     C*    ScMsgId       dsply
      * get Message Text
     C                   Eval        RetdFldsDsPtr
     C                             = SpcPtr + UseOffstToFldsReturned
     C                   Eval        Sc1stLvl
     C                             = %Subst( Rf1stLvlTxt: 1:
     C                                       Rf1stLvlTxtLen )
      * get Sender Qualjob
     C                   Eval        RetdFldsDsPtr
     C                             = SpcPtr + NextFldRtnOfs
     C                   Eval        SCJob
     C                             = %Subst( Rf1stLvlTxt: 1: 10)
     C                   Eval        SCUsr
     C                             = %Subst( Rf1stLvlTxt:11: 10)
     C                   Eval        SCNbr
     C                             = %Subst( Rf1stLvlTxt:21:  6)
      * get message reply status
     C                   Eval        RetdFldsDsPtr
     C                             = SpcPtr + NextFldRtnOfs
     C                   Eval        SCRpySts
     C                             = %Subst( Rf1stLvlTxt: 1: 10)
     C*    ScRpySts      dsply
     C                   If        UseMsgType = '05' and
     C                             SCRpySts   = 'W'
     C                   If        UseMsgId = rpyMsgId
     C                   ExSr      ChkRpyValue
     C                   If        rpyToJob   =  *blanks or
     C                             (rpyToJob   <> *blanks and
     C                              ScJob    = rpyToJob       )
     C                   ExSr      RpyMsg
     C                   EndIf
     C                   EndIf
     C                   EndIf
     C                   Eval      UsePtr =   SpcPtr
     C                                      + UseOffstToNxtEntry

     C                   EndDo

     C                   EndSr

      * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
      * ChkRpyValue - Check reply value valid or not
     C     ChkRpyValue   BegSr

     c                   eval      dftRpyValueErr = *Off
     C* How much storage is needed for everything?
     C                   callp     GetMsg( GetSize       :%size(GetSize)
     C                                    :'RTVM0400'    :UseMsgId
     C                                    : UseMsgF + UseMsgFLib
     C                                    :' '           :0
     C                                    :'*NO'         :'*NO'
     C                                    :ErrorNull)
     c* Allocate it and then call the API again
     c                   eval      FmtPtr = %alloc(GetBytAvl)
     c                   callp     GetMsg( Fmt0400       :GetBytAvl
     c                                    :'RTVM0400'    :UseMsgID
     c                                    :UseMsgF + UseMsgFLib
     c                                    :' '           :0
     c                                    :'*NO'         :'*NO'
     c                                    :ErrorNull)
     c* Default replies returned
     c                   if        rpyMsgValue = '*DFT'
     c                   if        LenDftRpyR > 0
     c                   eval      DftRpyPtr = FmtPtr + OffDftRpy
     c                   eval      DftRpy  = %SubSt(DftRpyE:1:LenDftRpyR)
     c*    DftRpy        dsply
     c                   eval      rpyMsgValue = DftRpy
     c                   else
     c                   eval      dftRpyValueErr = *On
     c                   endif
     c                   endif
     c* Any valid replies returned
     c                   if        NbrVldRpyR > 0
     c                   eval      VldRpyPtr = FmtPtr + OffVldRpy
     c                   eval      VldRpyAryIdx = 1
     c                   reset                   VldRpyAry
     c                   do        NbrVldRpyR
     c*    VldRpyE       dsply
     c                   eval      VldRpyAryStr = %trim(VldRpyAryStr) +
     c                             ' ' + %trim(VldRpyE)
     c                   eval      VldRpyAry(VldRpyAryIdx) = VldRpyE
     c                   eval      VldRpyAryIdx = VldRpyAryIdx + 1
     c                   eval      VldRpyPtr = VldRpyPtr + LenVldRpyE
     c                   enddo

     c                   if        Not dftRpyValueErr
     c     lower:upper   xlate     rpyMsgValue   rpyMsgValue
     c                   if        %lookup(rpyMsgValue: VldRpyAry) = 0
     C                   CallP     SndEscMsg( 'CPF9898'
     C                             : 'QCPFMSG'
     C                             : 'MsgId: ' + UseMsgId  +
     C                               ' reply value ' + %trim(rpyMsgValue) +
     C                               ' is not valid, valid reply value is '+
     C                               %trim(VldRpyAryStr)
     C                                       )
     c                   endif
     c                   else
     C                   CallP     SndEscMsg( 'CPF9898'
     C                             : 'QCPFMSG'
     C                             : 'MsgId: ' + UseMsgId  +
     C                               ' reply value ' + %trim(rpyMsgValue) +
     C                               ' is not valid, no default reply' +
     C                               ' setting, valid reply value is '+
     C                               %trim(VldRpyAryStr)
     C                                       )
     c                   endif

     C                   endif
     C                   EndSr

      * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
      *
     C     RpyMsg        BegSr
     C
     C                   CALLP     SndRpyMsg ( SCMsgKey :
     C                                         MsiQlMsgqName :
     C                                         %trim(rpyMsgValue):
     C                                         %len(%trim(rpyMsgValue)):
     C                                         '*NO' :
     C                                         ApiErr)
      * If there was an error in the API, terminate the subroutine
     C                   If        AeBytesAvl > *Zero
     C*    AeMsgId       DSPLY
     C                   CallP     SndEscMsg( AeMsgId
     C                                : 'QCPFMSG'
     C                                : %Subst( AeMsgDta: 1 )
     C                                       )
     C                   Else
     C                   Callp     SndCmpMsg(
     C                              'MsgId:' + rpyMsgId + ' replied to job'+
     C                              ' ' + %trim(SCNbr) + '/' + %trim(SCUSr)+
     C                              '/' + %trim(SCJob) + ' with value ' +
     C                              %trim(rpyMsgValue) + '.'
     C                                      )
     C                   EndIf
     C
     C                   EndSr

      * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
      * As400ObjFound - Attempts to locate an AS/400 object
     P As400ObjFound   B

     D As400ObjFound   PI              N
     D  QlObjName                    20    Value
     D  ObjType                      10    Value

      * Local variables and prototypes

     D RtvObjDesc      PR                  ExtPgm( 'QUSROBJD' )
     D  RcvrVar                       8
     D  LenRcvrVar                   10I 0 Const
     D  FmtName                       8    Const
     D  QlObjName                    20    Const
     D  ObjType                      10    Const
     D  ApiErrInf                          Like( ApiErr )

     D ApiErr          DS
     D  AeBytesProv                  10I 0 Inz( %Size( ApiErr ) )
     D  AeBytesAvl                   10I 0
     D  AeMsgId                       7
     D                                1
     D  AeMsgDta                    256

     D Rcvr            S              8


      * Invoke the QUSROBJD API to attempt to locate the object
     C                   CallP     RtvObjDesc( Rcvr:
     C                                         %Size( Rcvr ):
     C                                         'OBJD0100':
     C                                         QlObjName:
     C                                         ObjType:
     C                                         ApiErr )

      * If the API returns any error at all, I assume we were unable to
      * locate the object.
     C                   If        AeBytesAvl > *Zero
     C                   CallP     SndEscMsg( AeMsgId
     C                                : 'QCPFMSG'
     C                                : %Subst( AeMsgDta: 1:AeBytesAvl- 16 )
     C                                       )
     C                   Return    *Off
     C                   Else
     C                   Return    *On
     C                   EndIf

     P As400ObjFound   E
     **-- Send escape message:  ----------------------------------------------**
     P SndEscMsg       B
     D                 Pi            10i 0
     D  PxMsgId                       7a   Const
     D  PxMsgF                       10a   Const
     D  PxMsgDta                    512a   Const  Varying
     **
     D MsgKey          s              4a

     C                   Callp     SndPgmMsg( PxMsgId
     C                                       : PxMsgF + '*LIBL'
     C                                       : PxMsgDta
     C                                       : %Len( PxMsgDta )
     C                                       : '*ESCAPE'
     C                                       : '*PGMBDY'
     C                                       : 1
     C                                       : MsgKey
     C                                       : ApiErr
     C                                      )

     C                   If        AeBytesAvl > *Zero
     C                   Return    -1
     C
     C                   Else
     C                   Return    0
     C                   EndIf
     P SndEscMsg       E
     **-- Send completion message:  ------------------------------------------**
     P SndCmpMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying

     D MsgKey          s              4a

     C                   Callp     SndPgmMsg( 'CPF9897'
     C                                       : 'QCPFMSG   *LIBL'
     C                                       : PxMsgDta
     C                                       : %Len( PxMsgDta )
     C                                       : '*COMP'
     C                                       : '*PGMBDY'
     C                                       : 1
     C                                       : MsgKey
     C                                       : ApiErr
     C                                      )

     C                   If        AeBytesAvl > *Zero
     C                   Return    -1
     C
     C                   Else
     C                   Return    0
     C                   EndIf

     **
     P SndCmpMsg       E



File   : QCMDSRC
Member : AUTORPY
Type   : CMD
Usage  : CRTCMD CMD(AUTORPY) PGM(AUTORPY)

/*  ===============================================================  */
/*  = Command....... AutoRpy                                      =  */
/*  = CPP........... AutoRpy  RPGLE                               =  */
/*  = Description... Auto reply to the sender of an inquiry       =  */
/*  =                message.                                     =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( AutoRpy   )                                =  */
/*  =             Pgm( AutoRpy    )                               =  */
/*  =             SrcFile( YourSourceFile )                       =  */
/*  ===============================================================  */
/*  = Date  : 2008/09/09                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */
             CMD        PROMPT('Auto Reply')

             PARM       KWD(MSGQ) TYPE(QUAL2) MIN(1) PROMPT('Message +
                          queue')
             PARM       KWD(MSGID) TYPE(*CHAR) LEN(7) PROMPT('Reply +
                          message id')
             PARM       KWD(REPLY) TYPE(*CHAR) LEN(32) DFT(*DFT) +
                          SPCVAL((*DFT)) PROMPT('Reply')
             PARM       KWD(LMTRPYJOB) TYPE(*NAME) LEN(10) +
                          PROMPT('Reply to job')

 QUAL2:      QUAL       TYPE(*NAME) EXPR(*YES)
             QUAL       TYPE(*NAME) DFT(*LIBL) SPCVAL((*LIBL) +
                          (*CURLIB)) EXPR(*YES) PROMPT('Library')



測試方式:
1.
CRTMSGF QGPL/TESTMSGF
/* Add message id with no default reply value */
ADDMSGD MSGID(TST0001) MSGF(QGPL/TESTMSGF) MSG(TEST_001) SEV(99) VALUES(C D R I)

/* Add message id with default reply value */
ADDMSGD MSGID(TST0002) MSGF(QGPL/TESTMSGF) MSG(TEST_001) SEV(99) VALUES(C D R I) DFT(C) 

2.
AUTORPYT1 CLP:
PGM
  DCL &CURUSR *CHAR 10
  RTVJOBA    USER(&CURUSR)
 SNDUSRMSG  MSGID(TST0001) MSGF(QGPL/TESTMSGF) +
                       TOUSR(&CURUSR)          
ENDPGM

AUTORPYT2 CLP:
PGM
  DCL &CURUSR *CHAR 10
  RTVJOBA    USER(&CURUSR)
 SNDUSRMSG  MSGID(TST0002) MSGF(QGPL/TESTMSGF) +
                       TOUSR(&CURUSR)          
ENDPGM

3.
Compile AUTORPYT1, AUTORPYT2

4. for example use USER01 subbmit job
SBMJOB CMD(CALL AUTORPYT1) JOB(JOB1)  
SBMJOB CMD(CALL AUTORPYT2) JOB(JOB2)

5.
DSPMSG USER01

                               Display Messages                               
                                                      System:   DDSC810       
Queue . . . . . :   USER01                    Program . . . . :   *DSPMSG       
  Library . . . :     QUSRSYS                 Library . . . :                 
Severity  . . . :   00                      Delivery  . . . :   *HOLD         
                                                                              
Type reply (if required), press Enter.                                        
  Job 690946/USER01/JOB2 completed normally on 09/09/08 at 15:17:58.         
  Job 690962/USER01/JOB1 completed normally on 09/09/08 at 15:17:58.         
  TEST 0001                                                                   
    Reply . . .                                                               
  Waiting for reply to message on message queue USER01.                      
  TEST_002                                                                    
    Reply . . .                                                               
  Waiting for reply to message on message queue USER01.                      
                                                                              


6.
AUTORPY MSGQ(USER01) MSGID(TST0001)
MSGID TST001 does not set default reply value,so we got following message :   
                        Additional Message Information                         
                                                                               
Message ID . . . . . . :   CPF9898       Severity . . . . . . . :   40         
Message type . . . . . :   Information                                         
Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:19:26   
                                                                               
Message . . . . :   MsgId: TST0001 reply value *DFT is not valid, no default   
  reply setting, valid reply value is C D E F.                                 
Cause . . . . . :   This message is used by application programs as a general  
  escape message.                                                              
                                                                                                                                                            
                                                                               

7.
AUTORPY MSGQ(USER01) MSGID(TST0001) REPLY(C)
Got following message:
                        Additional Message Information                         
                                                                               
Message ID . . . . . . :   CPF9897       Severity . . . . . . . :   40         
Message type . . . . . :   Information                                         
Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:22:06   
                                                                               
Message . . . . :   MsgId:TST0001 replied to job 690963/USER01/JOB1 with      
  value C.                                                                     
Cause . . . . . :   No additional online help information is available.        

7.1 DSPMSG USER01

                               Display Messages                                
                                                      System:   DDSC810        
Queue . . . . . :   USER01                  Program . . . . :   *DSPMSG        
  Library . . . :     QUSRSYS                 Library . . . :                  
Severity  . . . :   00                      Delivery  . . . :   *HOLD          
                                                                               
Type reply (if required), press Enter.                                         
  Job 690946/USER01/JOB2 completed normally on 09/09/08 at 15:17:58.          
  Job 690962/USER01/JOB1 completed normally on 09/09/08 at 15:17:58.          
  TEST 0001                                                                    
    Reply . . :   C                                                            
  Waiting for reply to message on message queue USER01.                       
  TEST_002                                                                     
    Reply . . .                                                                
  Waiting for reply to message on message queue USER01.                       
  Job 690963/VENGOAL/JOB1 completed normally on 09/09/08 at 15:22:06.          
                                                                                 

8.
AUTORPY MSGQ(USER01) MSGID(TST0002) REPLY(RR) <== Reply TST002 message with wrong value
Got following message:
                        Additional Message Information                         
                                                                               
Message ID . . . . . . :   CPF9898       Severity . . . . . . . :   40         
Message type . . . . . :   Information                                         
Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:26:54   
                                                                               
Message . . . . :   MsgId: TST0002 reply value RR is not valid, valid reply    
  value is C D R I.                                                          
Cause . . . . . :   This message is used by application programs as a general  
  escape message.                                                              

9.
AUTORPY MSGQ(USER01) MSGID(TST0002) JOB(JOB3)
Because we just submitted JOB1,JOB2, the TST0002 still isn't replied.
DSPMSG USER01 will got same step 7.1 result.

10.
AUTORPY MSGQ(USER01) MSGID(TST0002) LMTRPYJOB(JOB2)
Got following message:
                        Additional Message Information                        
                                                                              
Message ID . . . . . . :   CPF9897       Severity . . . . . . . :   40        
Message type . . . . . :   Information                                        
Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:34:13  
                                                                              
Message . . . . :   MsgId:TST0002 replied to job 690965/USER01/JOB2 with     
  value C.                                                                    
Cause . . . . . :   No additional online help information is available.       
                                                                              
10.1
DSPMSG USER01
                               Display Messages                                
                                                      System:   DDSC810        
Queue . . . . . :   USER01                  Program . . . . :   *DSPMSG        
  Library . . . :     QUSRSYS                 Library . . . :                  
Severity  . . . :   00                      Delivery  . . . :   *HOLD          
                                                                               
Type reply (if required), press Enter.                                         
  Job 690946/USER01/JOB2 completed normally on 09/09/08 at 15:17:58.          
  Job 690962/USER01/JOB1 completed normally on 09/09/08 at 15:17:58.          
  TEST 0001                                                                    
    Reply . . :   C                                                            
  Waiting for reply to message on message queue USER01.                       
  TEST_002                                                                     
    Reply . . :   C                                                            
  Waiting for reply to message on message queue USER01.                       
  Job 690963/USER01/JOB1 completed normally on 09/09/08 at 15:22:06.          
  Job 690965/USER01/JOB2 completed normally on 09/09/08 at 15:34:13.          




沒有留言: