Connect to a queue manager

This example demonstrates how to use the MQCONN call to connect a program to a queue manager in z/OS batch.

This extract is taken from the Browse sample application (program CSQ4BCA1) supplied with IBM MQ for z/OS. For the names and locations of the sample applications on other platforms, see Sample procedural programs (platforms except z/OS ).

#include <cmqc.h>
⋮
static char Parm1[MQ_Q_MGR_NAME_LENGTH] ;

int  main(int argc, char *argv[] )
   {
   /*                                                    */
   /*     Variables for MQ calls                         */
   /*                                                    */
   MQHCONN Hconn;      /* Connection handle              */
   MQLONG  CompCode;   /* Completion code                */
   MQLONG  Reason;     /* Qualifying reason              */

   /* Copy the queue manager name, passed in the         */
   /* parm field, to Parm1                               */
   strncpy(Parm1,argv[1],MQ_Q_MGR_NAME_LENGTH);

   /*                                                    */
   /* Connect to the specified queue manager.            */
   /*   Test the output of the connect call.  If the     */
   /*   call fails, print an error message showing the   */
   /*   completion code and reason code, then leave the  */
   /*   program.                                         */
   /*                                                    */
   MQCONN(Parm1,
          &Hconn,
          &CompCode,
          &Reason);
   if ((CompCode != MQCC_OK) | (Reason != MQRC_NONE))
      {
      sprintf(pBuff, MESSAGE_4_E,
              ERROR_IN_MQCONN, CompCode, Reason);
      PrintLine(pBuff);
      RetCode = CSQ4_ERROR;
      goto AbnormalExit2;
      }
      ⋮
}
Parent topic: C language examples