Example: Display messages from IBM-supplied commands more than once

This example shows how to define and create a command that re-displays messages.

The Clear Output Queue (CLROUTQ) command issues the completion message CPF3417, which describes the number of entries deleted, the number not deleted, and the name of the output queue. If the Clear Output Queue (CLROUTQ) command is run within a CPP, the message is still issued but it becomes a detailed message because it is not issued directly by the CPP. For example, if a user-defined Clear Output Queue (CLROUTQ) command was issued from the Programmer Menu, the message would not be displayed. You can, however, receive an IBM® message and reissue it from your CPP.

For example, you create a command named CQ2 to clear the output queue QPRINT2.

The command definition statements for the CQ2 command are:

CMD PROMPT ('Clear QPRINT2 output queue')

The Create Command (CRTCMD) command is:

CRTCMD CMD(CQ2) PGM(CQ2)

The CPP, which receives the completion message and displays it, is as follows:

PGM /* Clear QPRINT2 output queue CPP */
DCL &MSGID TYPE(*CHAR) LEN(7)
DCL &MSGDTA TYPE(*CHAR) LEN(100)
CLROUTQ QPRINT2
RCVMSG MSGID(&MSGID) MSGDTA(&MSGDTA) MSGTYPE(*COMP)
SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) MSGTYPE(*COMP)
ENDPGM

The MSGDTA length for message CPF3417 is 28 bytes. However, by defining the variable &MSGDTA as 100 bytes, the same approach can be used on most messages because any unused positions are ignored.

Related information
Create Command (CRTCMD) command