monmsg in cl
DESCRIPTION
MONMSG'S IN CLTRANSCRIPT
MONITORING MESSAGES
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 MessageStatus 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 levelHere 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.
FROM THE DESK OF N.K. ELURUPage 1
MONITORING MESSAGES
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)
FROM THE DESK OF N.K. ELURUPage 2
MONITORING MESSAGES
FROM THE DESK OF N.K. ELURUPage 3
MONITORING MESSAGES
MONMSG / Difference between cpf0000 and cpf9999 in as400
Before we go for the difference between CPF0000 and CPF9999, we need to understand how the
MONMSG works.
First, 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)
But now suppose we have given the generic message handling MONMSG command as above, but
the program generates a message that is not in this generic list of messages then that will not be
handled.
That unhandled message is converted into CPF9999 by our system automatically.
FROM THE DESK OF N.K. ELURUPage 4
MONITORING MESSAGES
Hence, all the unhandled messages are converted to CPF9999, which actually is being handled by
our generic MOMSG command.
Example
Suppose there is any program which needs parameter value (file name) to be passed, but actually we
are not passing the value in this case. In the program when we try to delete the file then what we
get an error CPD0071.
Hence, here this unhandled exception is converted to CPF9999 and then it is handled via
CPF0000(GENERIC MSG HANDLER).
FROM THE DESK OF N.K. ELURUPage 5