15 pts.
 monitoring message
what is the difference between program level & command level monmsg

Software/Hardware used:
ASKED: January 29, 2010  6:51 PM
UPDATED: February 1, 2010  4:58 PM

Answer Wiki:
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). Tom
Last Wiki Answer Submitted:  January 30, 2010  11:13 am  by  Whatis23   5,665 pts.
All Answer Wiki Contributors:  Whatis23   5,665 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

I think we did your homework

 44,150 pts.

 

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')                                 
ERROR1:      RCVMSG     MSGID(&MSGID) MSGDTA(&MSGDTA) MSGTYPE(*DIAG)             
             IF         COND(&MSGID *EQ '       ') THEN(GOTO +                   
                          CMDLBL(ESCAPE))                                        
             SNDPGMMSG  MSGID(&MSGID) MSGDTA(&MSGDTA) +                          
                            MSGF(QCPFMSG) MSGTYPE(*DIAG)                         
             GOTO       CMDLBL(ERROR1) /* Loop back for addl diags */            
ESCAPE:      RCVMSG     MSGID(&MSGID) MSGDTA(&MSGDTA) +                          
                            MSGTYPE(*EXCP)                                       
             SNDPGMMSG  MSGID(&MSGID) MSGDTA(&MSGDTA) +                          
                            MSGF(QCPFMSG) MSGTYPE(*ESCAPE)                       
 EOJ:        ENDPGM                                                              
 5,525 pts.