Opening an existing queue
This example demonstrates how to use the MQOPEN call to open an existing queue. This extract is taken from the Browse sample application (program CSQ4BVA1) supplied with WebSphere MQ for z/OS. For the names and locations of the sample applications on other platforms, see Sample programs (all platforms except z/OS).
⋮ * -------------------------------------------------------* WORKING-STORAGE SECTION. * -------------------------------------------------------* * * W01 - Fields derived from the command area input * 01 W01-OBJECT PIC X(48). * * W02 - MQM API fields * 01 W02-HCONN PIC S9(9) BINARY VALUE ZERO. 01 W02-OPTIONS PIC S9(9) BINARY. 01 W02-HOBJ PIC S9(9) BINARY. 01 W02-COMPCODE PIC S9(9) BINARY. 01 W02-REASON PIC S9(9) BINARY. * * CMQODV defines the object descriptor (MQOD) * 01 MQM-OBJECT-DESCRIPTOR. COPY CMQODV. * * CMQV contains constants (for setting or testing * field values) and return codes (for testing the * result of a call) * 01 MQM-CONSTANTS. COPY CMQV SUPPRESS. * -------------------------------------------------------* E-OPEN-QUEUE SECTION. * -------------------------------------------------------* * * * This section opens the queue * * * Initialize the Object Descriptor (MQOD) control * block * (The copy file initializes the remaining fields.) * MOVE MQOT-Q TO MQOD-OBJECTTYPE. MOVE W01-OBJECT TO MQOD-OBJECTNAME. * * Initialize W02-OPTIONS to open the queue for both * inquiring about and setting attributes * COMPUTE W02-OPTIONS = MQOO-INQUIRE + MQOO-SET.* * Open the queue * CALL 'MQOPEN' USING W02-HCONN MQOD W02-OPTIONS W02-HOBJ W02-COMPCODE W02-REASON. * * Test the output from the open * * If the completion code is not OK, display a * separate error message for each of the following * errors: * * Q-MGR-NOT-AVAILABLE - MQM is not available * CONNECTION-BROKEN - MQM is no longer connected to CICS * UNKNOWN-OBJECT-NAME - The queue does not exist * NOT-AUTHORIZED - The user is not authorized to open * the queue * * For any other error, display an error message * showing the completion and reason codes * IF W02-COMPCODE NOT = MQCC-OK EVALUATE TRUE * WHEN W02-REASON = MQRC-Q-MGR-NOT-AVAILABLE MOVE M01-MESSAGE-6 TO M00-MESSAGE * WHEN W02-REASON = MQRC-CONNECTION-BROKEN MOVE M01-MESSAGE-6 TO M00-MESSAGE * WHEN W02-REASON = MQRC-UNKNOWN-OBJECT-NAME MOVE M01-MESSAGE-2 TO M00-MESSAGE * WHEN W02-REASON = MQRC-NOT-AUTHORIZED MOVE M01-MESSAGE-3 TO M00-MESSAGE * WHEN OTHER MOVE 'MQOPEN' TO M01-MSG4-OPERATION MOVE W02-COMPCODE TO M01-MSG4-COMPCODE MOVE W02-REASON TO M01-MSG4-REASON MOVE M01-MESSAGE-4 TO M00-MESSAGE END-EVALUATE END-IF. E-EXIT. * * Return to performing section * EXIT. EJECT
Parent topic:
COBOL examples
fg18970_