AN RPG EQUIVALENT OF SNDUSRMSG
Q: I use the SNDUSRMSG CL command in my batch programs in order to get
input from the system operator. Is there a way that I can do the same
thing in ILE RPG with APIs?
A: The Send User Message (SNDUSRMSG) CL command is actually a short
cut for the Send Program Message (SNDPGMMSG) command followed by the
Receive Message (RCVMSG) command.
To do the same thing as SNDUSRMSG with APIs requires you to use two
steps. First, send a message to a non-program queue. Second, receive
the reply message.
The QSYSOPR message queue is not a program queue. Confusingly, the
SNDPGMMSG CL command can messages to non-program queues like QSYSOPR,
but the Send Program Message (QMHSNDPM) API can't. To send messages to
non-program message queues such as QSYSOPR, users' messages queues, or
workstation message queues, you have to use the Send Non-program
Message (QMHSNDM) API.
The following ILE RPG program sends an inquiry message to the QSYSOPR
message queue. It tells the API that it wants the message reply to go
to its own program message queue and then uses the Receive Program
Message (QMHRCVPM) API to wait for the reply on its program message
queue.
Q: I use the SNDUSRMSG CL command in my batch programs in order to get
input from the system operator. Is there a way that I can do the same
thing in ILE RPG with APIs?
A: The Send User Message (SNDUSRMSG) CL command is actually a short
cut for the Send Program Message (SNDPGMMSG) command followed by the
Receive Message (RCVMSG) command.
To do the same thing as SNDUSRMSG with APIs requires you to use two
steps. First, send a message to a non-program queue. Second, receive
the reply message.
The QSYSOPR message queue is not a program queue. Confusingly, the
SNDPGMMSG CL command can messages to non-program queues like QSYSOPR,
but the Send Program Message (QMHSNDPM) API can't. To send messages to
non-program message queues such as QSYSOPR, users' messages queues, or
workstation message queues, you have to use the Send Non-program
Message (QMHSNDM) API.
The following ILE RPG program sends an inquiry message to the QSYSOPR
message queue. It tells the API that it wants the message reply to go
to its own program message queue and then uses the Receive Program
Message (QMHRCVPM) API to wait for the reply on its program message
queue.
Code:
* * Demonstration of using message APIs to do the equivalent of the * SNDUSRMSG CL command in ILE RPG. * Scott Klement, July 29, 2004 * * D QMHSNDM PR ExtPgm('QMHSNDM') D MsgID 7A const D QualMsgF 20A const D MsgTxt 32767A const options(*varsize) D MsgTxtLen 10I 0 const D MsgType 10A const D MsgQueues 20A const dim(50) options(*varsize) D NumQueues 10I 0 const D RpyQueue 20A const D MsgKey 4A D ErrorCode 8000A options(*varsize) D CCSID 10I 0 const options(*nopass) D QMHRCVPM PR ExtPgm('QMHRCVPM') D MsgInfo 32767A options(*varsize) D MsgInfoLen 10I 0 const D Format 8A const D StackEntry 10A const D StackCount 10I 0 const D MsgType 10A const D MsgKey 4A const D WaitTime 10I 0 const D MsgAction 10A const D ErrorCode 8000A options(*varsize) D RCVM0100 DS qualified D BytesRtn 10I 0 D BytesAvail 10I 0 D MsgSev 10I 0 D MsgID 7A D MsgType 2A D MsgKey 4A D 7A D CCSID_status 10I 0 D CCSID 10I 0 D MsgDtaLen 10I 0 D MsgDtaAvail 10I 0 D MsgDta 8000A D ErrorCode ds qualified D BytesProv 10I 0 inz(0) D BytesAvail 10I 0 inz(0) D Message s 100A varying D MsgKey s 4A D MsgQ s 20A dim(1) inz('*SYSOPR') D Reply s 100A /free // Send an *INQ message to QSYSOPR asking for a reply. // // The message will look like the following: // // From . . . : MYUSERID 07/19/04 14:00:16 // Please Reply to this message. // Reply . . : boing // // If you want to remove the "From . . ." line from the // message display, you can do so by specifying a MsgID // and MsgFile as the first two parameters to QMHSNDM API. Message = 'Please reply to this message.'; QMHSNDM( *blanks : *blanks : Message : %len(Message) : '*INQ' : MsgQ : %elem(MsgQ) : '*PGMQ' : MsgKey : ErrorCode ); // Wait up to 1 hour (3600 seconds) for a reply to the // above message. If you change the value of 3600 below to // a value of -1, it will wait indefinitely. QMHRCVPM( RCVM0100 : %size(RCVM0100) : 'RCVM0100' : '*' : 0 : '*RPY' : MsgKey : 3600 : '*REMOVE' : ErrorCode ); Reply = %subst(RCVM0100.MsgDta: 1: RCVM0100.MsgDtaLen); // The "Reply" Variable should now contain the user's // reply. *inlr = *on; /end-free