Search code examples
ibm-midrangeclp

Unable to monitor message inside SELECT statement


I have this code which will work even if the QTEMP/FILE1 is already existing.

CRTPF FILE(QTEMP/FILE1) RCDLEN(133)
MONMSG MSGID(CPF5813)

But when I put the same code inside SELECT...ENDSELECT, then the MONMSG can't handle the existing file and will have an error due to CPF5813.

SELECT                                       
      WHEN (&A *EQ &B) THEN(DO)
          CRTPF FILE(QTEMP/FILE1) RCDLEN(133)
          MONMSG MSGID(CPF5813)
          ... other codes
      ENDDO
      OTHERWISE (DO)
          ... other codes
      ENDDO
ENDSELECT

How will I able to monitor the message inside SELECT statement?


Solution

  • Message CPF5813 is not the message to be monitored here, it is a diagnostic message. It is message CPF7302 which is raised by CRTPF and which must be monitored.

    If you want to check that CPF5813 is the diagnostic sent, you have to use RCVMSG like below :

       pgm
    
       dcl        &excpkey *char 4
       dcl        &diagid *char 7
    
       select
          when       (1 *eq 1) then(do)
             crtpf      file(qtemp/file1) rcdlen(133)
             monmsg     CPF7302 *n do
                rcvmsg     msgtype(*last) keyvar(&excpkey) rmv(*no)
                rcvmsg     msgtype(*prv) msgkey(&excpkey) rmv(*no) msgid(&diagid)
                if         (&diagid *ne cpf5813) do
                   sndpgmmsg  msgid(cpf9898) msgf(qcpfmsg) msgdta('qtemp/file1 not created for an +
                         unexpected reason: ' *cat &diagid *bcat 'see joblog for details') +
                         msgtype(*escape)
                enddo
             enddo
          enddo
          otherwise  (do)
             /* do something */
          enddo
       endselect
    
       endpgm