monitoring message

what is the difference between program level & command level monmsg

Answer Wiki

Thanks. We'll let you know when a new response is added.

A command-level message monitor lets you monitor for specific messages that might occur during the execution of a single command.

A program-level message monitor is a MONMSG command like CPF0000 that will trap all errors in the pgm and then the user can be informed that an error has taken place using SNDPGMMSG.

The command-level MONMSG commands take precedence over the procedure-level MONMSG commands.


A program-level MONMSG is placed after the declarative statements and <i>before</i> the executable statements in the program. It applies to every executable statement in the rest of the program. The most common usage is to monitor for all exceptions that are not explicitly monitored on individual statements later. You can have multiple program-level monitors, each monitoring for different types of exceptions.

A program-level monitor can only execute a GOTO command when an exception occurs. Different program-level monitors can GOTO different labels in the program or to the same labels.

Usually a program-level monitor will watch for a generic message identifier such as CPF0000 and MCH0000 in order to catch all exceptions of those types.

A command-level MONMSG only applies to the single executable statements that it follows. Multiple command-level monitors can be placed after each executable statement.

A command level monitor can execute any other executable statement. Often, the executable statement will be a DO statement in order to run a block of statements in a DO/ENDDO group. A GOTO statement is not required.

In short, a program-level monitor applies to all statements in the program. A command-level monitor only catches messages from the single statement that it follows.

A command-level monitor will only see the messages that can be sent from the command that it follows. A program-level monitor can see all of the messages that can be sent from any statement in the program (unless a command-level monitor catches it first).


Discuss This Question: 2  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb
    I think we did your homework
    54,090 pointsBadges:
  • WoodEngineer
    Here is an example of code we use. It shows a program-level monitor. There are other more sophisticated versions but this is a good fit for our shop.
    /* CLP error handling variables & MONMSG command ------------------ */     
                 DCL        VAR(&ERRORSW)  TYPE(*LGL)                          
                 DCL        VAR(&MSGID)    TYPE(*CHAR) LEN(7)                  
                 DCL        VAR(&MSGDTA)   TYPE(*CHAR) LEN(100)                
                 MONMSG     MSGID(CPF0000) EXEC(GOTO ERROR)                    
    /* Insert CLP statements here -------------------------------------- */    
                 RETURN     /* Use this command as normal end of program */          
    /* ----------------------------------------------------------------- */          
    ERROR:       IF         COND(&ERRORSW) THEN(SNDPGMMSG MSGID(CPF9999) +           
                            MSGF(QCPFMSG) MSGTYPE(*ESCAPE)) /* Func chk */           
                 CHGVAR     VAR(&ERRORSW) VALUE('1')                                 
                 IF         COND(&MSGID *EQ '       ') THEN(GOTO +                   
                 SNDPGMMSG  MSGID(&MSGID) MSGDTA(&MSGDTA) +                          
                                MSGF(QCPFMSG) MSGTYPE(*DIAG)                         
                 GOTO       CMDLBL(ERROR1) /* Loop back for addl diags */            
    ESCAPE:      RCVMSG     MSGID(&MSGID) MSGDTA(&MSGDTA) +                          
                 SNDPGMMSG  MSGID(&MSGID) MSGDTA(&MSGDTA) +                          
                                MSGF(QCPFMSG) MSGTYPE(*ESCAPE)                       
     EOJ:        ENDPGM                                                              
    8,225 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: