I was working on a batch process that is initiated by a single command from any command line for one of our clients and wanted to devise some method of reporting back to the user that the request had been submitted for processing. The best way to accomplish this was to send the user a message from the command screen much like one receives when a program is submitted to batch for compilation.
After some research I discovered that the message I needed is CPC1221 in message file QCPFMSG. Using this information, I added the following section to the program that submits the job to batch:
DCL VAR(&MSGDTA) + TYPE(*CHAR) + LEN(46) SBMJOB CMD(...) JOB(...) RCVMSG MSGDTA(&MSGDTA) SNDPGMMSG MSGID(CPC1221) + MSGF(QCPFMSG) + MSGDTA(&MSGDTA) + TOPGMQ(*PRV) + MSGTYPE(*INFO)
The pertinent operations above are the DCL, RCVMSG, and SNDPGMMSG commands.
The declaration of correct length and type for the &MSGDTA variable was ascertained by performing the DSPMSGD command for CPC1221 in QCPFMSG and then taking option 2 to display field data. This option shows all of the variables used in a message and their respective data type, length, decimal positions, varying length and dump status as applicable.
The command RCVMSG acts much like the MONMSG command (although it does not substitute) in that you can place the command immediately after an operation to capture any message generated. In this case, I wanted to capture the job submission message so I placed the command right after the SBMJOB command. There are several items of information available through the RCVMSG command; however, in this case all I wanted to capture was the variable message data.
Once I had captured the message data from the submit, it was turned around and sent to the requesting user through the SNDPGMMSG command. Using this command you can format messages either free-form or use messages already defined in message files like QCPFMSG as I did in this case.
When you use a predefined message, there can be variable data which needs to be passed. In this case, the &MSGDTA held the five variables job number, User ID, job name, job queue, and job queue library. By placing this variable in the MSGDTA parameter of the SNDPGMMSG, the appropriate information is sent. An additional key point here is the designation of TOPGMQ. By using the *PRV designation for this parameter, the message is sent to the calling program in the invocation stack, in this case, the program, menu or other object on which the command was entered. Finally, it is important to note the use of the *INFO value for the MSGTYPE parameter. This designates the message as informational only and thus requires no user action.
Jim Johnson Murfreesboro, Tennessee
LATEST COMMENTS
MC Press Online