Below are key MQSeries calls need to write in COBOL program. Read MQSeries with COBOL sample program. In this post, you will learn how to write different calls in the COBOL program.
The working storage section of any MQ series program usually carries the following 4 IBM supplied copybooks.
- CMQODV (MQM-OBJECT-DESCRIPTOR)
- CMQMDV (MQM-MESSAGE-DESCRIPTOR)
- CMQPMOV (MQM-PUT-MESSAGE-OPTIONS)
- CMQGMOV (MQM-GET-MESSAGE-OPTIONS)
- CMQV (MQM-CONSTANTS)
1. The first MQ Call in the procedure division is MQCONN. This call establishes the connection with the queue manager of the open system application.
CALL 'MQCONN' USING WS-QMGR WS-HCONN WS-COMPCODE WS-REASON.
WS-QMGR should be populated with queue manager name before issuing this call. WS-HCONN will be populated with connection handle ID after successful execution of this call. This ID should be used in the subsequent calls that need access to this queue manager.
2. Open the queue in the queue manager (MQOPEN)
Usually one queue manager maintains more than one queue. Our application will be interested in only one queue of a particular queue manager. Using MQOPEN call opens the particular queue, object.
CALL 'MQOPEN' USING WS-HCONN MQOD WS-OPENOPTIONS WS-HOBJ WS-COMPCODE WS-REASON.
MQOD is the object descriptor copybook that needs to be populated with object information. Example, MQOD-OBJECTNAME with Queue name, MQOD-OBJECTTYPE (MQOT-Q),WS-OPENOPTIONS (MQOO-INPUT-AS-Q-DEF). WS-HCONN should point to the connection handle ID of the queue manager.
The object’s connection handle ID is populated with WS-HOBJ on the successful execution of MQOPEN. This should be used in all the subsequent operations with that object.
Related: MQSeries, COBOL Jobs and Career options
3. Get and Put a message in the queue (MQGET/ MQPUT)
CALL 'MQGET' USING WS-HCONN WS-HOBJ MQMD MQGMO WS-MSG-LTH-MAX MQ-MESSAGE-FROM-OPEN-SYSTEM WS-DATALENGTH WS-COMPCODE WS-REASON.
WS-HCONN is the connection handle of the queue manager. WS-HOBJ is the object handle ID (queue). MQMD is the message descriptor copybook and MQMGO is the get message options copybook. The attributes of the message to get/put are populated in MQMD (MQMD-CORRELID, MQMD-MSGTYPE, MQMD-PERSISTENCE, MQMD-EXPIRY etc) and the attributes of the ‘GET/PUT’ operation are mentioned in the MQMGO. (MQGMO-WAITINTERVAL is populated with the wait time, MQGMO-OPTIONS is set with MQGMO-WAIT option)
4. Close the queue (MQCLOS)
CALL 'MQCLOSE' USING WS-HCONN WS-HOBJ MQCO-NONE WS-COMPCODE WS-REASON.
WS-HCONN is the connection handle of the queue manager and WS-HOBJ is the handle ID of the object that is getting closed. MQCO-NONE is the simple close of the object. MQCO-DELETE, MQCO-DELETE-PURGE can also be mentioned.
5. Disconnect the host queue manager. (MQDISCONN)
CALL 'MQDISC' USING WS-HCONN WS-COMPCODE WS-REASON.
MQDISC API Call disconnects the queue manager represented by connection handle WS-HCONN.
In all the above calls, we mentioned WS-COMPCODE and WS-REASON as the last two arguments. They collectively called as return codes.
Completion code usually contains,
MQCC-FAILED (1) or MQCC-WARNING (2).
Reason code contains,
when MQCC-OK. It has the respective reason code in case of failure and warning.
Related: TIBCO Online Training -1