Troubleshooting
Problem
This document provides an example of using RCVMSG in a CL program.
Resolving The Problem
The following is an example of using RCVMSG in a CL program.
The logic in the CL is to send two messages to the job message queue. Then the CL will retrieve the message ID and perform the desired flow.
Both messages are just intended to demo the use of RCVMSG and not of any consequence in this sample.
Message ID . . . . . . . . . : CPF2103 Library &1 already exists in library list.
Message ID . . . . . . . . . : CPF9898 TEST RCVMSG in CL
When this program is called it will examine the last message on the job message queue. That message will be CPF9898.
The CL will run cmd WRKSPLF. When user exits the WRKSPLF panel with F3 the CL will loop back to check the previous message in the job message queue.
The message will be CPF2103 and the CL will run DSPLIBL. When user uses F3 to exit the DSPLIBL panel the CL then ends.
This image shows the messages during a run of the CL
This image shows the messages during a run of the CL

PGM
DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&VAR1) TYPE(*CHAR) LEN(4)
DCL VAR(&VAR2) TYPE(*CHAR) LEN(7)
DCL VAR(&TEST) TYPE(*CHAR) LEN(18) VALUE('TEST RCVMSG in CL')
SNDPGMMSG MSGID(CPF2103) MSGF(QSYS/QCPFMSG) TOMSGQ(QUSRSYS/BIMBRA) MSGTYPE(*INFO)
SNDPGMMSG MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA(&TEST) TOMSGQ(QUSRSYS/BIMBRA) +
MSGTYPE(*INFO)
RCVMSG MSGQ(QUSRSYS/BIMBRA) MSGTYPE(*LAST) RMV(*NO) KEYVAR(&MSGKEY) MSGID(&MSGID)
LOOP: IF COND(&MSGID *EQ 'CPF2103') THEN(DO)
CHGVAR VAR(&VAR1) VALUE(&MSGKEY)
CHGVAR VAR(&VAR2) VALUE(&MSGID)
DSPLIBL
GOTO END
ENDDO
ELSE IF (&MSGID *NE 'CPF2103') THEN(DO)
CHGVAR VAR(&VAR1) VALUE(&MSGKEY)
CHGVAR VAR(&VAR2) VALUE(&MSGID)
RCVMSG MSGQ(QUSRSYS/BIMBRA) MSGTYPE(*PRV) MSGKEY(&MSGKEY) RMV(*NO) +
KEYVAR(&VAR1) MSGID(&MSGID)
WRKSPLF
GOTO LOOP
ENDDO
END: ENDPGM
Sample program interaction:
> call rcvmsg1
106 - SNDPGMMSG MSGID(CPF2103) MSGF(QSYS/QCPFMSG)
TOMSGQ(QUSRSYS/BIMBRA) MSGTYPE(*INFO)
107 - SNDPGMMSG MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA('TEST RCVMSG
in CL') TOMSGQ(QUSRSYS/BIMBRA) MSGTYPE(*INFO)
109 - RCVMSG MSGQ(QUSRSYS/BIMBRA) MSGTYPE(*LAST) RMV(*NO)
KEYVAR(&MSGKEY) MSGID(&MSGID)
120 - RCVMSG MSGQ(QUSRSYS/BIMBRA) MSGTYPE(*PRV) MSGKEY(X'00000200')
RMV(*NO) KEYVAR(&VAR1) MSGID(&MSGID)
123 - WRKSPLF
114 - DSPLIBL
- RETURN /* RETURN due to end of CL program */
106 - SNDPGMMSG MSGID(CPF2103) MSGF(QSYS/QCPFMSG)
TOMSGQ(QUSRSYS/BIMBRA) MSGTYPE(*INFO)
107 - SNDPGMMSG MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA('TEST RCVMSG
in CL') TOMSGQ(QUSRSYS/BIMBRA) MSGTYPE(*INFO)
109 - RCVMSG MSGQ(QUSRSYS/BIMBRA) MSGTYPE(*LAST) RMV(*NO)
KEYVAR(&MSGKEY) MSGID(&MSGID)
120 - RCVMSG MSGQ(QUSRSYS/BIMBRA) MSGTYPE(*PRV) MSGKEY(X'00000200')
RMV(*NO) KEYVAR(&VAR1) MSGID(&MSGID)
123 - WRKSPLF
114 - DSPLIBL
- RETURN /* RETURN due to end of CL program */
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p0000006x8GAAQ","label":"CL"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
410470298
Was this topic helpful?
Document Information
More support for:
IBM i
Component:
CL
Software version:
All Versions
Operating system(s):
IBM i
Document number:
637619
Modified date:
14 March 2025
UID
nas8N1015031
Manage My Notification Subscriptions