工具:MONMSGQ 命令動態指定 MSGID,並藉由 QMHRCVM API 擷取訊息比對的自動監控訊息的工具
File : QCLSRC
Member : MONMSGQC
Type : CLP
Usage : CRTCLPGM MONMSGQC
/*------------------------------------------------------------------*/
/* PROGRAM ID : MONMSGQC */
/* PROGRAM NAME : CL OF MONITOR MESSAGE QUEUE */
/*------------------------------------------------------------------*/
PGM PARM(&MSGQANDLIB &MSGID &ACTION &RPY &CMD &CONTINUE &WAIT)
/*------------------------------------------------------------------*/
/* DECLARE */
/*------------------------------------------------------------------*/
/* COMMAND PARAMETER(S) FOR THIS PROGRAM */
DCL VAR(&MSGQANDLIB) TYPE(*CHAR) LEN( 20 ) /* MSGQ AND LIBRARY */
DCL VAR(&MSGQ ) TYPE(*CHAR) LEN( 10 ) /* MESSAGE QUEUE */
DCL VAR(&MSGQLIB ) TYPE(*CHAR) LEN( 10 ) /* LIBRARY */
DCL VAR(&MSGID ) TYPE(*CHAR) LEN( 7 ) /* MESSAGE ID */
DCL VAR(&ACTION ) TYPE(*CHAR) LEN( 5 ) /* ACTION */
DCL VAR(&RPY ) TYPE(*CHAR) LEN( 132 ) /* REPLY */
DCL VAR(&CMD ) TYPE(*CHAR) LEN(3000 ) /* COMMAND TO RUN */
DCL VAR(&CONTINUE ) TYPE(*CHAR) LEN( 4 ) /* CONTINUE ? */
DCL VAR(&WAIT ) TYPE(*CHAR) LEN( 6 ) /* WAIT TIME */
/* NO MAX WAIT TIME */
/* DCL VAR(&WAITN ) TYPE(*DEC ) LEN( 15 5) VALUE(-1) */
/* SHARED PARAMETERS FOR THIS PROGRAM */
DCL VAR(&SH_MSG ) TYPE(*CHAR) LEN( 80 ) /* MESSAGE */
DCL VAR(&SH_MSGID ) TYPE(*CHAR) LEN( 7 ) /* MESSAGE ID */
DCL VAR(&SBMJOB ) TYPE(*CHAR) LEN(3500 ) /* SUBMIT JOB COMMAND */
DCL VAR(&CMDLEN ) TYPE(*DEC ) LEN( 15 5) /* LENGTH OF COMMAND */
DCL VAR(&BYTAVLC ) TYPE(*CHAR) LEN( 4 ) /* BYTES AVAILABLE */
DCL VAR(&BYTAVL ) TYPE(*DEC ) LEN( 15 5) /* BYTES AVAILABLE */
/*--+--------------------+--*/
/* + PARAMETERS FOR API + */
/*--+--------------------+--*/
/* QMHRCVM */
DCL VAR(&RCM_MSG ) TYPE(*CHAR) LEN( 25 ) /* MESSAGE */
DCL VAR(&MSG_ID ) TYPE(*CHAR) LEN( 7 ) /* MESSAGE ID */
DCL VAR(&MSG_TYP ) TYPE(*CHAR) LEN( 2 ) /* MESSAGE TYPE */
DCL VAR(&MSG_KEY ) TYPE(*CHAR) LEN( 4 ) /* MESSAGE KEY */
DCL VAR(&MSG_KEYBIN) TYPE(*CHAR) LEN( 4 ) /* MESSAGE KEY */
DCL VAR(&RCM_MSGLEN) TYPE(*CHAR) LEN( 4 ) /* LENGTH OF MESSAGE */
DCL VAR(&RCM_FORMAT) TYPE(*CHAR) LEN( 8 ) /* FORMAT */
DCL VAR(&RCM_MSGQ ) TYPE(*CHAR) LEN( 20 ) /* MESSAGE QUEUE */
DCL VAR(&RCM_MSGTYP) TYPE(*CHAR) LEN( 10 ) /* MESSAGE TYPE */
DCL VAR(&RCM_MSGKEY) TYPE(*CHAR) LEN( 4 ) /* MESSAGE KEY */
DCL VAR(&RCM_WAIT ) TYPE(*CHAR) LEN( 4 ) /* WAIT TIME */
DCL VAR(&RCM_ACTION) TYPE(*CHAR) LEN( 10 ) /* ACTION */
DCL VAR(&RCM_ERRCD ) TYPE(*CHAR) LEN( 15 ) /* ERROR CODE */
/*------------------------------------------------------------------*/
/* INITIALIZE */
/*------------------------------------------------------------------*/
/*- DIVISION OF COMMAND PARAMETER ----------------------------------*/
CHGVAR VAR(&MSGQ ) VALUE(%SST(&MSGQANDLIB 1 10))
CHGVAR VAR(&MSGQLIB ) VALUE(%SST(&MSGQANDLIB 11 10))
/*- CHECK OF COMMAND PARAMETER -------------------------------------*/
/* FOR MSGQ */
IF ((&MSGQLIB *NE '*LIBL' ) *AND (&MSGQLIB *NE '*CURLIB')) DO
CHKOBJ OBJ(&MSGQLIB) OBJTYPE(*LIB)
MONMSG MSGID(CPF9801) EXEC(DO)
RCVMSG MSGQ(*PGMQ) RMV(*YES)
/* MSG: LIBRARY NOT FOUND */
SNDPGMMSG MSGID(CPF9810) MSGF(QCPFMSG) +
MSGDTA(&MSGQLIB) +
MSGTYPE(*ESCAPE)
ENDDO
ENDDO
CHKOBJ OBJ(&MSGQLIB/&MSGQ) OBJTYPE(*MSGQ)
MONMSG MSGID(CPF9801) EXEC(DO)
RCVMSG MSGQ(*PGMQ) RMV(*YES)
/* MSG: MSG QUEUE IN LIBRARY NOT FOUND */
SNDPGMMSG MSGID(CPF2403) MSGF(QCPFMSG) +
MSGDTA(&MSGQANDLIB) +
MSGTYPE(*ESCAPE)
ENDDO
/* IF &ACTION IS *PGM OR *BOTH */
IF ((&ACTION *EQ '*PGM') *OR (&ACTION *EQ '*BOTH')) DO
IF (&CMD *EQ ' ') DO
CHGVAR VAR(&SH_MSG) VALUE('CMD PARAMETER' *BCAT +
'REQUIRED WITH' *BCAT +
'ACTION(' *CAT +
&ACTION *TCAT +
')' )
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA(&SH_MSG) +
MSGTYPE(*ESCAPE)
ENDDO
ENDDO
/*- PARAMETER SETTING ----------------------------------------------*/
/* FOR QMHRCVM */
CHGVAR VAR(%BIN(&RCM_MSGLEN)) VALUE(25)
CHGVAR VAR(&RCM_FORMAT) VALUE('RCVM0200')
CHGVAR VAR(&RCM_MSGQ ) VALUE(&MSGQANDLIB)
CHGVAR VAR(&RCM_MSGTYP) VALUE('*ANY')
CHGVAR VAR(&RCM_MSGKEY) VALUE(' ')
CHGVAR VAR(%BIN(&RCM_WAIT )) VALUE(&WAIT)
/* NOMAX WAIT TIME */
/* CHGVAR VAR(%BIN(&RCM_WAIT )) VALUE(&WAITN) */
CHGVAR VAR(&RCM_ACTION) VALUE('*OLD')
CHGVAR VAR(%BIN(&RCM_ERRCD 1 4)) VALUE(15)
/*------------------------------------------------------------------*/
/* M A I N */
/*------------------------------------------------------------------*/
MAIN:
CALL PGM(QMHRCVM ) PARM(&RCM_MSG +
&RCM_MSGLEN +
&RCM_FORMAT +
&RCM_MSGQ +
&RCM_MSGTYP +
&RCM_MSGKEY +
&RCM_WAIT +
&RCM_ACTION +
&RCM_ERRCD )
CHGVAR VAR(&BYTAVLC ) VALUE(%SST(&RCM_MSG 5 4))
CHGVAR VAR(&BYTAVL ) VALUE(%BIN(&BYTAVLC))
/* If you specify a value of zero or above and the message does not */
/* arrive in the specified time, most fields in the RCVM0100 or */
/* RCVM0200 output are unchanged. The bytes returned output field has*/
/* a value of 8, and the bytes available output field has a value of */
/* 0. The remaining output fields are unchanged; they contain */
/* whatever was already stored in the space. */
IF (&BYTAVL *EQ 0) GOTO CONTINUE
CHGVAR VAR(&MSG_ID ) VALUE(%SST(&RCM_MSG 13 7))
CHGVAR VAR(&MSG_TYP ) VALUE(%SST(&RCM_MSG 20 2))
CHGVAR VAR(&MSG_KEY ) VALUE(%SST(&RCM_MSG 22 4))
CHGVAR VAR(&MSG_KEYBIN) VALUE(%BIN(&MSG_KEY))
MONMSG MSGID(CPF0819) EXEC(DO)
RCVMSG MSGQ(*PGMQ) RMV(*YES)
ENDDO
/* IF MESSAGE ID FOUND IN MESSAGE QUEUE */
IF (&MSG_ID *EQ &MSGID) DO
/* FOR REPLY ACTION */
IF ((&ACTION *EQ '*RPY') *OR (&ACTION *EQ '*BOTH')) DO
SNDRPY MSGKEY(&MSG_KEY) MSGQ(&MSGQLIB/&MSGQ) RPY(&RPY) RMV(*NO)
MONMSG MSGID(CPF2401 CPF2403 CPF2408 CPF2410 +
CPF2411 CPF2420 CPF2422 CPF2432 +
CPF2433 CPF2477 CPD2406 ) EXEC(DO)
RCVMSG MSGQ(*PGMQ) RMV(*NO ) MSGID(&SH_MSGID)
CHGVAR VAR(&SH_MSG) VALUE('SEE THE PREVIOUSLY' *BCAT +
'LISTED MESSAGE ' *BCAT +
'IN THE JOBLOG ' *BCAT +
'(MSGID:' *CAT +
&SH_MSGID *CAT +
')' )
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA(&SH_MSG) +
MSGTYPE(*ESCAPE)
ENDDO
ENDDO
/* FOR SBMJOB ACTION */
IF ((&ACTION *EQ '*CMD') *OR (&ACTION *EQ '*BOTH')) DO
CHGVAR VAR(&SBMJOB ) VALUE('SBMJOB CMD(' *CAT +
&CMD *CAT +
')' *CAT +
' JOB(MON' *CAT +
&MSG_ID *CAT +
')' )
CHGVAR VAR(&CMDLEN ) VALUE(3500)
CALL PGM(QCMDEXC) PARM(&SBMJOB &CMDLEN)
ENDDO
ENDDO
CONTINUE:
IF (&CONTINUE *EQ *YES) GOTO MAIN
/*------------------------------------------------------------------*/
/* END OF PROGRAM */
/*------------------------------------------------------------------*/
EXIT:
ENDPGM
----------------------------------------------------------------------
File : QCMDSRC
Member : MONMSGQ
Type : CMD
Usage : CRTCMD MONMSGQ PGM(MONMSGQC)
/*------------------------------------------------------------------*/
/*--- COMMAND ID : MONMSGQ ---*/
/*--- COMMAND NAME : MONITOR MESSAGE QUEUE. ---*/
/*------------------------------------------------------------------*/
CMD PROMPT('MONITOR MESSAGE QUEUE')
PARM KWD(MSGQ) TYPE(MSGQ) MIN(1) +
PROMPT('MESSAGE QUEUE')
PARM KWD(MSGID) TYPE(*CHAR) LEN(7) MIN(1) +
FULL(*YES) EXPR(*YES) PROMPT('MESSAGE ID')
PARM KWD(ACTION) TYPE(*CHAR) LEN(5) RSTD(*YES) +
VALUES(*CMD *RPY *BOTH) MIN(1) EXPR(*YES) +
PROMPT(ACTION)
PARM KWD(RPY) TYPE(*CHAR) LEN(132) SPCVAL((*DFT)) +
EXPR(*YES) PMTCTL(IFRPY) PROMPT(REPLY)
PARM KWD(CMD) TYPE(*CMDSTR) LEN(3000) +
PMTCTL(IFPGM) PROMPT('COMMAND TO RUN(IN +
SBMJOB)')
PARM KWD(CONTINUE) TYPE(*CHAR) LEN(4) RSTD(*YES) +
DFT(*YES) VALUES(*YES *NO) EXPR(*YES) +
PROMPT('IF FOUND, THEN CONTINUE ?')
PARM KWD(WAIT) TYPE(*CHAR) LEN(6) DFT(30) RANGE(0 +
999999) EXPR(*YES) CHOICE(SECONDS) +
PMTCTL(*PMTRQS) PROMPT('WAIT TIME')
MSGQ: QUAL TYPE(*NAME) LEN(10) EXPR(*YES)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*LIBL) (*CURLIB)) EXPR(*YES) +
PROMPT(LIBRARY)
IFRPY: PMTCTL CTL(ACTION) COND((*EQ *RPY))
PMTCTL CTL(ACTION) COND((*EQ *BOTH)) LGLREL(*OR)
IFPGM: PMTCTL CTL(ACTION) COND((*EQ *CMD))
PMTCTL CTL(ACTION) COND((*EQ *BOTH)) LGLREL(*OR)
/* DEPENDENT DEFINITION */
DEP CTL(&ACTION *EQ *RPY) PARM((RPY))
DEP CTL(&ACTION *EQ *CMD) PARM((CMD))
DEP CTL(&ACTION *EQ *BOTH) PARM((RPY) (CMD))
使用方法
Command Entry DDSCS20
Request level: 2
Type command, press Enter.
===>
SBMJOB CMD( MONMSGQ MSGQ(QSYSOPR) MSGID(CPPEA12) ACTION(*CMD)
CMD(SNDDST TYPE(*LMSG) TOINTNET((user@yahoo.com.tw))
DSTD('test from MONMSGQ Command') LONGMSG('Test from MOMMSGQ')
)
) JOB(MONSYSOPR)
Receive Nonprogram Message (QMHRCVM) API 參考資料
Receive Nonprogram Message (QMHRCVM) API
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-01-15 工具:MONMSGQ 命令動態指定 MSGID,並藉由 QMHRCVM API 擷取訊息比對的自動監控訊息的工具
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言