---
title: "MQSeries Tutorial for Mainframe Programmers (3 of 5)"
description: "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. https://srinimf.c..."
url: https://srinimf.com/2015/09/25/mqseries-tutorial-for-mainframe-programmers-3-of-5/
date: 2015-09-25
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/09/pexels-photo-1090387.jpeg?fit=1880%2C1124&ssl=1
categories: ["MQSeries"]
tags: ["MQSeries for mainframe", "MQSeries Tutorial"]
type: post
lang: en
---

# MQSeries Tutorial for Mainframe Programmers (3 of 5)

Below are key MQSeries calls need to write in COBOL program. Read [MQSeries with COBOL sample program](http://srinimf.com/2014/03/08/mq-series-cobol/). In this post, you will learn [how to](https://srinimf.com/2016/03/14/how-to-open-a-queue-in-mqseries-with-mqopen/) write different calls in the COBOL program.

Related[IBM MQSERIES for ZOS tutorial to read](https://srinimf.com/2014/05/19/ibm-mqseries-for-zos/)

The working storage section of any MQ series program usually carries the following **4 IBM supplied copybooks**.

1. CMQODV     (MQM-OBJECT-DESCRIPTOR)
2. CMQMDV (MQM-MESSAGE-DESCRIPTOR)
3. CMQPMOV (MQM-PUT-MESSAGE-OPTIONS)
4. CMQGMOV (MQM-GET-MESSAGE-OPTIONS)
5. 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](http://www.indeed.com/jobs?q=MQSeries&l=United+States&indpubnum=6634974704162507)

**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-OK (0),
MQCC-FAILED (1) or MQCC-WARNING (2).
```

**Reason code contains,**

MQRC-NONE (0)

when MQCC-OK. It has the respective reason code in case of failure and warning.

***Related:** *[TIBCO Online Training -1](http://click.linksynergy.com/link?id=yYOcxCqEbGo&offerid=323058.131612&type=2&murl=https%3A%2F%2Fwww.udemy.com%2Fadditional-workflow-patterns-with-tibco-business-studio%2F)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2015%2F09%2F25%2Fmqseries-tutorial-for-mainframe-programmers-3-of-5%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F09%2Fpexels-photo-1090387.jpeg%3Ffit%3D1200%252C717%26ssl%3D1&description=MQSeries%20Tutorial%20for%20Mainframe%20Programmers%20%283%20of%205%29)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/09/25/mqseries-tutorial-for-mainframe-programmers-3-of-5/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/09/25/mqseries-tutorial-for-mainframe-programmers-3-of-5/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/09/25/mqseries-tutorial-for-mainframe-programmers-3-of-5/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/09/25/mqseries-tutorial-for-mainframe-programmers-3-of-5/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20MQSeries%20Tutorial%20for%20Mainframe%20Programmers%20%283%20of%205%29&body=https%3A%2F%2Fsrinimf.com%2F2015%2F09%2F25%2Fmqseries-tutorial-for-mainframe-programmers-3-of-5%2F&share=email)
-

### Like this:

Like Loading…
