Rob,
I missed a very important point.  My apologies.
When you receive the message you need a variable for MSGKEY.  The *PRV will receive the message previous to &MSGKEY.
    RCVMSG  PGMQ(*SAME (*)) MSGTYPE(*LAST) WAIT(0) RMV(*NO) +
            MSGID(&MSGID) KEYVAR(&KEYVAR) RTNTYPE(&RTNTYPE)
    CHGVAR VAR(&MSGKEY) VALUE(&KEYVAR)
    DMPCLPGM
    RCVMSG  PGMQ(*SAME (*)) MSGTYPE(*PRV) MSGKEY(&MSGKEY) WAIT(0) RMV(*NO) +
            MSGID(&MSGID) KEYVAR(&KEYVAR) RTNTYPE(&RTNTYPE)
    DMPCLPGM
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of rob@xxxxxxxxx
Sent: Wednesday, September 17, 2014 1:02 PM
To: Midrange Systems Technical Discussion
Subject: Re: CL: Identifying the 'real' message.
What I am finding out is that *PRV seems to be meaningless, or how I am using it is wrong.
    RCVMSG  PGMQ(*SAME (*)) MSGTYPE(*LAST) WAIT(0) RMV(*NO) +
            MSGID(&MSGID) KEYVAR(&KEYVAR) RTNTYPE(&RTNTYPE)
    DMPCLPGM
    RCVMSG  PGMQ(*SAME (*)) MSGTYPE(*PRV) MSGKEY(*NONE) WAIT(0) RMV(*NO) +
            MSGID(&MSGID) KEYVAR(&KEYVAR) RTNTYPE(&RTNTYPE)
    DMPCLPGM
On the first dump I have
Variable     Value           Value in Hexadecimal
              *...+....1     * . . . + . . . . 1 
&KEYVAR      '   ÷'          000003E1 
&MSGID       'CPFB414'       C3D7C6C2F4F1F4 
&RTNTYPE     '15'            F1F5 
and the second one has the same values.  If I replace the MSGKEY on the second RCVMSG with &KEYVAR then I get all blanks returned.
Now I being told that I have to shoot a message before and after any processing, irregardless of whether or not I am doing this all in the same program.  Then I have to loop through those messages.  They may come to me in any order chosen and I just have to guess what one is the one I want?
Well, um, ok.
I modified this a little bit.  I only shoot the second message if the program aborts.  And the diagnostic message I want is always the first one after the message I shot before.
SNDPGMMSG  MSG(TEST) TOPGMQ(*SAME) KEYVAR(&LOWKEY)
RMVMSG     MSGKEY(&LOWKEY)
chgatr '/barneyphil' atr(*alwsav) value(*no)
 MONMSG CPFB414 EXEC(DO) /* Object not changed */
   /* Figure out why the object was not changed.  Might not exist, or you may +
      not have authorization to it. */
SNDPGMMSG  MSG(TEST) TOPGMQ(*SAME) KEYVAR(&HIKEY)
RMVMSG     MSGKEY(&HIKEY)
/*-----------------------------------------------------------------*/
/* LOOP TO RECEIVE MESSAGES ON INACTIVE INVOCATION                 */
/*-----------------------------------------------------------------*/
CHGVAR %BIN(&MSGKEY 1 4)  (%BIN(&LOWKEY 1 4) + 1)
LOOP:
RCVMSG     PGMQ(*SAME (*)) MSGKEY(&MSGKEY) MSGID(&MSGID) RMV(*NO)
MONMSG CPF2410 EXEC(DO) /* HANDLE MSGKEY NOT FOUND                 */
  RCVMSG     MSGTYPE(*EXCP) RMV(*YES) /* REMOVE UNWANTED EXCEPTION */
  GOTO       SKIP
ENDDO
DMPCLPGM
SKIP:
CHGVAR %BIN(&MSGKEY 1 4)  (%BIN(&MSGKEY 1 4) + 1) IF (&MSGKEY *LT &HIKEY) GOTO LOOP
 EndDo
Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1 Group Dekko Dept 1600 Mail to:  2505 Dekko Drive
          Garrett, IN 46738
Ship to:  Dock 108
          6928N 400E
          Kendallville, IN 46755
http://www.dekko.com
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: 
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at 
http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.