Author |
Message
|
Nigel24 |
Posted: Wed Oct 11, 2006 3:21 am Post subject: MQPUT not "PUT"ting the requested string onto the |
|
|
Newbie
Joined: 11 Oct 2006 Posts: 4
|
I have a simple program that Connects, Opens, Puts a string ("Hello!"), Closes and Disconnects to a simple local queue. The message turns up on the requested queue as expected, but the problem is it doesn't read "Hello!".
The program segment (running on an AS/400 in RPG, but simple to follow) is as follows:
Code: |
Eval W_Hello = 'Hello!'
Eval W_BufferPtr = %addr(W_Hello)
Eval W_Test = %str(W_BufferPtr : 6)
CallP MQPut (W_ConnHandle : W_ObjHandle : DS_MQMD : DS_MQPMO : 6 : W_BufferPtr : W_CompCode : W_Reason) |
The third line is simply testing that the memory locations addressed by the pointer, W_BufferPtr, that is passed to the MQPUT API to tell it what data to send. A breakpoint on the "CallP MQPUT" shows both W_Hello and W_Test to hold "Hello!".
The API is clearly understanding the '6', because it sends 6 characters or data to the queue. If I change this, it duly sends the correct number of bytes. But it just refuses to send the data addressed by W_BufferPtr.
Code: |
Work with MQ Messages
Queue Manager Name . . : TEST.MANAGER
Queue name . . . . . . . NIGEL
Type options, press Enter.
4=Delete 5=Display Description 8=Display Data
GMT GMT
Opt Date Time Type UserId Format Size
20061011 10460240 DATAGRAM LDNSUPND TESTSTUF 6 |
Code: |
Display MQ Message Data
Queue Manager Name . . : TEST.MANAGER
Queue name . . . . . . : NIGEL
Date (GMT) . : 20061011 Type . . . . : DATAGRAM
Time (GMT) . : 10460240 Format . . . : TRADE
Userid . . . : LDNSUPND
Offset Hexadecimal Text
0000 80000000 0000 <...... > |
Any ideas? It's driving me mad!  |
|
Back to top |
|
 |
Vitor |
Posted: Wed Oct 11, 2006 3:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Disclaimer - I know slightly more about the dark side of the Moon than I do about AS/400 or RPG.
Accepting that, how is the MQMD being set up? I notice the Format is shown as "TRADE" - I would have expected MQ_STR or something that indicates string data. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Oct 11, 2006 3:48 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Can you check the Put sample program (AMQ3PUT4 in QMQMSAMP) to see how it's passing in the Buffer?
You might be passing in a pointer when you don't need to. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Oct 11, 2006 3:59 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Are you sure you want to have TESTSTUF as format?
Have you defined an additional header?
Look up the different predefined formats and the litteral values to be populated... and their differential behavior... I would have thought you wanted to use MQSTR here....
Possibly just another CCSID conversion issue?
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Nigel24 |
Posted: Wed Oct 11, 2006 4:06 am Post subject: |
|
|
Newbie
Joined: 11 Oct 2006 Posts: 4
|
RPG is very similar to C or JAVA, but with out any OO. An AS/400 is just the same as any other box nowadays - it just tends to be a helluva lot faster and reliable!
MQMD looks like this:
(The MDxxxx is the field name definition, the next number is the FROM position, the next number is the TO position, an "I" after this dictates an "I"nteger, the next value being the number of decimal places for numerics, and "Inz" means initialise to the value in braces. If nothing appears in braces, it means zero for numerics, blanks for alphanumeric):
Code: |
* Structure identifier
D MDSID 1 4 INZ('MD ')
* Structure version number
D MDVER 5 8I 0 INZ(1)
* Options for report messages
D MDREP 9 12I 0 INZ(0)
* Message type
D MDMT 13 16I 0 INZ(8)
* Message lifetime
D MDEXP 17 20I 0 INZ(-1)
* Feedback or reason code
D MDFB 21 24I 0 INZ(0)
* Numeric encoding of message data
D MDENC 25 28I 0 INZ(273)
* Character set identifier of message data
D MDCSI 29 32I 0 INZ(0)
* Format name of message data
D MDFMT 33 40 INZ('FMSTR ')
* Message priority
D MDPRI 41 44I 0 INZ(-1)
* Message persistence
D MDPER 45 48I 0 INZ(2)
* Message identifier
D MDMID 49 72 INZ(X'000000000000000000000000000000000000000000000000')
* Correlation identifier
D MDCID 73 96 INZ(X'000000000000000000000000000000000000000000000000')
* Backout counter
D MDBOC 97 100I 0 INZ(0)
* Name of reply queue
D MDRQ 101 148 INZ
* Name of reply queue manager
D MDRM 149 196 INZ
* User identifier
D MDUID 197 208 INZ
* Accounting token
D MDACC 209 240 INZ(X'0000000000000000000000000000000000000000000000000000000000000000')
* Application data relating to identity
D MDAID 241 272 INZ
* Type of application that put the message
D MDPAT 273 276I 0 INZ(0)
* Name of application that put the message
D MDPAN 277 304 INZ
* Date when message was put
D MDPD 305 312 INZ
* Time when message was put
D MDPT 313 320 INZ
* Application data relating to origin
D MDAOD 321 324 INZ
* Group identifier
D MDGID 325 348 INZ(X'000000000000000000000000000000000000000000000000')
* Sequence number of logical message within group
D MDSEQ 349 352I 0 INZ(1)
* Offset of data in physical message from start of logical message
D MDOFF 353 356I 0 INZ(0)
* Message flags
D MDMFL 357 360I 0 INZ(0)
* Length of original message
D MDOLN 361 364I 0 INZ(-1) |
MDMT is initialised as 8 (DataGram) - I guess that means a string of data.
I've put MDFMT back to "FMSTR " which it was originally, but this made no difference, except of course to show the duff data to be of a different format:
Code: |
Work with MQ Messages
Queue Manager Name . . : TEST.MANAGER
Queue name . . . . . . . NIGEL
Type options, press Enter.
4=Delete 5=Display Description 8=Display Data
GMT GMT
Opt Date Time Type UserId Format Size
20061011 11594336 DATAGRAM LDNSUPND FMSTR 6 |
|
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Oct 11, 2006 4:14 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Nigel24 wrote: |
RPG is very similar to C or JAVA, but with out any OO. |
So... like C then?
Nigel24 wrote: |
An AS/400 is just the same as any other box nowadays - it just tends to be a helluva lot faster and reliable!  |
The z folks might disagree with that...
Nigel24 wrote: |
MDMT is initialised as 8 (DataGram) - I guess that means a string of data.
I've put MDFMT back to "FMSTR " which it was originally, but this made no difference, except of course to show the duff data to be of a different format: |
I was reasonably sure that it wasn't the problem. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Nigel24 |
Posted: Wed Oct 11, 2006 4:16 am Post subject: |
|
|
Newbie
Joined: 11 Oct 2006 Posts: 4
|
Sample AMQ3PUT4 does the following:
Code: |
** message buffer
D BUFFER S 60A
* Buffer length
D BUFLEN S 10I 0
* Buffer pointer
D BUFPTR S * INZ (%ADDR(BUFFER)) |
Code: |
C CALLP MQOPEN(HCONN : MQOD : OPTS : HOBJ : OCODE : REASON)
*
* report reason, if any; stop if failed
C REASON IFNE RCNONE
** "MQOPEN ended with reason code ...."
C MOVEL 'MQOPEN' CNAME 6
C MOVE REASON RCODE 10
C EXCEPT MQCALL
C ENDIF
*
C OCODE IFEQ CCFAIL
** "unable to open queue for output"
C EXCEPT MESS
C ENDIF
*
** initial loop condition is based on result of MQOPEN
** set initial index to data
C Z-ADD 1 I 5 0
* length of each message buffer
C Z-ADD 60 BUFLEN
*
* Start loop to put messages . . .
C CCODE DOWNE CCFAIL
* read next line (from test data)
C I IFLT 4
C MOVEL DATA(I) BUFFER
C ADD 1 I
*
C** . . . put each buffer to message queue
C MOVEL FMSTR MDFMT
C CALLP MQPUT(HCONN : HOBJ : MQMD : MQPMO : BUFLEN : BUFPTR : CCODE : REASON) |
"DATA" array
Code: |
This is the first message added to the queue.
This is the second message.
This is the final message. |
so it's just using the defaults which I listed on my previous post above. The only difference is that I've set MDFMT to "FMSTR" on the initialise, whereas the sample program does it immediately before the Call. I've tried it both ways though, but it made no difference. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Oct 11, 2006 4:43 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Nigel24 wrote: |
Sample AMQ3PUT4 does the following:
Code: |
D BUFPTR S * INZ (%ADDR(BUFFER)) |
|
Nigel24 wrote: |
Code: |
Eval W_BufferPtr = %addr(W_Hello) |
|
These look different to me. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Nigel24 |
Posted: Wed Oct 11, 2006 4:45 am Post subject: |
|
|
Newbie
Joined: 11 Oct 2006 Posts: 4
|
To close this one off - I've got a workaround that points to a corrupt API.
Whilst this doesn't work:
Code: |
Eval W_Hello = 'Hello!'
Eval W_HelloPtr = %addr(W_Hello)
CallP MQPut (W_ConnHandle : W_ObjHandle : DS_MQMD : DS_MQPMO : 6 : W_HelloPtr : W_CompCode : W_Reason) |
This does: (The IBM manual points out that the API will equally happily accept a text string, array or pointer):
Code: |
Eval W_Hello = 'Hello!'
CallP MQPut (W_ConnHandle : W_ObjHandle : DS_MQMD : DS_MQPMO : 6 : W_Hello : W_CompCode : W_Reason) |
|
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Oct 11, 2006 4:49 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I don't think you were creating your pointer correctly - but I'm not an RPG programmer.
From my occasional bouts of C programming, though, your RESULTS look like you were passing in a pointer that was being interpreted as a value directly, rather than being de-referenced.
Which is why I don't think you were creating your pointer correctly. And the sample program calls that INZ function on the %addr result, whereas you just captured the %addr result. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
kevinf2349 |
Posted: Wed Oct 11, 2006 8:15 am Post subject: |
|
|
 Grand Master
Joined: 28 Feb 2003 Posts: 1311 Location: USA
|
Quote: |
Whilst this doesn't work:
Code:
Eval W_Hello = 'Hello!'
Eval W_HelloPtr = %addr(W_Hello)
CallP MQPut (W_ConnHandle : W_ObjHandle : DS_MQMD : DS_MQPMO : 6 : W_HelloPtr : W_CompCode : W_Reason)
|
Which I wouldn't expect to work because the W_HelloPtr should be the buffer containing the data, not the address of the buffer
From the APR
Quote: |
Buffer (MQBYTE×BufferLength) - input
Message data.
This is a buffer containing the application data to be sent. |
Why do you think it is a corrupt API? |
|
Back to top |
|
 |
|