Figure 2: Test for the SNDMSG command PGM /* ---------------------------------------------------------------- */ /* Declare variables */ /* ---------------------------------------------------------------- */ DCL VAR(&USER) TYPE(*CHAR) LEN(10) DCL VAR(&TEXT) TYPE(*CHAR) LEN(10) Catching all errors is important. /* ---------------------------------------------------------------- */ /* Catch all errors */ /* ---------------------------------------------------------------- */ MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDPGM)) This is the actual test /* ---------------------------------------------------------------- */ /* Send a message to the message queue */ /* ---------------------------------------------------------------- */ RTVJOBA USER(&USER) SNDMSG MSG('HALLO') TOUSR(&USER) RCVMSG MSGQ(&USER) MSG(&TEXT) /* ------------------------------------------------------- */ /* The actual test */ /* ------------------------------------------------------- */ IF COND(&TEXT *NE 'HELLO') THEN(DO) DMPCLPGM SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('The text was not the same, see dump') MSGTYPE(*ESCAPE) GOTO CMDLBL(ENDPGM) Unexpected errors where found /* ---------------------------------------------------------------- */ /* Errors in the program */ /* ---------------------------------------------------------------- */ ERROR: CALL PGM(IUNIT/@LOG) MONMSG MSGID(CPF0000) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('An unexpected error occured') MSGTYPE(*ESCAPE) Leave gracefully /* ---------------------------------------------------------------- */ /* Exit */ /* ---------------------------------------------------------------- */ ENDPGM: SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Test TESTTEST says hello') TOPGMQ(*SAME) CALL PGM(IUNIT/@LOG) MONMSG MSGID(CPF0000) ENDPGM