ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Old data in message buffer on MQGET on z/OS

Post new topic  Reply to topic
 Old data in message buffer on MQGET on z/OS « View previous topic :: View next topic » 
Author Message
Alyindar
PostPosted: Mon Jan 05, 2015 1:32 pm    Post subject: Old data in message buffer on MQGET on z/OS Reply with quote

Newbie

Joined: 13 Mar 2008
Posts: 5

I did some searching but did not see a related topic, my apologies if I missed one.

I'm working with an ISPF panel that displays a list of messages on the queue from a program written in COBOL. It strips away any extra headers and displays the first 40 characters of the message buffer. Unfortunately, if subsequent messages are shorter than the previous, the data spills into the next one. For example, I sent the following messages to a queue:
Code:
The quick red fox
jumped over the
lazy brown dog

And here's the display:
Code:
Format   Message  Message         
 Name     Length  Contents         
MQSTR          17 The quick red fox
MQSTR          15 jumped over theox
MQSTR          14 lazy brown dogeox


The impression I'm getting is that the MSGBUFFER is not being flushed between subsequent MQGETs, but this is not a problem I've had in writing batch applications. Here's snippets of code where the buffer is defined and the MQGETs occur:
Working storage:
Code:
01  W01-FORMATNAME              PIC X(8)   VALUE SPACES.
01  W01-MSGLEN                  PIC Z(7)9  VALUE SPACES.
01  W01-MSGBUFF                 PIC X(40)  VALUE SPACES.

01  W02-MSGBUFFER               PIC X(600) VALUE SPACES.
01  W02-DATALENGTH              PIC S9(09) BINARY.
01  W02-MAXMSGLENGTH            PIC 9(6) VALUE 600.

01  MQM-MESSAGE-DESCRIPTOR.
    COPY CMQMDV.
01  MQM-GET-MESSAGE-OPTIONS.
    COPY CMQGMOV.


Procedure division (first get happens outside of the loop with MQGMO-BROWSE-FIRST):
Code:
MOVE MQMD-FORMAT TO W01-FORMATNAME
MOVE W02-DATALENGTH TO W01-MSGLEN
MOVE W02-MSGBUFFER TO W01-MSGBUFF

CALL 'ISPLINK' USING ITBADD IMSG-TABLE

COMPUTE MQGMO-OPTIONS = MQGMO-BROWSE-NEXT          +
                        MQGMO-NO-WAIT              +
                        MQGMO-ACCEPT-TRUNCATED-MSG +
                        MQGMO-CONVERT              +
                        MQGMO-NO-SYNCPOINT
MOVE MQMI-NONE TO MQMD-MSGID
MOVE MQCI-NONE TO MQMD-CORRELID

CALL 'MQGET' USING W01-HCONN
                   W01-HOBJ
                   MQMD
                   MQGMO
                   W02-MAXMSGLENGTH
                   W02-MSGBUFFER
                   W02-DATALENGTH
                   W02-COMPCODE
                   W02-REASON


W01-MSGBUFF, W01-MSGLEN AND W01-FORMATNAME are VDEFINE'd to the correlating fields in the panel:
Code:
CALL 'ISPLINK' USING
       IVDEFINE IFORMATNAME   W01-FORMATNAME   ICHAR  I8.
CALL 'ISPLINK' USING
       IVDEFINE IMSGLEN       W01-MSGLEN       ICHAR  I8.
CALL 'ISPLINK' USING
       IVDEFINE IMSGBUFF      W01-MSGBUFF      ICHAR  I36.

CALL 'ISPLINK' USING ITBCREATE
                     IMSG-TABLE
                     IMSG-TABLE-KEY IMSG-TABLE-FIELDS
                     INOWRITE IREPLACE.


I can prevent the problem by adding a line "MOVE SPACES TO W02-MSGBUFFER" before the "CALL 'MQGET'" line, but I'm trying to understand why this step is necessary when I've not had these problems with batch programs (for example, the CSQ4BVJ1 sample program in SCSQCOBS). Is there something specific to the MQ-ISPF relationship that I'm missing here? Any advice is greatly appreciated!
Back to top
View user's profile Send private message
tczielke
PostPosted: Mon Jan 05, 2015 1:42 pm    Post subject: Reply with quote

Guardian

Joined: 08 Jul 2010
Posts: 939
Location: Illinois, USA

You should take into account the length of the message returned in the DATALENGTH field of the MQGET, and only print those number of bytes in your buffer. Notice that the CSQ4BVJ1 sample program that you mentioned does that with reference modification:

Code:

DISPLAY W00-LOOP, ' : ', W00-DATALENGTH, ' : ',
             W00-MSGBUFFER(1:W00-DATALENGTH)   
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon Jan 05, 2015 4:13 pm    Post subject: Re: Old data in message buffer on MQGET on z/OS Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

Alyindar wrote:

The impression I'm getting is that the MSGBUFFER is not being flushed between subsequent MQGETs, but this is not a problem I've had in writing batch applications.

You are correct in that MQ internals do NOT initialize (flush or clear) your MSGBUFFER - this is a programmer responsibility.

A best-practice is for your app to have a virgin MQMD (from COPYBOOK) that you use to initialize (clear) your working MQMD before the next MQGET. MOVE VIRGIN-MQMD TO MQM-MESSAGE-DESCRIPTOR.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
PaulClarke
PostPosted: Mon Jan 05, 2015 9:49 pm    Post subject: Reply with quote

Grand Master

Joined: 17 Nov 2005
Posts: 1002
Location: New Zealand

When MQ gives you a message it always tells you how big it is. In other words, how many of the bytes in the message buffer are relevant. It would be unnecessary and woefully inefficient if MQ initialised your message buffer (lets say set them all to zeroes or blanks) for every MQGET call. Suppose the buffer you give is 100MB long - would you really want MQ to set 100 million bytes to zero each time you retrieved a single 10 byte message?

Cheers,
Paul.
_________________
Paul Clarke
MQGem Software
www.mqgem.com
Back to top
View user's profile Send private message Visit poster's website
Alyindar
PostPosted: Thu Jan 08, 2015 7:58 am    Post subject: Reply with quote

Newbie

Joined: 13 Mar 2008
Posts: 5

I missed that in the example, thanks for point that out tczielke.

I modified my program to use reference modification and everything is working perfectly. Thanks for the explanations folks! It's good to take off the sysadmin hat and don the programmer hat once in awhile, you just might learn something!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Old data in message buffer on MQGET on z/OS
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.