ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How can I check for error messages that occur from a user written command?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I check for error messages that occur from a user written command?

    Is there a simple method for catching escape messages that occur from
    user written commands?

    MONMSG CPF0000 doesn't seem to work in this case.

    For example: I can code a cl that blows up with an escape message, wrap a command around it, then execute that command from another cl program. MONMSG CPF0000 following execution of the command does not catch the error. The job throws an operator escape message in the original cl program, before returning to the cl that executed the command.

    There's probably a way to code the original cl program to percolate the error up, but having to put code in every cl program for something like this seems inefficient too me.

  • #2
    Re: How can I check for error messages that occur from a user written command?

    Originally posted by lawrencewolf
    I can code a cl that blows up with an escape message
    What is the message ID of the escape message your CL program sends? Does the escape message begin with something other than CPF, such as USR?

    Comment


    • #3
      Re: How can I check for error messages that occur from a user written command?

      Here's an example:

      CL1: TEST1
      Addlible XXXXXX

      CMD: TEST1 - pointing at CL TEST1
      cmd 'This always blows up'

      CL2: TEST2
      TEST1
      MONMSG CPF0000

      Now, from a command line if i 'CALL TEST2', I get error message:
      CPF2110 received by TEST1 at 100. (C D I R)

      I tested this again, and it looks like creating the command over the cl doesn't matter. I can code CL2 as:

      CALL TEST1
      MONMSG CPF0000

      and the program still throws an escape message, that the operator must respond to, in CL1.

      Comment


      • #4
        Re: How can I check for error messages that occur from a user written command?

        TEST1 needs to monitor the ADDLIBLE command and act accordingly.

        TEST1 will not automatically trap the escape message that ADDLIBLE entry is generating, just because a caller (TEST2) is monitoring it (TEST1).

        Monitoring for the error in TEST2 (the caller) does not cause TEST1 (the callee) to monitor for escape messages.

        Comment


        • #5
          Re: How can I check for error messages that occur from a user written command?

          There's probably a way to code the original cl program to percolate the error up, but having to put code in every cl program for something like this seems inefficient too me.
          That may seem inefficient, but as Ted suggests, you need to put code into each program that you want to handle errors for. Fortunately, it's not that much code. Check out this article in IT Jungle.

          Comment


          • #6
            Re: How can I check for error messages that occur from a user written command?

            Thanks, I was hoping for a simple way of percolating the error up to the calling program, similar to what I've been able to do with Python and vb in the past. I know MONMSG won't do this, as my tests determined. But, I was thinking maybe there is some other way of accomplishing this feat.

            Comment


            • #7
              Re: How can I check for error messages that occur from a user written command?

              I did a test with IBM's advanced job scheduler (WRKJOBJS), using TEST2 as the schedule job that calls TEST1 (the cl which will error out). Somehow, it's able to complete the job without operator intervention, and provide notification in the history if an error occured.

              I can even use MONMSG CPF0000 after the statement 'CALL TEST1', to condition logic for errors that occur in the TEST1 cl. When I use monmsg there, the advanced job scheduler shows normal completion in it's history for the TEST2 job after it completes, even though TEST1 cl had an error. Without the monmsg, it shows an abnormal end in the history. Either way, the job completes without operator intervention.

              Anyway, if IBM's advanced job scheduler can do this with jobs it runs, there should be a way for me to do something similar.

              Comment


              • #8
                Re: How can I check for error messages that occur from a user written command?

                Originally posted by lawrencewolf View Post
                . . IBM's advanced job scheduler . . [is] able to complete the job without operator intervention, and provide notification in the history if an error occured.
                I don't know what's happening. Maybe IBM is using a condition handler. Now I'm curious. I'll have to find some time to look into this behavior of the advanced job scheduler.

                Comment


                • #9
                  Re: How can I check for error messages that occur from a user written command?

                  I think the advanced job scheduler is using something like: CHGJOB INQMSGRPY(*DFT)

                  I did some tests, adding that statement at the top of TEST2, and I'm able to catch the error without the operator getting an escape message. My cl looks like this now:

                  TEST1:
                  ADDLIBLE XXXXX

                  TEST2:
                  CHGJOB INQMSGRPY(*DFT)
                  CALL TEST1
                  MONMSG CPF0000 EXEC(DO)
                  /* perform some action */
                  ENDDO
                  CHGJOB INQMSGRPY(*RQD)

                  When I call TEST2, the job completes normally, but the MONMSG statement is catching the error. So I can condition logic if an error occurs. When I display the job log I see:

                  Library XXXX not found.
                  CPF2110 received by TEST1 at 100. (C D I R)
                  ? C

                  The MONSG in TEST2 is getting CPF9999, which does not tell me much about the error, other than it happened. I'd like to display something like 'Library XXXX not found.' instead, but haven't determined how to get that message yet.

                  If you know a simple way to get the originating message text, let me know! I'll probably figure it out sooner or later though. I'm thinking of somehow accessing the job log to retrieve the message, but I haven't done any research on how that's accomplished yet.

                  Comment


                  • #10
                    Re: How can I check for error messages that occur from a user written command?

                    I found this site with extremely useful explanations and examples on how to retrieve messages:

                    Receive a message from a program or procedure that has ended

                    It's a bit more coding than a catchall error handler in some other languages, but it looks to me like CHGJOB INQMSGRPY(*DFT) in conjunction with MONMSG and RCVMSG, and some logic to process the retrieved messages, will accomplish what I was looking for.

                    I should be able code a job that executes any command, have control always returned to the the job that executes the command, and condition logic on errors that may occur in the called programs.

                    One reason I was looking for something like this, is because occasionally a job will not end normally, and the operator is left with a cryptic explanation of the error, and an option to essentially cancel the job. Inevitably, I get emailed a screen shot of the error, which is completely meaningless, and am asked to fix the problem. In most cases, the operator will have cancelled the job and gone on to something else, making it difficult to even know what the problem was. Training operators to cancel the job, key DSPJOBLOG, press F10, then F18, Pageup, and then interpret the error from that screen or the next, after paging down, is not a great option. Particularly, when many different individuals are responsible for running jobs.

                    Comment


                    • #11
                      Re: How can I check for error messages that occur from a user written command?

                      x
                      Last edited by lawrencewolf; October 17, 2013, 05:44 PM. Reason: duplicate post

                      Comment

                      Working...
                      X