ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Retrieving CPF error message (or MONMSG MSGID)

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

  • Retrieving CPF error message (or MONMSG MSGID)

    Hello,

    I have a CL program with MONMSG monitoring for CPF errors. It is an interactive program with a DSPF. I would like to retrieve the error message so I can show it to the user if an error occurs. What's the easiest way?

    I've tried using RTVMSG inside my MONMSG, but it requires me to have the MSGID. So I've tried retrieving the MSGID by using a RCVMSG, but I never seem to be able to retrieve the correct MSGID. There must be an easier way to do this, right? Is there no way to store/retrieve the MSGID that is captured by the MONMSG?

    Basically, my code is this :
    Code:
    CALL QCMDEXC PARM(&CMD 2000)
    MONMSG MSGID(CPF0000) EXEC(DO)
        RCVMSG MSGID(&MSGID)
        RTVMSG MSGID(&MSGID) MSGF(QCPFMSG) MSG(&MSG)
        CHGVAR VAR(&W2MSG) VALUE(&MSG)
        SNDRCVF RCDFMT(WIN2)
        GOTO TF1
    ENDDO
    Since I'm intercepting all CPF errors, I simply want to show what error is intercepted. The program is destined to be used only by other developers, so there is no need to remove technical jargon from the message.

    Thanks !​​

  • #2
    DDS can do it for you, using a message subfile, it will also show completion messages :

    This DSPF show a message subfile from line 21 (see SFLMSGRCD) for 3 lines (SFLPAG)
    Code:
         A                                      DSPSIZ(24 80 *DS3)
         A                                      CF03(03)
         A          R MAIN
         A            CMD         1314   B  2  4CNTFLD(73)
    
         A          R SMSG                      SFL
         A                                      SFLMSGRCD(21)
         A            KEY                       SFLMSGKEY
         A            PGMQ                      SFLPGMQ
         A          R CMSG                      SFLCTL(SMSG) OVERLAY
         A                                      SFLPAG(3)
         A                                      SFLSIZ(4)
         A                                      SFLDSP SFLDSPCTL
         A                                      SFLINZ
         A N99                                  SFLEND(*PLUS)
         A            PGMQ                      SFLPGMQ​
    This CL sets the PGMQ with the name of the PGM
    Code:
       pgm
       dclf       dspf
       chgvar     &pgmq yourpgm
     MAIN:
       SNDF       RCDFMT(MAIN)
       SNDF       RCDFMT(CMSG)
       RCVF       RCDFMT(MAIN)
       RMVMSG     CLEAR(*ALL)
       if         (&in03 = '1') then(goto endpgm)
       call       qcmdexc (&cmd 1000)
       monmsg     cpf0000
       goto       main
    
     endpgm:
       endpgm​
    Nicolas

    Comment


    • #3
      I don't see any reason to use RTVMSG... just use RCVMSG.

      You say you can't get the "right" message id... can you elaborate? How do you know which one is the "right" one? Presumably you're seeing a different message in the job log than the one you're receiving in the program? Can you provide an example so we can understand better?

      Comment


      • #4
        In case it was unclear what I suggested in my last post:


        Code:
        CALL QCMDEXC PARM(&CMD 2000)
        MONMSG MSGID(CPF0000) EXEC(DO)
          RCVMSG MSGTYPE(*EXCP) MSGID(&MSGID) MSG(&MSG)
          CHGVAR VAR(&W2MSG) VALUE(&MSG)
          SNDRCVF RCDFMT(WIN2)
          GOTO TF1
        ENDDO​
        There seems to be no need for RTVMSG here because the message is already in the prgoram queue (job log) so you can just get the data from there. No reason to get the msgid from the pgmq and then use that to get the message from a message file...

        Comment


        • #5
          Thanks for the replies. I just went with Scott Klement's suggestion. I don't know what was happening before. RCVMSG would always get a different message, which is why I posted this question. But it seems to be working fine now, with just RCVMSG. Thanks.

          Comment

          Working...
          X