midrange.com code scratchpad
Name:
Command AUTORPY
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
09/09/2008 08:38:26 am
IP:
Logged
Description:
Auto Reply message by message id and reply to job
Code:
  1. <pre>
  2.                              Auto Reply (AUTORPY)                              
  3.                                                                                
  4. Type choices, press Enter.                                                     
  5.                                                                                
  6. Message queue  . . . . . . . . . >               Name                          
  7.   Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB          
  8. Reply message id . . . . . . . . >               Character value               
  9. Reply  . . . . . . . . . . . . . >                                             
  10. Reply to job . . . . . . . . . .                 Name                          
  11.                                                                                
  12.  
  13.  
  14.  
  15. <b>
  16. File   : QRPGLESRC
  17. Member : AUTORPY
  18. Type   : RPGLE
  19. Usage  : CRTBNDRPG PGM(AUTORPY) TGTRLS(V5R1M0)
  20. </b>
  21.      **
  22.      **  Program . . : AUTORPY
  23.      **  Description : Auto Reply Message - CPP
  24.      **  Author  . . : Vengoal Chang
  25.      **  Date  . . . : 2008/09/09
  26.      **
  27.      **
  28.      **
  29.      **  Program summary
  30.      **  ---------------
  31.      **
  32.      **  Message handling API:
  33.      **    QMHLSTM       List Nonprogram Messages
  34.      **
  35.      **    QMHSNDRM      Send Reply Message
  36.      **
  37.      **    QMHRTVM       Retrieve message
  38.      **
  39.      **    QMHSNDPM      Send program message
  40.      **
  41.      **
  42.      **
  43.      **  Compile options:
  44.      **    CrtBndRpg Pgm( AUTORPY )
  45.      **              TgtRls( V5R1M0 )
  46.      **
  47.      **
  48.      **-- Header specifications:  --------------------------------------------**
  49.      H Debug  Option(*Srcstmt:*NoDebugIO) DftActGrp(*NO) ActGrp(*Caller)
  50.  
  51.      **-- Retrieve message:  ------------------------------------------
  52.      D GetMsg          Pr                  ExtPgm( 'QMHRTVM' )
  53.      D  RtRcvVar                  32767a          Options( *VarSize )
  54.      D  RtRcvVarLen                  10i 0 Const
  55.      D  RtFmtNam                     10a   Const
  56.      D  RtMsgId                       7a   Const
  57.      D  RtMsgFq                      20a   Const
  58.      D  RtMsgDta                    512a   Const  Options( *VarSize )
  59.      D  RtMsgDtaLen                  10i 0 Const
  60.      D  RtRplSubVal                  10a   Const
  61.      D  RtRtnFmtChr                  10a   Const
  62.      D  RtError                   32767a          Options( *VarSize )
  63.  
  64.      D GetSize         ds
  65.      D  GetBytRtn                    10i 0
  66.      D  GetBytAvl                    10i 0
  67.      D Fmt0400         ds                  based(FmtPtr)
  68.      D  BytRtn                       10i 0
  69.      D  BytAvl                       10i 0
  70.      D  OffDftRpy             53     56i 0
  71.      D  LenDftRpyR            57     60i 0
  72.      D  RpyType              105    114
  73.      D  MaxRpyLen            117    120i 0
  74.      D  OffVldRpy            125    128i 0
  75.      D  NbrVldRpyR           129    132i 0
  76.      D  LenVldRpyR           133    136i 0
  77.      D  LenVldRpyA           137    140i 0
  78.      D  LenVldRpyE           141    144i 0
  79.  
  80.      D Upper           C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  81.      D Lower           C                   'abcdefghijklmnopqrstuvwxyz'
  82.  
  83.      D DftRpy          S             32
  84.      D DftRpyE         S             32    based(DftRpyPtr)
  85.      D VldRpyE         S             32    based(VldRpyPtr)
  86.      D VldRpyAryStr    S            320
  87.      D VldRpyAry       S             32    Dim(10)
  88.      D VldRpyAryIdx    S              3i 0
  89.  
  90.      D ErrorNull       Ds
  91.      D    BytesProv                  10i 0 inz(0)
  92.      D    BytesAvaile                10i 0 inz(0)
  93.  
  94.      **-- Send escape message:
  95.      D SndEscMsg       Pr            10i 0
  96.      D  PxMsgId                       7a   Const
  97.      D  PxMsgF                       10a   Const
  98.      D  PxMsgDta                    512a   Const  Varying
  99.      **-- Send completion message:
  100.      D SndCmpMsg       Pr            10i 0
  101.      D  PxMsgDta                    512a   Const  Varying
  102.  
  103.      **-- Send program message:
  104.      D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
  105.      D  MsgId                         7a   Const
  106.      D  MsgFq                        20a   Const
  107.      D  MsgDta                      128a   Const
  108.      D  MsgDtaLen                    10i 0 Const
  109.      D  MsgTyp                       10a   Const
  110.      D  CalStkE                      10a   Const  Options( *VarSize )
  111.      D  CalStkCtr                    10i 0 Const
  112.      D  MsgKey                        4a
  113.      D  Error                      1024a          Options( *VarSize )
  114.  
  115.       * Prototypes
  116.      D CrtUsrSpc       PR                  ExtPgm( 'QUSCRTUS' )
  117.      D  QlSpcName                    20    Const
  118.      D  ExtAttr                      10    Const
  119.      D  SizeInBytes                  10I 0 Const
  120.      D  InitVal                       1    Const
  121.      D  PublicAut                    10    Const
  122.      D  TextDesc                     50    Const
  123.      D  Replace                      10    Const
  124.      D   ReplaceYes    C                   '*YES'
  125.      D   ReplaceNo     C                   '*NO'
  126.      D  ApiErrInfo                         Like( ApiErr )
  127.  
  128.      D ChgUsrSpcAttr   PR                  ExtPgm( 'QUSCUSAT' )
  129.      D  RetdLibName                  10
  130.      D  QlUsrSpcName                 20    Const
  131.      D  AttrToChg                          Like( EnableAutoExtendDs )
  132.      D                                     Const
  133.      D  ApiErrInf                          Like( ApiErr )
  134.  
  135.      D DltUsrSpc       PR                  ExtPgm( 'QUSDLTUS' )
  136.      D  QlUsrSpcName                 20    Const
  137.      D  ApiErrInfo                         Like( ApiErr )
  138.  
  139.      D AddrOfUsrSpc    PR                  ExtPgm( 'QUSPTRUS' )
  140.      D  QlUsrSpcName                 20    Const
  141.      D  PtrToUsrSpc                    *
  142.      D  ApiErrInfo                         Like( ApiErr )
  143.  
  144.      D As400ObjFound   PR              N
  145.      D  QlObjName                    20    Value
  146.      D  ObjType                      10    Value
  147.  
  148.      D SndRpyMsg       PR                  ExtPgm( 'QMHSNDRM' )
  149.      D  SndMsgKey                     4    Const
  150.      D  SndQualMsgq                  20    Const
  151.      D  SndRpyMsgTxt                100    Const
  152.      D  SndRpyMsgLen                 10I 0 Const
  153.      D  SndRmvMsg                    10    Const
  154.      D  ApiErrInf                          Like( ApiErr )
  155.  
  156.      D LstMsgsFrmQ     PR                  ExtPgm( 'QMHLSTM' )
  157.      D  QlUsrSpcName                 20    Const
  158.      D  FmtName                       8    Const
  159.      D   LSTM0100      C                   'LSTM0100'
  160.      D  MsgSltInf                          Like( MsgSltInfo )
  161.      D                                     Const
  162.      D  SizeOfMsgSltInf...
  163.      D                               10I 0 Const
  164.      D  FmtOfMsgSltInf...
  165.      D                                8    Const
  166.      D   MSLT0100      C                   'MSLT0100'
  167.      D  ApiErrInf                          Like( ApiErr )
  168.  
  169.       * Other program data
  170.      D RetdLibName     S             10
  171.  
  172.      D EnableAutoExtendDs...
  173.      D                 DS
  174.      D  NumFlds                      10I 0 Inz( 1 )
  175.      D  KeyForAutoExtend...
  176.      D                               10I 0 Inz( 3 )
  177.      D  LengthOfData                 10I 0 Inz( 1 )
  178.      D  AutoExtendVal                 1    Inz( '1' )
  179.  
  180.      D ApiErr          DS
  181.      D  AeBytesProv                  10I 0 Inz( %Size( ApiErr ) )
  182.      D  AeBytesAvl                   10I 0
  183.      D  AeMsgId                       7
  184.      D                                1
  185.      D  AeMsgDta                    256
  186.  
  187.      D MsgSltInfo      DS
  188.      D  MsiMaxMsgsReq                10I 0 Inz( -1 )
  189.      D  MsiListDirection...
  190.      D                               10    Inz( '*NEXT' )
  191.      D  MsiSelectionCriterion...
  192.      D                               10    Inz( '*MNR' )
  193.      D  MsiSevCriterion...
  194.      D                               10I 0 Inz( *Zero )
  195.      D  MsiMaxMsgLen                 10I 0 Inz( 112 )
  196.      D  MsiMaxHlpLen                 10I 0 Inz( 4 )
  197.      D  MsiOffstToQlMsgqName...
  198.      D                               10I 0
  199.      D  MsiOffstToStrMsgKey...
  200.      D                               10I 0
  201.      D  MsiNumMsgQs                  10I 0 Inz( 1 )
  202.      D  MsiOffstToFldRetdId...
  203.      D                               10I 0
  204.      D  MsiNumFldsToReturn...
  205.      D                               10I 0 Inz( 3 )
  206.      D  MsiQlMsgqName                20
  207.      D  MsiStrMsgKey                  4    Inz( X'00000000' )
  208.      D  MsiFldRetdId                 10I 0 Inz( 302 )
  209.      D  MsiFldRetdId1                10I 0 Inz( 601 )
  210.      D  MsiFldRetdId2                10I 0 Inz(1001 )
  211.  
  212.      D UsrSpcHdr       DS                  Based( SpcPtr )
  213.      D  OffstTo1stSpcEntry...
  214.      D                       125    128I 0
  215.      D  NumberOfMsgs         133    136I 0
  216.  
  217.      D UsrSpcEntry     DS                  Based( UsePtr )
  218.      D  UseOffstToNxtEntry...
  219.      D                         1      4I 0
  220.      D  UseOffstToFldsReturned...
  221.      D                         5      8I 0
  222.      D  UseMsgId              17     23
  223.      D  UseMsgType            24     25
  224.      D  UseMsgKey             26     29
  225.      D  UseMsgF               30     39
  226.      D  UseMsgFLib            40     49
  227.      D  UseMsgQ               50     59
  228.      D  UseMsgQLib            60     69
  229.  
  230.      D RetdFldsDs      DS                  Based( RetdFldsDsPtr )
  231.      D  NextFldRtnOfs          1      4I 0
  232.      D  Rf1stLvlTxtLen...
  233.      D                        29     32I 0
  234.      D  Rf1stLvlTxt           33    144
  235.  
  236.      D ScMsgId         S              7
  237.      D ScMsgType       S              2
  238.      D ScMsgKey        S              4
  239.      D ScJob           S             10
  240.      D ScUsr           S             10
  241.      D ScNbr           S              6
  242.      D ScJobSts        S             10
  243.      D ScRpySts        S              1
  244.      D Sc1stLvl        S            112
  245.      D dftRpyValueErr  S               N
  246.  
  247.      D main            PR                  ExtPgm('AUTORPY')
  248.      D  qualMsgqName                 20
  249.      D  rpyMsgid                      7
  250.      D  rpyMsgValue                  32
  251.      D  rpyToJob                     10
  252.  
  253.      D main            PI
  254.      D  qualMsgqName                 20
  255.      D  rpyMsgid                      7
  256.      D  rpyMsgValue                  32
  257.      D  rpyToJob                     10
  258.  
  259.      C                   Eval      MsiQlMsgqName = qualMsgQName
  260.      C                   CallP     As400ObjFound( MsiQlMsgqName:
  261.      C                                                '*MSGQ' )
  262.  
  263.       * Set offset fields in the Msi data structure
  264.      C                   Eval      MsiOffstToQlMsgqName
  265.      C                             =   %Addr( MsiQlMsgqName )
  266.      C                               - %Addr( MsgSltInfo    )
  267.      C                   Eval      MsiOffstToStrMsgKey
  268.      C                             =   %Addr( MsiStrMsgKey  )
  269.      C                               - %Addr( MsgSltInfo    )
  270.      C                   Eval      MsiOffstToFldRetdId
  271.      C                             =   %Addr( MsiFldRetdId  )
  272.      C                               - %Addr( MsgSltInfo    )
  273.  
  274.      C                   ExSr      LoadUsrSpc
  275.  
  276.      C                   ExSr      ProcessMsgs
  277.  
  278.      C                   Eval      *INLR = *On
  279.  
  280.       * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
  281.       * LoadUsrSpc - Creates and then loads the user space with the
  282.       *              1st level text of all messages in the specified
  283.       *              message queue.
  284.      C     LoadUsrSpc    BegSr
  285.  
  286.       * Just to be on the safe side, delete the user space before
  287.       * attempting to create it.
  288.      C                   CallP     DltUsrSpc( 'MSGSPC    QTEMP': ApiErr )
  289.  
  290.      C                   CallP     CrtUsrSpc( 'MSGSPC    QTEMP':
  291.      C                                        *Blank:
  292.      C                                        25000:
  293.      C                                        X'00':
  294.      C                                        '*ALL':
  295.      C                                        *Blank:
  296.      C                                        ReplaceYes:
  297.      C                                        ApiErr )
  298.  
  299.       * If there was an error in the API, terminate the subroutine
  300.      C                   If        AeBytesAvl > *Zero
  301.      C                   CallP     SndEscMsg( AeMsgId
  302.      C                                : 'QCPFMSG'
  303.      C                                : %Subst( AeMsgDta: 1: AeBytesAvl-16 )
  304.      C                                       )
  305.      C                   LeaveSr
  306.      C                   EndIf
  307.  
  308.       * Turn on the autoextend attribute for this user space
  309.      C                   CallP     ChgUsrSpcAttr( RetdLibName:
  310.      C                                            'MSGSPC    QTEMP':
  311.      C                                            EnableAutoExtendDs:
  312.      C                                            ApiErr )
  313.  
  314.       * If there was an error in the API, terminate the subroutine
  315.      C                   If        AeBytesAvl > *Zero
  316.      C                   LeaveSr
  317.      C                   EndIf
  318.  
  319.       * Populate the user space with the messages
  320.      C                   CallP     LstMsgsFrmQ( 'MSGSPC    QTEMP':
  321.      C                                          LSTM0100:
  322.      C                                          MsgSltInfo:
  323.      C                                          %Size( MsgSltInfo ):
  324.      C                                          MSLT0100:
  325.      C                                          ApiErr )
  326.  
  327.       * If there was an error in the API, terminate the subroutine
  328.      C                   If        AeBytesAvl > *Zero
  329.      C                   CallP     SndEscMsg( AeMsgId
  330.      C                                : 'QCPFMSG'
  331.      C                                : %Subst( AeMsgDta: 1:AeBytesAvl- 16 )
  332.      C                                       )
  333.      C                   LeaveSr
  334.      C                   EndIf
  335.  
  336.       * Get a pointer to the user space
  337.      C                   CallP     AddrOfUsrSpc( 'MSGSPC    QTEMP':
  338.      C                                           SpcPtr:
  339.      C                                           ApiErr )
  340.  
  341.       * If there was an error in the API, terminate the subroutine
  342.      C                   If        AeBytesAvl > *Zero
  343.      C                   CallP     SndEscMsg( AeMsgId
  344.      C                                : 'QCPFMSG'
  345.      C                                : %Subst( AeMsgDta: 1: AeBytesAvl-16 )
  346.      C                                       )
  347.      C                   LeaveSr
  348.      C                   EndIf
  349.  
  350.      C                   EndSr
  351.  
  352.       * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
  353.       * ProcessMsgs  -- Process messages in the specified message queue
  354.      C     ProcessMsgs   BegSr
  355.  
  356.       * Set the basing pointer for the User Space Entry for the first
  357.       * message in the subfile.
  358.      C                   Eval        UsePtr
  359.      C                             = SpcPtr + OffstTo1stSpcEntry
  360.      C                   Do        NumberOfMsgs
  361.       * move user space values to screen
  362.      C                   Eval      ScMsgId  = UseMsgId
  363.      C                   Eval      ScMsgType = UseMsgType
  364.      C                   Eval      ScMsgKey = UseMsgKey
  365.      C*    ScMsgId       dsply
  366.       * get Message Text
  367.      C                   Eval        RetdFldsDsPtr
  368.      C                             = SpcPtr + UseOffstToFldsReturned
  369.      C                   Eval        Sc1stLvl
  370.      C                             = %Subst( Rf1stLvlTxt: 1:
  371.      C                                       Rf1stLvlTxtLen )
  372.       * get Sender Qualjob
  373.      C                   Eval        RetdFldsDsPtr
  374.      C                             = SpcPtr + NextFldRtnOfs
  375.      C                   Eval        SCJob
  376.      C                             = %Subst( Rf1stLvlTxt: 1: 10)
  377.      C                   Eval        SCUsr
  378.      C                             = %Subst( Rf1stLvlTxt:11: 10)
  379.      C                   Eval        SCNbr
  380.      C                             = %Subst( Rf1stLvlTxt:21:  6)
  381.       * get message reply status
  382.      C                   Eval        RetdFldsDsPtr
  383.      C                             = SpcPtr + NextFldRtnOfs
  384.      C                   Eval        SCRpySts
  385.      C                             = %Subst( Rf1stLvlTxt: 1: 10)
  386.      C*    ScRpySts      dsply
  387.      C                   If        UseMsgType = '05' and
  388.      C                             SCRpySts   = 'W'
  389.      C                   If        UseMsgId = rpyMsgId
  390.      C                   ExSr      ChkRpyValue
  391.      C                   If        rpyToJob   =  *blanks or
  392.      C                             (rpyToJob   <> *blanks and
  393.      C                              ScJob    = rpyToJob       )
  394.      C                   ExSr      RpyMsg
  395.      C                   EndIf
  396.      C                   EndIf
  397.      C                   EndIf
  398.      C                   Eval      UsePtr =   SpcPtr
  399.      C                                      + UseOffstToNxtEntry
  400.  
  401.      C                   EndDo
  402.  
  403.      C                   EndSr
  404.  
  405.       * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
  406.       * ChkRpyValue - Check reply value valid or not
  407.      C     ChkRpyValue   BegSr
  408.  
  409.      c                   eval      dftRpyValueErr = *Off
  410.      C* How much storage is needed for everything?
  411.      C                   callp     GetMsg( GetSize       :%size(GetSize)
  412.      C                                    :'RTVM0400'    :UseMsgId
  413.      C                                    : UseMsgF + UseMsgFLib
  414.      C                                    :' '           :0
  415.      C                                    :'*NO'         :'*NO'
  416.      C                                    :ErrorNull)
  417.      c* Allocate it and then call the API again
  418.      c                   eval      FmtPtr = %alloc(GetBytAvl)
  419.      c                   callp     GetMsg( Fmt0400       :GetBytAvl
  420.      c                                    :'RTVM0400'    :UseMsgID
  421.      c                                    :UseMsgF + UseMsgFLib
  422.      c                                    :' '           :0
  423.      c                                    :'*NO'         :'*NO'
  424.      c                                    :ErrorNull)
  425.      c* Default replies returned
  426.      c                   if        rpyMsgValue = '*DFT'
  427.      c                   if        LenDftRpyR > 0
  428.      c                   eval      DftRpyPtr = FmtPtr + OffDftRpy
  429.      c                   eval      DftRpy  = %SubSt(DftRpyE:1:LenDftRpyR)
  430.      c*    DftRpy        dsply
  431.      c                   eval      rpyMsgValue = DftRpy
  432.      c                   else
  433.      c                   eval      dftRpyValueErr = *On
  434.      c                   endif
  435.      c                   endif
  436.      c* Any valid replies returned
  437.      c                   if        NbrVldRpyR > 0
  438.      c                   eval      VldRpyPtr = FmtPtr + OffVldRpy
  439.      c                   eval      VldRpyAryIdx = 1
  440.      c                   reset                   VldRpyAry
  441.      c                   do        NbrVldRpyR
  442.      c*    VldRpyE       dsply
  443.      c                   eval      VldRpyAryStr = %trim(VldRpyAryStr) +
  444.      c                             ' ' + %trim(VldRpyE)
  445.      c                   eval      VldRpyAry(VldRpyAryIdx) = VldRpyE
  446.      c                   eval      VldRpyAryIdx = VldRpyAryIdx + 1
  447.      c                   eval      VldRpyPtr = VldRpyPtr + LenVldRpyE
  448.      c                   enddo
  449.  
  450.      c                   if        Not dftRpyValueErr
  451.      c     lower:upper   xlate     rpyMsgValue   rpyMsgValue
  452.      c                   if        %lookup(rpyMsgValue: VldRpyAry) = 0
  453.      C                   CallP     SndEscMsg( 'CPF9898'
  454.      C                             : 'QCPFMSG'
  455.      C                             : 'MsgId: ' + UseMsgId  +
  456.      C                               ' reply value ' + %trim(rpyMsgValue) +
  457.      C                               ' is not valid, valid reply value is '+
  458.      C                               %trim(VldRpyAryStr)
  459.      C                                       )
  460.      c                   endif
  461.      c                   else
  462.      C                   CallP     SndEscMsg( 'CPF9898'
  463.      C                             : 'QCPFMSG'
  464.      C                             : 'MsgId: ' + UseMsgId  +
  465.      C                               ' reply value ' + %trim(rpyMsgValue) +
  466.      C                               ' is not valid, no default reply' +
  467.      C                               ' setting, valid reply value is '+
  468.      C                               %trim(VldRpyAryStr)
  469.      C                                       )
  470.      c                   endif
  471.  
  472.      C                   endif
  473.      C                   EndSr
  474.  
  475.       * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
  476.       *
  477.      C     RpyMsg        BegSr
  478.      C
  479.      C                   CALLP     SndRpyMsg ( SCMsgKey :
  480.      C                                         MsiQlMsgqName :
  481.      C                                         %trim(rpyMsgValue):
  482.      C                                         %len(%trim(rpyMsgValue)):
  483.      C                                         '*NO' :
  484.      C                                         ApiErr)
  485.       * If there was an error in the API, terminate the subroutine
  486.      C                   If        AeBytesAvl > *Zero
  487.      C*    AeMsgId       DSPLY
  488.      C                   CallP     SndEscMsg( AeMsgId
  489.      C                                : 'QCPFMSG'
  490.      C                                : %Subst( AeMsgDta: 1 )
  491.      C                                       )
  492.      C                   Else
  493.      C                   Callp     SndCmpMsg(
  494.      C                              'MsgId:' + rpyMsgId + ' replied to job'+
  495.      C                              ' ' + %trim(SCNbr) + '/' + %trim(SCUSr)+
  496.      C                              '/' + %trim(SCJob) + ' with value ' +
  497.      C                              %trim(rpyMsgValue) + '.'
  498.      C                                      )
  499.      C                   EndIf
  500.      C
  501.      C                   EndSr
  502.  
  503.       * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * =
  504.       * As400ObjFound - Attempts to locate an AS/400 object
  505.      P As400ObjFound   B
  506.  
  507.      D As400ObjFound   PI              N
  508.      D  QlObjName                    20    Value
  509.      D  ObjType                      10    Value
  510.  
  511.       * Local variables and prototypes
  512.  
  513.      D RtvObjDesc      PR                  ExtPgm( 'QUSROBJD' )
  514.      D  RcvrVar                       8
  515.      D  LenRcvrVar                   10I 0 Const
  516.      D  FmtName                       8    Const
  517.      D  QlObjName                    20    Const
  518.      D  ObjType                      10    Const
  519.      D  ApiErrInf                          Like( ApiErr )
  520.  
  521.      D ApiErr          DS
  522.      D  AeBytesProv                  10I 0 Inz( %Size( ApiErr ) )
  523.      D  AeBytesAvl                   10I 0
  524.      D  AeMsgId                       7
  525.      D                                1
  526.      D  AeMsgDta                    256
  527.  
  528.      D Rcvr            S              8
  529.  
  530.  
  531.       * Invoke the QUSROBJD API to attempt to locate the object
  532.      C                   CallP     RtvObjDesc( Rcvr:
  533.      C                                         %Size( Rcvr ):
  534.      C                                         'OBJD0100':
  535.      C                                         QlObjName:
  536.      C                                         ObjType:
  537.      C                                         ApiErr )
  538.  
  539.       * If the API returns any error at all, I assume we were unable to
  540.       * locate the object.
  541.      C                   If        AeBytesAvl > *Zero
  542.      C                   CallP     SndEscMsg( AeMsgId
  543.      C                                : 'QCPFMSG'
  544.      C                                : %Subst( AeMsgDta: 1:AeBytesAvl- 16 )
  545.      C                                       )
  546.      C                   Return    *Off
  547.      C                   Else
  548.      C                   Return    *On
  549.      C                   EndIf
  550.  
  551.      P As400ObjFound   E
  552.      **-- Send escape message:  ----------------------------------------------**
  553.      P SndEscMsg       B
  554.      D                 Pi            10i 0
  555.      D  PxMsgId                       7a   Const
  556.      D  PxMsgF                       10a   Const
  557.      D  PxMsgDta                    512a   Const  Varying
  558.      **
  559.      D MsgKey          s              4a
  560.  
  561.      C                   Callp     SndPgmMsg( PxMsgId
  562.      C                                       : PxMsgF + '*LIBL'
  563.      C                                       : PxMsgDta
  564.      C                                       : %Len( PxMsgDta )
  565.      C                                       : '*ESCAPE'
  566.      C                                       : '*PGMBDY'
  567.      C                                       : 1
  568.      C                                       : MsgKey
  569.      C                                       : ApiErr
  570.      C                                      )
  571.  
  572.      C                   If        AeBytesAvl > *Zero
  573.      C                   Return    -1
  574.      C
  575.      C                   Else
  576.      C                   Return    0
  577.      C                   EndIf
  578.      P SndEscMsg       E
  579.      **-- Send completion message:  ------------------------------------------**
  580.      P SndCmpMsg       B
  581.      D                 Pi            10i 0
  582.      D  PxMsgDta                    512a   Const  Varying
  583.  
  584.      D MsgKey          s              4a
  585.  
  586.      C                   Callp     SndPgmMsg( 'CPF9897'
  587.      C                                       : 'QCPFMSG   *LIBL'
  588.      C                                       : PxMsgDta
  589.      C                                       : %Len( PxMsgDta )
  590.      C                                       : '*COMP'
  591.      C                                       : '*PGMBDY'
  592.      C                                       : 1
  593.      C                                       : MsgKey
  594.      C                                       : ApiErr
  595.      C                                      )
  596.  
  597.      C                   If        AeBytesAvl > *Zero
  598.      C                   Return    -1
  599.      C
  600.      C                   Else
  601.      C                   Return    0
  602.      C                   EndIf
  603.  
  604.      **
  605.      P SndCmpMsg       E
  606.  
  607.  
  608. <b>
  609. File   : QCMDSRC
  610. Member : AUTORPY
  611. Type   : CMD
  612. Usage  : CRTCMD CMD(AUTORPY) PGM(AUTORPY)
  613. </b>
  614. /*  ===============================================================  */
  615. /*  = Command....... AutoRpy                                      =  */
  616. /*  = CPP........... AutoRpy  RPGLE                               =  */
  617. /*  = Description... Auto reply to the sender of an inquiry       =  */
  618. /*  =                message.                                     =  */
  619. /*  =                                                             =  */
  620. /*  = CrtCmd      Cmd( AutoRpy   )                                =  */
  621. /*  =             Pgm( AutoRpy    )                               =  */
  622. /*  =             SrcFile( YourSourceFile )                       =  */
  623. /*  ===============================================================  */
  624. /*  = Date  : 2008/09/09                                          =  */
  625. /*  = Author: Vengoal Chang                                       =  */
  626. /*  ===============================================================  */
  627.              CMD        PROMPT('Auto Reply')
  628.  
  629.              PARM       KWD(MSGQ) TYPE(QUAL2) MIN(1) PROMPT('Message +
  630.                           queue')
  631.              PARM       KWD(MSGID) TYPE(*CHAR) LEN(7) PROMPT('Reply +
  632.                           message id')
  633.              PARM       KWD(REPLY) TYPE(*CHAR) LEN(32) DFT(*DFT) +
  634.                           SPCVAL((*DFT)) PROMPT('Reply')
  635.              PARM       KWD(LMTRPYJOB) TYPE(*NAME) LEN(10) +
  636.                           PROMPT('Reply to job')
  637.  
  638.  QUAL2:      QUAL       TYPE(*NAME) EXPR(*YES)
  639.              QUAL       TYPE(*NAME) DFT(*LIBL) SPCVAL((*LIBL) +
  640.                           (*CURLIB)) EXPR(*YES) PROMPT('Library')
  641.  
  642.  
  643.  
  644. Test Step:
  645. 1.
  646. CRTMSGF QGPL/TESTMSGF
  647. /* Add message id with no default reply value */
  648. ADDMSGD MSGID(TST0001) MSGF(QGPL/TESTMSGF) MSG(TEST_001) SEV(99) VALUES(C D R I)
  649.  
  650. /* Add message id with default reply value */
  651. ADDMSGD MSGID(TST0002) MSGF(QGPL/TESTMSGF) MSG(TEST_001) SEV(99) VALUES(C D R I) DFT(C) 
  652.  
  653. 2.
  654. AUTORPYT1 CLP:
  655. PGM
  656.   DCL &CURUSR *CHAR 10
  657.   RTVJOBA    USER(&CURUSR)
  658.     SNDUSRMSG  MSGID(TST0001) MSGF(QGPL/TESTMSGF) +
  659.                        TOUSR(&CURUSR)          
  660. ENDPGM
  661.  
  662. AUTORPYT2 CLP:
  663. PGM
  664.   DCL &CURUSR *CHAR 10
  665.   RTVJOBA    USER(&CURUSR)
  666.     SNDUSRMSG  MSGID(TST0002) MSGF(QGPL/TESTMSGF) +
  667.                        TOUSR(&CURUSR)          
  668. ENDPGM
  669.  
  670. 3.
  671. Compile AUTORPYT1, AUTORPYT2
  672.  
  673. 4. for example use USER01 subbmit job
  674. SBMJOB CMD(CALL AUTORPYT1) JOB(JOB1)  
  675. SBMJOB CMD(CALL AUTORPYT2) JOB(JOB2)
  676.  
  677. 5.
  678. DSPMSG USER01
  679.  
  680.                                Display Messages                               
  681.                                                       System:   DDSC810       
  682. Queue . . . . . :   USER01                    Program . . . . :   *DSPMSG       
  683.   Library . . . :     QUSRSYS                 Library . . . :                 
  684. Severity  . . . :   00                      Delivery  . . . :   *HOLD         
  685.                                                                               
  686. Type reply (if required), press Enter.                                        
  687.   Job 690946/USER01/JOB2 completed normally on 09/09/08 at 15:17:58.         
  688.   Job 690962/USER01/JOB1 completed normally on 09/09/08 at 15:17:58.         
  689.   TEST 0001                                                                   
  690.     Reply . . .                                                               
  691.   Waiting for reply to message on message queue USER01.                      
  692.   TEST_002                                                                    
  693.     Reply . . .                                                               
  694.   Waiting for reply to message on message queue USER01.                      
  695.                                                                               
  696.  
  697.  
  698. 6.
  699. AUTORPY MSGQ(USER01) MSGID(TST0001)
  700. MSGID TST001 does not set default reply value,so we got following message :   
  701.                         Additional Message Information                         
  702.                                                                                
  703. Message ID . . . . . . :   CPF9898       Severity . . . . . . . :   40         
  704. Message type . . . . . :   Information                                         
  705. Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:19:26   
  706.                                                                                
  707. Message . . . . :   MsgId: TST0001 reply value *DFT is not valid, no default   
  708.   reply setting, valid reply value is C D E F.                                 
  709. Cause . . . . . :   This message is used by application programs as a general  
  710.   escape message.                                                              
  711.                                                                                                                                                             
  712.                                                                                
  713.  
  714. 7.
  715. AUTORPY MSGQ(USER01) MSGID(TST0001) REPLY(C)
  716. Got following message:
  717.                         Additional Message Information                         
  718.                                                                                
  719. Message ID . . . . . . :   CPF9897       Severity . . . . . . . :   40         
  720. Message type . . . . . :   Information                                         
  721. Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:22:06   
  722.                                                                                
  723. Message . . . . :   MsgId:TST0001 replied to job 690963/USER01/JOB1 with      
  724.   value C.                                                                     
  725. Cause . . . . . :   No additional online help information is available.        
  726.  
  727. 7.1 DSPMSG USER01
  728.  
  729.                                Display Messages                                
  730.                                                       System:   DDSC810        
  731. Queue . . . . . :   USER01                  Program . . . . :   *DSPMSG        
  732.   Library . . . :     QUSRSYS                 Library . . . :                  
  733. Severity  . . . :   00                      Delivery  . . . :   *HOLD          
  734.                                                                                
  735. Type reply (if required), press Enter.                                         
  736.   Job 690946/USER01/JOB2 completed normally on 09/09/08 at 15:17:58.          
  737.   Job 690962/USER01/JOB1 completed normally on 09/09/08 at 15:17:58.          
  738.   TEST 0001                                                                    
  739.     Reply . . :   C                                                            
  740.   Waiting for reply to message on message queue USER01.                       
  741.   TEST_002                                                                     
  742.     Reply . . .                                                                
  743.   Waiting for reply to message on message queue USER01.                       
  744.   Job 690963/VENGOAL/JOB1 completed normally on 09/09/08 at 15:22:06.          
  745.                                                                                  
  746.  
  747. 8.
  748. AUTORPY MSGQ(USER01) MSGID(TST0002) REPLY(RR) <== Reply TST002 message with wrong value
  749. Got following message:
  750.                         Additional Message Information                         
  751.                                                                                
  752. Message ID . . . . . . :   CPF9898       Severity . . . . . . . :   40         
  753. Message type . . . . . :   Information                                         
  754. Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:26:54   
  755.                                                                                
  756. Message . . . . :   MsgId: TST0002 reply value RR is not valid, valid reply    
  757.   value is C D R I.                                                          
  758. Cause . . . . . :   This message is used by application programs as a general  
  759.   escape message.                                                              
  760.  
  761. 9.
  762. AUTORPY MSGQ(USER01) MSGID(TST0002) JOB(JOB3)
  763. Because we just submitted JOB1,JOB2, the TST0002 still isn't replied.
  764. DSPMSG USER01 will got same step 7.1 result.
  765.  
  766. 10.
  767. AUTORPY MSGQ(USER01) MSGID(TST0002) LMTRPYJOB(JOB2)
  768. Got following message:
  769.                         Additional Message Information                        
  770.                                                                               
  771. Message ID . . . . . . :   CPF9897       Severity . . . . . . . :   40        
  772. Message type . . . . . :   Information                                        
  773. Date sent  . . . . . . :   09/09/08      Time sent  . . . . . . :   15:34:13  
  774.                                                                               
  775. Message . . . . :   MsgId:TST0002 replied to job 690965/USER01/JOB2 with     
  776.   value C.                                                                    
  777. Cause . . . . . :   No additional online help information is available.       
  778.                                                                               
  779. 10.1
  780. DSPMSG USER01
  781.                                Display Messages                                
  782.                                                       System:   DDSC810        
  783. Queue . . . . . :   USER01                  Program . . . . :   *DSPMSG        
  784.   Library . . . :     QUSRSYS                 Library . . . :                  
  785. Severity  . . . :   00                      Delivery  . . . :   *HOLD          
  786.                                                                                
  787. Type reply (if required), press Enter.                                         
  788.   Job 690946/USER01/JOB2 completed normally on 09/09/08 at 15:17:58.          
  789.   Job 690962/USER01/JOB1 completed normally on 09/09/08 at 15:17:58.          
  790.   TEST 0001                                                                    
  791.     Reply . . :   C                                                            
  792.   Waiting for reply to message on message queue USER01.                       
  793.   TEST_002                                                                     
  794.     Reply . . :   C                                                            
  795.   Waiting for reply to message on message queue USER01.                       
  796.   Job 690963/USER01/JOB1 completed normally on 09/09/08 at 15:22:06.          
  797.   Job 690965/USER01/JOB2 completed normally on 09/09/08 at 15:34:13.          
  798. </pre>
© 2004-2019 by midrange.com generated in 0.012s valid xhtml & css