如何於 RPG 中直接傳送訊息(QMHSNDM API)至 Message Queue及從 Message Queue 接收訊息(QMHRCVM API) ?
利用 system API
QMHSNDM API : 傳送訊息至 Message Queue , 範例 RPGLE QMHSNDMR
QMHRCVM API : 從 Message Queue 接收訊息 , 範例 RPGLE QMHRCVMR
File : QRPGLESRC
Member: QMHSNDMR 傳送訊息至 QSYSOPR Message Queue
Type : RPGLE
Usage : CRTBNDRPG QMHSNDMR
CALL QMHSNDMR
D STRUCT DS
D MSGDLN 10I 0
D MSGQ# 10I 0
D MSGKEY 4
D MSGQ 20 INZ('QSYSOPR *LIBL ')
*
D*****************************************************************
D* The following is copied from QSYSINC/QRPGSRC member QUSEC
D* so that the variable length field QUSBNG can be defined
D* as 100 bytes for exception data. The defined field is
D* named EXCDTA.
D*****************************************************************
D QUSBN DS
D* Qus EC
D QUSBNB 1 4B 0
D* Bytes Provided
D QUSBNC 5 8B 0
D* Bytes Available
D QUSBND 9 15
D* Exception Id
D QUSBNF 16 16
D* Reserved
D* 17 17 QUSBNG
D* Varying length
D EXCDTA 17 116
*
D MSGTX1 C CONST('This is Test Message -
D from RPG.')
*
D MSGDTA DS
D MSGTXT 1 70
*
C MOVE *BLANKS QUSBN
C Z-ADD 0 QUSBNB
C* *
C MOVEL MSGTX1 MSGTXT
C CALL 'QMHSNDM'
C PARM *BLANKS MSGID 7
C PARM *BLANKS MSGFIL 20
C PARM MSGDTA
C PARM 70 MSGDLN
C PARM '*INFO ' MSGTYP 10
C PARM MSGQ
C PARM 1 MSGQ#
C PARM *BLANKS RPYMQ 20
C PARM MSGKEY
C PARM QUSBN
C*
C RETURN
File : QRPGLESRC
Member: QMHRCVMR 從 QSYSOPR Message Queue 接收訊息
Type : RPGLE
Usage : CRTBNDPGM QMHRCVMR
CALL QMHRCVMR
DMSGINFO DS
D ByteRet 10I 0
D ByteAvl 10I 0
D MsgSev 10I 0
D MsgId 7A
D MsgTypeO 2A
D MsgKeyO 4A
D MsgFileNm 10A
D MsgLibSpec 10A
D MsgLibUsed 10A
D SndJob 10A
D SndUsr 10A
D SndJobNbr 6A
D SndPgm 12A
D Rsrvd1 4A
D DateSent 7A
D TimeSent 6A
D Rsrvd3 17A
D CnvStat 10I 0
D CCSIDData 10I 0
D Alert 9A
D CCSIDMsg 10I 0
D CCSIDRpl 10I 0
D LenRplDta 10I 0
D LenRplAvl 10I 0
D LenMsgRet 10I 0
D LenMsgAvl 10I 0
D LenHlpRet 10I 0
D LenHlpAvl 10I 0
D RplData 256A
D Message 256A
D MsgHlp 256A
DMsgInfoLn S 10I 0
DFmtName S 8A
DMsgQueue S 20A
DMsgType S 10A
DMsgKey S 4A
DWaitTime S 10I 0
DMsgAction S 10A
DMsgDta S 50A
DErrCde DS
D BProvd 10I 0
D BAvail 10I 0
D ExcpId 7A
D Rsrvd2 1A
D ExcpDta 256A
C eval MsgInfoLn=944
c eval FmtName='RCVM0200'
C eval MsgQueue='QSYSOPR *LIBL '
c* eval MsgType='*ANY'
c eval MsgType='*LAST'
c* eval MsgType='*FIRST'
C eval MsgKey=*BLANKS
C eval WaitTime=0
C eval MsgAction='*SAME'
C* eval MsgAction='*OLD'
C Call 'QMHRCVM'
C Parm MsgInfo
C parm MsgInfoLn
C parm FmtName
C parm MsgQueue
C parm MsgType
C parm MsgKey
C parm WaitTime
C parm MsgAction
C parm ErrCde
C Eval MsgDta = %subst(RPLDATA : 1 : 30)
C MsgDta Dsply
C Eval MsgDta = %subst(RPLDATA:LENRPLDTA + 1 : +
C LENMSGRET)
C MsgID Dsply
C MsgDta Dsply
C Eval *InLr = *On
參考資料
QMHSNDM()--Send Nonprogram Message
http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/info/apis/QMHSNDM.HTM
QMHRCVM()--Receive Nonprogram Message
http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/info/apis/Qmhrcvm.htm
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期三, 11月 01, 2023
2002-04-22 如何於 RPG 中直接傳送訊息(QMHSNDM API)至 Message Queue及從 Message Queue 接收訊息(QMHRCVM API) ?
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言