CL Programming

Examples of Sending Messages

Example 1: The following CL procedure allows the display station user to submit a job by calling a CL program which contains this procedure instead of entering the Submit Job (SBMJOB) command. The procedure sends a completion message when the job has been submitted.

PGM
SBMJOB JOB(WKLYPAY) JOBD(USERA) RQSDTA('CALL WKLY PARM(PAY1)')
SNDPGMMSG MSG('WKLYPAY job submitted') MSGTYPE(*COMP)
ENDPGM

Example 2: The following CL procedure changes a message based on a parameter received from a program that is called from within the this procedure. The message is then sent by the CL procedure as a completion message. (The RCDCNT field is defined as characters in PGMA.)

PGM
DCL &RCDCNT TYPE(*CHAR) LEN(3)
CALL PGMA PARM(&RCDCNT)
SNDPGMMSG MSG('PGMA completed' *BCAT &RCDCNT *BCAT +
          'records processed') MSGTYPE(*COMP)
ENDPGM

Example 3: The following procedure sends a message requesting the system operator to load a special form. The Receive Message (RCVMSG) command waits for the reply. The system operator must enter at least 1 character as a reply to the inquiry message, but the procedure does not use the reply value.

PGM
DCL &MSGKEY TYPE(*CHAR) LEN(4)
SNDPGMMSG   MSG('Load special form') TOUSR(*SYSOPR) +
            KEYVAR(&MSGKEY) MSGTYPE(*INQ)
RCVMSG MSGTYPE(*RPY) MSGKEY(&MSGKEY) WAIT(120)
.
.
.
ENDPGM

The WAIT parameter must be specified on the RCVMSG command so that the procedure waits for the reply. If the WAIT parameter is not specified, the procedure continues with the instruction following the RCVMSG command, without receiving the reply. The MSGKEY parameter is used in the RCVMSG command to allow the procedure to receive the reply to a specific message. The variable &MSGKEY in the SNDPGMMSG command is returned to the procedure for use in the RCVMSG command.

Example 4: The following procedure sends a message to the system operator when it is run in batch mode or to the display station operator when it is run from a display station. The procedure accepts either an uppercase or lowercase Y or N. (The lowercase values are translated to uppercase by the translation table (TRNTBL parameter) to make program logic easier.) If the value entered is not one of these four, the operator is issued a message indicating the reply is not valid.

PGM
DCL &REPLY *CHAR LEN(1)
.
.
SNDUSRMSG MSG('Update YTD Information Y or N') VALUES(Y N) +
     MSGRPY(&REPLY)
IF (&REPLY *EQ Y)
 DO
 .
 .
 .
 ENDDO
ELSE
 DO
 .
 .
 ENDDO
 .
 .
 .
ENDPGM

Example 5: The following procedure uses the message CPF9898 to send an escape message. The text of the message is 'Procedure detected failure'. Immediate messages are not allowed as escape messages so message CPF9898 can be used with the message as message data.

   PGM
   .
   .
   .
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGTYPE(*ESCAPE)
     MSGDTA('Procedure detected failure')
   .
   .
   ENDPGM

Example 6: The following procedure allows the system operator to send a message to several display stations. When the system operator calls the program, this procedure, contained within the called program, displays a prompt which the system operator can enter the type of message to be sent and the text for the message. The procedure concatenates the date, time, and text of the message.

           PGM
           DCLF WSMSGD
           DCL &MSG TYPE(*CHAR) LEN(150)
           DCL &HOUR TYPE(*CHAR) LEN(2)
           DCL &MINUTE TYPE(*CHAR) LEN(2)
           DCL &MONTH TYPE(*CHAR) LEN(2)
           DCL &DAY TYPE(*CHAR) LEN(2)
           DCL &WORKHR TYPE(*DEC) LEN(2 0)
           SNDRCVF RCDFMT(PROMPT)
           IF &IN91 RETURN /* Request was ended  */
           RTVSYSVAL QMONTH RTNVAR(&MONTH)
           RTVSYSVAL QDAY RTNVAR(&DAY)
           RTVSYSVAL QHOUR RTNVAR(&HOUR)
           IF (&HOUR *GT '12') DO
           CHGVAR &WORKHR &HOUR
           CHGVAR &WORKHR (&WORKHR - 12)
           CHGVAR &HOUR &WORKHR /* Change from military time */
           ENDDO
           RTVSYSVAL QMINUTE RTNVAR(&MINUTE)
           CHGVAR    &MSG ('From Sys Opr ' *CAT &MONTH *CAT '/' +
                     *CAT &DAY +
                     *BCAT &HOUR *CAT ':' *CAT &MINUTE +
                     *BCAT &TEXT)
           IF (&TYPE *EQ 'B') GOTO BREAK
NORMAL:    SNDPGMMSG MSG(&MSG) TOMSGQ(WS1 WS2 WS3)
           GOTO ENDMSG
BREAK:     SNDBRKMSG MSG(&MSG) TOMSGQ(WS1 WS2 WS3)
ENDMSG:    SNDPGMMSG MSG('Message sent to display stations') +
                     MSGTYPE(*COMP)
           ENDPGM

The DDS for the display file, WSMSGD, used in this program follows:


|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A                                      DSPSIZ(24 80)
     A          R PROMPT                    TEXT('Prompt')
     A                                      BLINK
     A                                      CA03(91 'Return')
     A                                  1  2'Send Messages To Work Stations'
                                             DSPATR(HI)
     A                                  3  2'TYPE'
     A            TYPE           1   1    +2VALUES('N' 'B')
     A                                      CHECK(ME)
                                            DSPATR(MDT)
     A                                    +3'(N = No breaks  B = Break)'
     A                                  5  2'Text'
     A            TEXT         100   1    +2LOWER
     A
     A

If the system operator enters the following on the prompt:

B
 
Please sign off by 3:30 today

the following break message is sent:

From Sys Opr 10/30 02:00  Please sign off by 3:30 today


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]