Highlighted
Absent Member.
Absent Member.
1884 views

Visual COBOL and IBM MQ

Jump to solution

I tried to use Visual COBOL 2.3 to connect to IBM MQ 7.5 which is installed on the same machine (RHEL 7.2)

The sample code is from IBM MQ 7.5 sample folder and I follow IBM document (instructions) , the sample is also posted online as

http://www.davar.net/EXTRACTS/Sample/MQS/6.0/2.1/amq0put0.cbl

I setup and compile the code as these steps:

export COBCPY=/opt/mqm/inc/cobcpy64

cob64 -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqicb_r

Everything is good, create the 64-bit executable:

[cobol@rh7 samp]$  cob64 -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqicb_r
cob64 -C nolist -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqicb_r
* Micro Focus COBOL                  V2.3 revision 000           Compiler
* Copyright (C) Micro Focus 1984-2015. All rights reserved.
* Accepted - verbose
* Accepted - reentrant
* Accepted - nolist
* Accepted - list("amq0put0.lst")
* Compiling amq0put0.cbl
* Total Messages:     0
* Data:       10608     Code:        1193
* Micro Focus COBOL Code Generator
* Copyright (C) Micro Focus 1984-2015. All rights reserved.
* Accepted - verbose
* Generating amq0put0
* Data:       10376     Code:        1950     Literals:         624
cob64: Entry points defined in module: amq0put0.o
    *AMQ0PUT0
    amq0put0

But when I run it,   I always got this error:

MQCONN ended with reason code +000002058 

2058 Queue Manager name error   --http://www-01.ibm.com/support/docview.wss?uid=swg21166938

In the sample folder, there is also the C code,  and executable from C code: amqsput

I use ./amqsput REQUEST_Q QM1   to test with my local queue and queue manager.  no issue at all.  I can send message to it.

this is how COBOL calls MQ function:

       CALL 'MQCONN'
            USING QM-NAME, HCONN,
            COMPLETION-CODE, CON-REASON.

this is how C code to call MQ:

 MQCONN(QMName,                  /* queue manager                  */
          &Hcon,                   /* connection handle              */
          &CompCode,               /* completion code                */
          &CReason);               /* reason code                    */

I assign the same value for the first parameter in both COBOL and C  (I change original COBOL to accept Queue Manager Name from console)

I do not understand why COBOL code failed,  C code succeeded.  both executed from the same folder.

Really appreciated for the help.

PS -- The IBM instructions for MQ development  has the special part for Micro Focus COBOL.  I just follow it exactly.

 

 

 

 

Tags (2)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: Visual COBOL and IBM MQ

Jump to solution

After I checked IBM online instruction for compiling C code:

gcc -m64  -o amqsput_64_r amqsput0.c -I/opt/mqm/inc -L/opt/mqm/lib64 -Wl,-rpath=/opt/mqm/lib64 -Wl,-rpath=/usr/lib64 -lmqm_r

I realized I should link the COBOL code to MQ server library (instead of MQ Client Library)

$cob64 -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqmcb_r

cob64 -C nolist -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqmcb_r

* Micro Focus COBOL                  V2.3 revision 000           Compiler

* Copyright (C) Micro Focus 1984-2015. All rights reserved.

* Accepted - verbose

* Accepted - reentrant

* Accepted - nolist

* Accepted - list("amq0put0.lst")

* Compiling amq0put0.cbl

* Total Messages:     0

* Data:       10608     Code:        1193

* Micro Focus COBOL Code Generator

* Copyright (C) Micro Focus 1984-2015. All rights reserved.

* Accepted - verbose

* Generating amq0put0

* Data:       10376     Code:        1950     Literals:         624

cob64: Entry points defined in module: amq0put0.o

   *AMQ0PUT0

   amq0put0

I retested with new executable:

$./amq0put0
AMQ0PUT0 start
Please enter the name of the target queue
REQUEST_Q
Please enter the name of the queue manager
sample
target queue is REQUEST_Q                                      
Please enter the message(s)
Test from COBOL
Test again from COBOL

AMQ0PUT0 end


Everything is working now.

View solution in original post

Tags (2)
0 Likes
1 Reply
Highlighted
Absent Member.
Absent Member.

RE: Visual COBOL and IBM MQ

Jump to solution

After I checked IBM online instruction for compiling C code:

gcc -m64  -o amqsput_64_r amqsput0.c -I/opt/mqm/inc -L/opt/mqm/lib64 -Wl,-rpath=/opt/mqm/lib64 -Wl,-rpath=/usr/lib64 -lmqm_r

I realized I should link the COBOL code to MQ server library (instead of MQ Client Library)

$cob64 -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqmcb_r

cob64 -C nolist -xtvP amq0put0.cbl -L /opt/mqm/lib64 -lmqmcb_r

* Micro Focus COBOL                  V2.3 revision 000           Compiler

* Copyright (C) Micro Focus 1984-2015. All rights reserved.

* Accepted - verbose

* Accepted - reentrant

* Accepted - nolist

* Accepted - list("amq0put0.lst")

* Compiling amq0put0.cbl

* Total Messages:     0

* Data:       10608     Code:        1193

* Micro Focus COBOL Code Generator

* Copyright (C) Micro Focus 1984-2015. All rights reserved.

* Accepted - verbose

* Generating amq0put0

* Data:       10376     Code:        1950     Literals:         624

cob64: Entry points defined in module: amq0put0.o

   *AMQ0PUT0

   amq0put0

I retested with new executable:

$./amq0put0
AMQ0PUT0 start
Please enter the name of the target queue
REQUEST_Q
Please enter the name of the queue manager
sample
target queue is REQUEST_Q                                      
Please enter the message(s)
Test from COBOL
Test again from COBOL

AMQ0PUT0 end


Everything is working now.

View solution in original post

Tags (2)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.