星期一, 11月 06, 2023

2004-10-18 如何於 RPG 中將程式執行中的訊息寫入 JobLog 中 ?(API QMHSNDPM)


如何於 RPG 中將程式執行中的訊息寫入 JobLog 中 ?(API QMHSNDPM)

File  : QRPGLESRC
Member: SNDPGMMSGR
Type  : RPGLE
Usage : CRTBNDRPG SNDPGMMSGR
        CALL SNDPGMMSGR
        畫面 24 行會顯示此程式所傳送之訊息,同時此訊息亦會寫入JOBLOG,可以執行
        DSPJOBLOG 顯示 Job Log(工作日誌)。
        此範例中有四種訊息傳送方式,最常使用是 *INFO(一般資訊), *COMP(程式執行完成時的訊息), 
        *DIAG(程式錯誤偵測訊息), *ESCAPE(程式執行錯誤訊息),一般當系統偵測到程式執行錯誤時,
        會先發送 *DIAG 訊息,再發送 *ESCAPE 訊息,但是如果是自己所寫的程式可以直接發送
        *ESCAPE 訊息,通知系統程式不正常結束。


     H dftactgrp(*NO)

     D sndpgmmsg       PR
     D   peMsg                      256A   const
     D   outMsgType                  10A   const


     C                   callp     sndpgmmsg('test  *INFO' : '*INFO')
     C                   callp     sndpgmmsg('test  *COMP' : '*COMP')
     C                   callp     sndpgmmsg('test  *DIAG' : '*DIAG')
     C                   callp     sndpgmmsg('test  *ESCAPE msg' : '*ESCAPE')

     C                   eval      *InLr = *On

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  This ends this program abnormally, and sends back an escape.
      *   message explaining the failure.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P sndpgmmsg       B
     D sndpgmmsg       PI
     D   peMsg                      256A   const
     D   outMsgType                  10A   const

     D QMHSNDPM        PR                  ExtPgm('QMHSNDPM')
     D   MessageID                    7A   Const
     D   QualMsgF                    20A   Const
     D   MsgData                    256A   Const
     D   MsgDtaLen                   10I 0 Const
     D   MsgType                     10A   Const
     D   CallStkEnt                  10A   Const
     D   CallStkCnt                  10I 0 Const
     D   MessageKey                   4A
     D   ErrorCode                32766A   options(*varsize)

     D dsEC            DS
     D  dsECBytesP             1      4I 0 INZ(256)
     D  dsECBytesA             5      8I 0 INZ(0)
     D  dsECMsgID              9     15
     D  dsECReserv            16     16
     D  dsECMsgDta            17    256

     D wwMsgLen        S             10I 0
     D wwTheKey        S              4A

     c                   eval      wwMsgLen = %len(%trimr(peMsg))
     c                   if        wwMsgLen<1
     c                   return
     c                   endif

     c                   callp     QMHSNDPM('CPF9897': 'QCPFMSG   *LIBL':
     c                               peMsg: wwMsgLen: %trim(outMsgType):
     c                               '*PGMBDY': 1: wwTheKey: dsEC)
     c*                  callp     QMHSNDPM('CPF9897': 'QCPFMSG   *LIBL':
     c*                              peMsg: wwMsgLen: %trim(outMsgType):
     c*                              '*': 3: wwTheKey: dsEC)

     c                   return
     P                 E

            




沒有留言: