Ü RCVMSG

 

·         This command is used to retrieve the message from the message queue.

·         The format of this command is:

RCVMSG     PGMQ(Program message queue)
           MSGQ(message queue name)
           MSGTYPE(message type)
           MSGKEY(message key)
           WAIT(wait time)
           RMV(remove message option)
           KEYVAR(message key received)
           MSG(msg text received)
           MSGLEN(length of the received message)
           MSGDTA(message data received)
           MSGDTALEN(message data length)
           MSGID(ID of the received message)
           SEV(severity of the message)
           SENDER(sender of the message received)
           RTNTYPE(return type of the message)
           MSGF(message file name)
           MSGLIB(message file used)

 

·         This command is quite useful when we want the track of all the important messages that are sent during the program execution. We can keep track of the status of the program and can know the reason of the program ending abnormally. Whenever any program ends abnormally, before that it sends escape message to the previous program’s message queue. Before escape messages are sent, many diagnostic messages are also sent the program that can give us the important information of the possible reason that could be behind ending the program. *DIAG message are needed to get the actual reason as the information provided by the *EXCP message may not be sufficient e.g. the *EXCP message may be “Error occurred while processing”.

·         TOPGMQ is used to send the message to the caller level in the call stack. It’s value can be *SAME, *PRV, *EXT.

·         MSGTYPE can be *INFO, *INQ, *RQS, *COMP, *DIAG, *NOTIFY, *ESCAPE or *STATUS. Other than this the message type can be *FIRST,*NEXT,*PREV which we can use to read the message back and forth from the message queue. For *NEXT, *PREV we need MSGKEY value also based on which only the message will be read back and forth.

·         MSGKEY (Message key) is needed for random access of the messages. The message key CL variable that we define in MSGKEY(&msgkey) will contain the key value. We can retrieve the message key with KEYVAR and can then use it with MSGKEY.

·         KEYVAR is used to store the message key of the message received. Whenever the message comes into the message queue, a unique message key is assigned to it. We can get this key in a variable that we have in KEYVAR. We can then use the message type *PREV, *NEXT to access previous and next messages.

·         WAIT by default contains value 0, which means that the RCVMSG command doesn’t wait for any new message to arrive in the message queue. If the message is not available in the message queue, then it proceeds to the next statement. But I few mention some value as WAIT parameter, e.g. WAIT (100) then the program wait for 100 sec before moving to the next statement.

·         RMV parameter if mentioned as RMV(*YES), then the message is cleared after being read from the message queue.

·         MSG returns the first level message of the message received.

·         SEV returns the severity of the message.

·         SENDER contains data structure information about the sender of the message.

01-10: Job name of the sender
11-20: User name of the sender
21-26: Job number
27-38: Program name that sent the message.

From this data structure we can get other detail information also related to the sender e.g. the statement number etc.

·         RTNTYPE stores the return type code.

RTNTYPE CODE             MEANING
01                       Completion message
02                       Diagnostic message
04                       Information message
05                       Inquiry message

 

 

Example

 


Columns . . . :    1  80                  Browse                    AMITCCCCC/QRPGLESRC
 SEU==>                                                                      READFILEO2
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+...
        *************** Beginning of data *********************************************
0001.00 PGM
0002.00              DCL        VAR(&VAR1) TYPE(*CHAR) LEN(20)
0003.00              DCL        VAR(&REPLY) TYPE(*CHAR) LEN(1) +
0004.00                           VALUE('N')
0005.00              DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
0006.00              DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)
0007.00              DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
0008.00              DCL        VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
0009.00              DCL        VAR(&RTNTYPE) TYPE(*CHAR) LEN(2)
0010.00              DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(100)
0011.00              DCLF       FILE(AMIT/CUST)
0012.00              MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(END1))
0013.00 READ:
0014.00              OVRDBF     FILE(CUST) TOFILE(AMIT/CUST) POSITION(*RRN 23)
0015.00              OPNDBF     FILE(AMIT/CUST) OPTION(*INP) OPNID(ID1)
0016.00              MONMSG     MSGID(CPF4174) EXEC(GOTO CMDLBL(CONTINUE))
0017.00 CONTINUE:
0018.00              RCVF
0019.00  DSP:
0020.00              CHGVAR     VAR(&VAR1) VALUE(&CSNBR||'       '|| +
0021.00                         &CSNAME||'      '||+
0022.00                         ' ')
0023.00              SNDUSRMSG  MSG('DO U WANT TO CONTINUE FILE READING') +
0024.00                           MSGRPY(&REPLY)  VALUES('Y' 'N')
0025.00
0026.00              IF   (&REPLY='Y') DO
0027.00              SNDUSRMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&VAR1) +
0028.00                           MSGTYPE(*INFO)
0029.00              GOTO       CMDLBL(READ)
0030.00              ENDDO
0031.00              ELSE  DO
0032.00              GOTO       CMDLBL(END2)
0033.00              ENDDO
0034.00 END1:
0035.00              RCVMSG     MSGTYPE(*EXCP) RMV(*NO) KEYVAR(&MSGKEY) +
0036.00                           MSGID(&MSGID) MSGF(&MSGF) +
0037.00                           SNDMSGFLIB(&MSGFLIB)
0038.00              SNDUSRMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
0039.00                           MSGTYPE(*INFO)
0040.00        /*DON'T CLEAR THE MSG FROM MSG QUEUE ELSE U CAN'T GO PREV/NEXT*/
0041.00 DIAG:
0042.00              RCVMSG     MSGTYPE(*PRV) MSGKEY(&MSGKEY)   +
0043.00                           MSGDTA(&MSGDTA) MSGID(&MSGID) +
0044.00                           RTNTYPE(&RTNTYPE) MSGF(&MSGF) +
0045.00                           SNDMSGFLIB(&MSGFLIB)
0046.00              IF         COND(&RTNTYPE = '01') THEN(DO)
0047.00              SNDUSRMSG  MSG('BELOW IS COMPLETION MESSAGE') +
0048.00                           MSGTYPE(*INFO)
0049.00              SNDUSRMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
0050.00                           MSGTYPE(*INFO)
0051.00                         ENDDO
0052.00              ELSE
0053.00              IF         COND(&RTNTYPE = '02') THEN(DO)
0054.00              SNDUSRMSG  MSG('BELOW IS DIAGNOSTIC MESSAGE') +
0055.00                           MSGTYPE(*INFO)
0056.00              SNDUSRMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
0057.00                           MSGTYPE(*INFO)
0058.00                         ENDDO
0059.00              ELSE
0060.00              IF         COND(&RTNTYPE = '04') THEN(DO)
0061.00                         SNDUSRMSG  MSG('BELOW IS INFORMATION MESSAGE') +
0062.00                         MSGTYPE(*INFO)
0063.00                         SNDUSRMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
0064.00                         MSGTYPE(*INFO)
0065.00                         ENDDO
0066.00              ELSE
0067.00              IF         COND(&RTNTYPE = '15') THEN(DO)
0068.00                         SNDUSRMSG  MSG('BELOW EXCEPTION IS ALREADY HANDLED +
0069.00                                        AT RCVMSG TIME') +
0070.00                         MSGTYPE(*INFO)
0071.00                         SNDUSRMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
0072.00                         MSGTYPE(*INFO)
0073.00                         ENDDO
0074.00              ELSE
0075.00              IF         COND(&RTNTYPE = '  ') THEN(DO)
0076.00                         GOTO END2
0077.00                         ENDDO
0078.00              ELSE
0079.00                         GOTO DIAG
0080.00 END2:
0081.00              DLTOVR     FILE(CUST)
0082.00              CLOF       OPNID(ID1)
0083.00 ENDPGM
        ****************** End of data **************************************************


 

 

OUTPUT

 


                           Display Program Messages                            
                                                                               
 DO U WANT TO CONTINUE FILE READING                                            
 Y                                                                             
 000023       KWNIK.                                                            
 DO U WANT TO CONTINUE FILE READING                                            
 Y                                                                             
 000023       KWNIK.                                                            
 End of file detected for file  in .                                           
 BELOW EXCEPTION IS ALREADY HANDLED AT RCVMSG TIME                             
 OPNID() for file  already exists.                                              
 BELOW IS COMPLETION MESSAGE                                                   
 Member  file  in  opened.                                                     
 BELOW IS DIAGNOSTIC MESSAGE                                                   
 Member  file  opened with no sharing allowed.                                 
                                                                                
 Press Enter to continue.                                                      
                                                                               
                                                                               
                                                                               
 F3=Exit   F12=Cancel                               


 

 

 

 




 

 







User Comments:



Subscribe

.  


Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy