ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Can we have an error subroutine in CL?

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

  • Can we have an error subroutine in CL?

    Hi everyone, I am facing an issue with error capturing in CL

    I understood that it is not possible to execute a subroutine inside a Monmsg like this

    MONMSG MSGID(CPF0000) EXEC(CALLSUBR SUBR(ERRORSR))

    But I need to capture all the errors that are thrown by the CL program into a file. I wrote an error subroutine inside CL like this


    SUBR SUBR(ERRORSR)
    RCVMSG PGMQ(*SAME) MSGQ(*PGMQ) MSGTYPE(*DIAG) +
    WAIT(3) RMV(*NO) MSG(&MSG) +
    MSGDTA(&MSGDATA) MSGDTALEN(&MSGLEN) +
    MSGID(&MSGID)
    CHGVAR VAR(&SQLSTMT) VALUE('INSERT INTO +
    QTEMP.ERRFILE VALUES(' || ''''|| +
    &MSGID||' '|| &MSG || ''''||')' )

    RUNSQL SQL(&SQLSTMT) COMMIT(*NONE) NAMING(*SQL)
    CALL PGM(RPTERROR)
    ENDSUBR

    If a command throw an error, I want to execute this error subroutine and continue the execution . Please let me know how to achieve this since writing subroutine inside monmsg is not an option. ​

  • #2
    I haven't tryed it but is it possible to code it like this:
    Code:
    monmsg cpf0000 exec(do)
    MONMSG MSGID(CPF0000) EXEC(DO)
         CALLSUBR SUBR(ERRORSR)
    ENDDO

    Comment


    • #3
      nishar, assuming you want to continue processing after you get an error, you can add the MONMSG after every command.

      Code:
      SOMECMD ...
      MONMSG MSGID(CPF0000) EXEC(CALLSUBR SUBR(ERRORSR))
      
      OTHERCMD ...
      MONMSG MSGID(CPF0000) EXEC(CALLSUBR SUBR(ERRORSR))​
      The rule about EXSR for MONMSG only applies to a MONMSG at the beginning of the program.

      BUT ... to me it seems like a very bad idea to continue processing after an error.

      Comment

      Working...
      X