ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Extracting Message Key from MESSAGE_QUEUE_INFO view

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

  • Extracting Message Key from MESSAGE_QUEUE_INFO view

    I am trying to use MESSAGE_QUEUE_INFO view to retrieve messages waiting for a reply in QSYSOPR in order to reply to them. I have been unable to convert the MESSAGE_KEY field from that view into usable field in my code. I keep getting a 462 error. Documentation says that that field is a binary(4) field. I would normally associate that as a integer(10). I have tried using the QMHLSTM API but the documentation indicates that the Message key is Character, however that isn't working either. Can any one point me as to the proper way to extract the field value into my code.

    Current SQL statement I am using
    Code:
    [FONT=Courier New]Select MESSAGE_QUEUE_LIBRARY, MESSAGE_QUEUE_NAME, [B]MESSAGE_KEY[/B]
    From   QSYS2.MESSAGE_QUEUE_INFO
    WHERE      MESSAGE_QUEUE_NAME    = 'QSYSOPR'
           and MESSAGE_QUEUE_LIBRARY = 'QSYS'
           and FROM_PROGRAM          = 'QCLXERR'
    
    [B]Relevant RPG Code:[/B]
    [B]    DCL-S MsgK    Char( 10);      Have tried setting this as VarChar and Integer(10)[/B]
        DCL-S MsgQ VarChar( 10);
        DCL-S MsgL VarChar( 10);
        Exec SQL Fetch next From MYCSR into :MsgL, :MsgQ, [B]:MsgK[/B];[/FONT]

  • #2
    According to this page: https://www.ibm.com/support/pages/sq...ql-views-qsys2

    462 is a warning not an error. What makes you think you have an error?

    Binary 4 may well be Unsigned Int - given that according to the QMHRCVM API the key is actually char 4! But that is not your issue as far as the 462 is concerned.

    P.S. I see from running the statement in Run Sql scripts that the key appears to be returned as a hex string which would imply Uns(10) or Char(4).
    Last edited by JonBoy; April 5, 2021, 04:28 PM. Reason: Added P.S.

    Comment


    • #3
      The message key is defined as VARBINARY(4), i.e. a varying Character Field without CCSID.
      If you do not want to get the warning, you may cast the Message-Key explicitly into VarChar(4) or CHAR(4).

      Code:
      Select ... Cast(Message_Key as VarChar(4)) ...
      Birgitta

      Comment


      • #4
        Using VarChar(4) did the trick. I was thinking I had error because I was getting Casting messages about the field when viewing the job log.

        Comment


        • #5
          Not disputing this but if it is a varbinary(4) Birgitta then why does Run Sql scripts just show it like this?
          Code:
           [TABLE]
          [TR]
          [TD]QSYS[/TD]
           			[TD]QSYSOPR[/TD]
           			[TD]000009A0[/TD]
           		[/TR]
          [TR]
          [TD]QSYS[/TD]
           			[TD]QSYSOPR[/TD]
           			[TD]00000B30[/TD]
           		[/TR]
          [TR]
          [TD]QSYS[/TD]
           			[TD]QSYSOPR[/TD]
           			[TD]00000BC0[/TD]
           		[/TR]
          [/TABLE]

          Comment


          • #6
            Originally posted by JonBoy View Post
            Not disputing this but if it is a varbinary(4) Birgitta then why does Run Sql scripts just show it like this?
            Ask the guys in Rochester why they decided to display the HEX values for Binary Data Types. ... may be because the character value is not readable.

            Comment

            Working...
            X