AS/400 CLLE

450 pts.
Tags:
AS 400
CL Program
CLLE
What is MONMSG in CL program? And why do we use this? I am not able to understand this concept?

Answer Wiki

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

MONMSG is used to monitor for program errors. There are some error that we know may be ok and we still want the program to proceed.  Other wise the program would halt and processing stops until it is answered or corrected. 

You may use something like this.
MONMSG     MSGID(CPF2105)  /*DOES NOT EXIST*/

If the error would have been triggered, you said ok I know this error could occur and let the program continue.


Discuss This Question: 12  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.
  • Splat
    As the text indicates, MONMSG is used for to monitor for messages and, optionally, responding to said messages with a set of actions.
    12,630 pointsBadges:
    report
  • vivekntt21
    If we are not giving MONMSG then what happens?
    450 pointsBadges:
    report
  • azohawk

    Depending on the severity of the error and the command, the program may continue (unlikely), or show as MSGW.  If this is an interactive job, the user will see an error messege with options that may include (C-cancel job, R-retry command in error, D-dump the program values, I-ignore the error and continue. If this is a batch job, you will see this either in working with active jobs or qsysopr messege queue as a MSGW status.

    Get a good CL programming book and it will give you examples of how to identify potential error codes and how to program fro them.  

    Personally, I look at the general lack of using MONMSG or the frequent trap for CPF0000 to be lazy. I know we all have a huge list of other tasks that need to be done yesterday, but why create more work later by not properly coding from the start. If you need to create a work file for a program, you do a MONMSG that will be generated if the file already exists-then what do you want to do. Delete the existing one and re-create? Add a member to it? Something else? What if the file fails to create? There are codes to monitor for and it is your job as a good programmer to know what needs to be done in that particular case.

    3,685 pointsBadges:
    report
  • GregManzo
    I agree with azohawk. We call ourselves professionals but there are far too many lazy programmers out there, and it's a false economy anyway - it would have been quicker to stop the problem from happening. If builders built buildings the way programmers write programs, the first woodpecker along would destroy civilisation.
    2,805 pointsBadges:
    report
  • Subhendu Sen
    Assuming you are in a learning process. Better you can follow your study materials to get answer. It is so easy to earn knowledge. However you can link here from IBM for your concepts: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_61/cl/monmsg.htm
    116,460 pointsBadges:
    report
  • ToddN2000
    The only time I use the CPF0000 catch all is for a few custom applications that are not day to day production. Things like a clean up procedure where you read a file of user profiles with RCVF and then use that data to run a few commands like WRKSPLF or DSPOBJD where there may or may not be data for a specific user. I don't want to have the program hang for any reason so if it errors it just moves on.
    111,200 pointsBadges:
    report
  • Splat
    I always use the CPF0000, MCH0000, RPG0000 catch-all, tied in with a dmpclpgm in the event of unanticipated error.  

    If a process fails I want to know why & I don't want an integral step skipped.
    12,630 pointsBadges:
    report
  • azohawk
    Splat, I was refering to the naked monmsg cpf0000 that I see after commands.
    3,685 pointsBadges:
    report
  • Splat
    Azohawk, that's how I read both your comment and ToddN2000's but I wasn't seeing any case made for general global monitoring so I tossed in my two cents worth.
    12,630 pointsBadges:
    report
  • TheRealRaven
    There are circumstances when "naked CPF0000" is useful, meaningful and probably the best choice. E.g., I've needed to code naked CPF0000s on practically every command in a program because errors/problems above could not be allowed to interfere with subsequent commands.In some cases such as deleting a daily QTEMP workfile, a DLTF with CPF0000 might be sufficient.

    OTOH, using CPF0000 in normal CL programming just to avoid handling actual errors is indeed a practice that doesn't belong in production code. A CPF0000 can be trapped, but then the joblog should be processed (by the error handling code) to locate and report the underlying error properly.
    27,660 pointsBadges:
    report
  • ToddN2000
    Over use of the CPF0000 is one way it made some programmers lazy. If you have consistent enough problems in your application / program that you find you are using this all the time, then it's time to fix the error that is causing it or add another level of checking before the program proceeds. I have seen this use when copying records to a file. If the file is full, you would get a CPF message halt. If you MONMSG and ignore the message it would increase the file by the parameters set in the file description. The downside is if you had a real problem or it was in a loop you could conceivably keep copying into the file and expanding it until you ran out of disk and started to get those potentially critical storage level messages.
    111,200 pointsBadges:
    report
  • WoodEngineer
    Perhaps this example will help.  It is a common use of MONMSG in CL programs at our shop:

    ADDLIBLE mylib
    MONMSG CPF2103  /* mylib is already in lib list */

    Since the library is already in the library list we do not need to take any action when this particular ADDLIBLE does not complete successfully.
    8,100 pointsBadges:
    report

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.

Following

Share this item with your network: