- 论坛徽章:
- 0
|
问高手,谁知道as400上的mq的例子程序
多谢老兄,这是它的源代码:
H
****************************************************************
* *
* Program name: AMQ3PUT4 *
* *
* Description: Sample ILE RPG program that puts messages to *
* a message queue (example using MQPUT) *
* *
*<START_COPYRIGHT>; *
* Licensed Materials - Property of IBM *
* *
* 5724-B41 *
* (C) Copyright IBM Corp. 1994, 2002 All Rights Reserved. *
* *
* US Government Users Restricted Rights - Use, duplication or *
* disclosure restricted by GSA ADP Schedule Contract with *
* IBM Corp. *
*<END_COPYRIGHT>; *
* *
****************************************************************
* *
* Function: *
* *
* *
* AMQ3PUT4 is a sample RPG program to put messages on a *
* message queue, and is an example of the use of MQPUT. *
* *
* -- sample input is taken from an array defined in *
* the source; the program parameter identifies *
* the target queue *
* *
* -- adds each text line in the array to the message *
* queue, taking each line of text as the content *
* of a datagram message *
* *
* -- writes a message for each MQI reason other than *
* RCNONE; stops if there is a MQI completion code *
* of CCFAIL *
* *
* Program logic: *
* MQCONN to the target queue manager *
* MQOPEN target queue for OUTPUT *
* for each line in the input array, *
* . MQPUT datagram message with text line as data *
* MQCLOSE target queue *
* MQDISC from the queue manager *
* *
****************************************************************
* *
* *
* *
* Exceptions signaled: none *
* Exceptions monitored: none *
* *
* AMQ3PUT4 has 2 parameters - (1) name of the target queue *
* (2) name of the queue manager *
* *
****************************************************************
FQSYSPRT O F 132 PRINTER
** Test data used as input
D DATA S 60 DIM(3) CTDATA PERRCD(1)
** message buffer
D BUFFER S 60A
* Handle connection
D HCONN S 10I 0
* Options
D OPTS S 10I 0
* Object handle
D HOBJ S 10I 0
* Completion codes
D OCODE S 10I 0
D CCODE S 10I 0
* Reason
D REASON S 10I 0
* Buffer length
D BUFLEN S 10I 0
* Buffer pointer
D BUFPTR S * INZ (%ADDR(BUFFER))
*
** Declare MQI structures needed
* MQI named constants
D/COPY CMQG
* Object Descriptor
D MQOD DS
D/COPY CMQODG
* Message Descriptor
D MQMD DS
D/COPY CMQMDG
* Put message options
D MQPMO DS
I/COPY CMQPMOG
** note, sample uses defaults where it can
*
* program parameters are: 48-character target queue name
* 48-character queue manager name
C *ENTRY PLIST
C PARM QNAME 48
C PARM QMNAME 48
** indicate that sample program has started
C MOVEL 'start' STATUS 5
C EXCEPT SAMPLE
*
****************************************************************
* *
* use parameter as the name of the target queue *
* *
****************************************************************
C MOVEL QNAME ODON 48
*
** say "target queue is ----"
C EXCEPT TARGET
****************************************************************
* *
* Connect to the queue manager *
* *
****************************************************************
C CALLP MQCONN(QMNAME : HCONN : OCODE : REASON)
*
* report reason and stop if it failed
C OCODE IFEQ CCFAIL
** "MQCONN ended with reason code ...."
C MOVEL 'MQCONN' CNAME 6
C MOVE REASON RCODE 10
C EXCEPT MQCALL
** "unable to connect to MQM"
C MOVE OCODE CCODE
C EXCEPT MESSC
C SETON LR
C RETURN
C ENDIF
****************************************************************
* *
* Open the target message queue for output (and fail if *
* MQM is quiescing) *
* *
* Resulting queue handle is HOBJ *
* *
****************************************************************
* options are Output and Fail-if-quiescing
C OOOUT ADD OOFIQ OPTS
* call ...
C CALLP MQOPEN(HCONN : MQOD : OPTS : HOBJ :
C 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 :
C BUFLEN : BUFPTR : CCODE : REASON)
*
** report reason, if any; stop if failed
C REASON IFNE RCNONE
** "MQPUT ended with reason code ...."
C MOVEL 'MQPUT ' CNAME
C MOVE REASON RCODE
C EXCEPT MQCALL
C ENDIF
*
*
** satisfy loop end condition after last input line
C ELSE
C Z-ADD CCFAIL CCODE
* end if (I < 4)
C ENDIF
** end DO-while loop; failure causes loop to end
C ENDDO
*
****************************************************************
* *
* Close the target queue (if it was opened) *
* *
****************************************************************
* if (OCODE not CCFAIL) ...
C OCODE IFNE CCFAIL
* ... close the queue (no options)
C Z-ADD CONONE OPTS
C CALLP MQCLOSE(HCONN : HOBJ : OPTS :
C CCODE : REASON)
*
* report reason, if any
C REASON IFNE RCNONE
** "MQCLOS ended with reason code ...."
C MOVEL 'MQCLOS' CNAME
C MOVE REASON RCODE
C EXCEPT MQCALL
C ENDIF
*
* end if (OCODE not CCFAIL)
C ENDIF
****************************************************************
* *
* Disconnect from the queue manager *
* *
****************************************************************
C CALLP MQDISC(HCONN : OCODE : REASON)
*
* report reason and stop if it failed
C OCODE IFEQ CCFAIL
** "MQDISC ended with reason code ...."
C MOVEL 'MQDISC' CNAME 6
C MOVE REASON RCODE 10
C EXCEPT MQCALL
C ENDIF
*
** "Sample AMQ1PUT4 end"
C MOVEL 'end ' STATUS 5
C EXCEPT SAMPLE
C SETON LR
****************************************************************
OQSYSPRT E SAMPLE 1
O 20 'Sample AMQ3PUT4 '
O STATUS 25
O E TARGET 1
O 20 'Target queue is '
O QNAME
O E TARGET 1
O 28 'Target queue manager is '
O QMNAME
O E MQCALL 1
O CNAME 10
O ' ended with reason code'
O RCODE 45
O E MESSC 1
O 25 'Unable to connect to'
O ' queue manager'
O E MESS 1
O 25 'Unable to open queue'
O ' for output'
****************************************************************
* *
* END OF AMQ3PUT4 *
* *
****************************************************************
****
* Sample input follows
****
**
This is the first message added to the queue.
This is the second message.
This is the final message. |
|