Ü  MONMSG

·         The monitor message (MONMSG) command monitors for the escape/status/notification messages that exist in a program at run time and allows us to take the corrective action for those messages.

·         The messages are sent to the program message queue for the conditions specified in the command. If condition exists, the CL command specified on the MONMSG command runs.

·         It doesn’t handle diagnostic messages but we can receive those messages from the message queue to get additional information related to the error.

 

Ü   Types of monitor message

ü  Escape Message

ü  Status or Notify Message

·         Escape Message

Escape message are send to tell your program of an error condition that forced the sender to end the program. By monitoring for escape message, you can take corrective actions or end your program.

·         Status or Notify Message

Status and notify message are send to tell your program of an abnormal condition that is not serious enough for sender to end. By monitoring for status or notify message, your program can detect this condition and not allow the function to continue.

 

Ü   Two levels of MONMSG command

ü  Program level

ü  Specific command level

 

·         Program level

The MONMSG is specified immediately following the last declared command in the CL program.

It will catch all the error escape messages that exist in the program and doesn’t have satisfying command level MONMSG or doesn’t have any command level MONMSG.

·         Specific command level

Here the MONMSG command immediately follows a CL command. If there is any error at a particular CL statement and it satisfies the condition specified in MONMSG, then the error is caught with this MONMSG.

e.g. Suppose there are multiple places in our program where we checking for the existence of an object. So rather than defining the MONMSG at many places, we will simply put it at program level.

 

           

Ü Monitor message command syntax   

·         MONMSG  MSGID ( )  CMPDTA ( ) EXEC ( )

 

ü  MSGID-Required

   Ex: MSGID (MCH1211)

ü  CMPDTA –(Optional)

       Ex: MONMSG MSGID (MCH1211) CMPDTA (LIB)

ü  EXEC - -(Optional)

 

We can monitor for a specific message, e.g.

    MONMSG    MSGID (CPF9821)

 

 

Or we can monitor for a list of messages, e.g.

    MONMSG    MSGID (CPF9821 CPF9822 ……  CPF9830)

 

 

Now if we want to catch all the messages that start with CPF98.., then we can go for the below MONMSG:

  MONMSG    MSGID (CPF9800)

 

Now if we want to catch all the possible generic messages for CPF…., we can use the below MONMSG:

  MONMSG    MSGID (CPF0000)

 

To have more generic message monitor, we can go for:

  MONMSG    MSGID (CPF0000 MCH0000) EXEC (GOTO ERROR)

 

 

Example


Columns . . . :    1 100                     Browse                           IROBO1/QRPGLESRC
 SEU==>                                                                              MONMSG_CL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+.
        *************** Beginning of data ****************************************************
0001.00 PGM
0002.00     DCLF       FILE(ACCOUNT) OPNID(ID1)
0003.00     DCL        VAR(&COUNT) TYPE(*DEC) LEN(2) VALUE(0)
0004.00     DCL        VAR(&CHAR) TYPE(*CHAR) LEN(3) VALUE(' ')
0005.00     DCL        VAR(&DSP) TYPE(*CHAR) LEN(35) VALUE(' ')
0006.00     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))  >>>>> Program level MONMSG
0007.00
0008.00     ADDLIBLE   IROBO1
0009.00     MONMSG     MSGID(CPF2103)   >>> This MONMSG checks if the library already exists, if it does
0010.00                                    don’t do anything, just let the program continue.
0011.00
0012.00     CHKOBJ     OBJ(*LIBL/ACCOUNT) OBJTYPE(*FILE) MBR(*FIRST)
0013.00     MONMSG     MSGID(CPF9801) EXEC(GOTO CMDLBL(ERROR))
0014.00
0015.00     /* READ THE FILE AND TAKE THE RECORD COUNT*/
0016.00     READ:
0017.00     RCVF       OPNID(ID1)
0018.00     MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
0019.00     CHGVAR     VAR(&COUNT) VALUE(&COUNT+1)
0020.00     CHGVAR     VAR(&CHAR) VALUE(&COUNT)
0021.00     GOTO       READ
0022.00
0023.00 ERROR:
0024.00              SNDPGMMSG   MSG('THERE IS SOME ERROR, CHECK THE PROGRAM')
0025.00
0026.00 END:
0027.00              CLOF       OPNID(ID1)
0028.00              MONMSG     MSGID(CPF4520)
0029.00              CHGVAR     VAR(&DSP) VALUE('TOTAL RECORD COUNT IS  ' +
0030.00                           *CAT &CHAR)
0031.00              SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&DSP)
0032.00
0033.00 ENDPGM
        ****************** End of data ****************************************************

 

 

 

OUTPUT

 


                           Work with Members Using PDM                 PUB1    
                                                                               
 File  . . . . . .   QRPGLESRC                                                 
   Library . . . .     IROBO1               Position to  . . . . .             
                                                                               
 Type options, press Enter.                                                    
  2=Edit         3=Copy  4=Delete 5=Display       6=Print     7=Rename         
  8=Display description  9=Save  13=Change text  14=Compile  15=Create module...
                                                                               
 Opt  Member      Type        Text                                             
      MONMSG_CL   CLP         MONMSG DEMOSTRATION                              
 
 
 
                                                                        More...
 Parameters or command                                                         
 ===>                                                                          
 F3=Exit          F4=Prompt             F5=Refresh            F6=Create        
 F9=Retrieve      F10=Command entry     F23=More options      F24=More keys    
 TOTAL RECORD COUNT IS  019.                                                   

 

 




 

 







User Comments:



Subscribe

.  


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