Put a message using MQPUT1
This example demonstrates how to use the MQPUT1 call to open a queue, put a single message on the queue, then close the queue.
This extract is taken from the Credit Check sample application (program CSQ4CCB5) 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 ).
⋮ MQLONG Hconn; /* Connection handle */ MQHOBJ Hobj_CheckQ; /* Object handle */ MQLONG CompCode; /* Completion code */ MQLONG Reason; /* Qualifying reason */ MQOD ObjDesc = {MQOD_DEFAULT}; /* Object descriptor */ MQMD MsgDesc = {MQMD_DEFAULT}; /* Message descriptor */ MQLONG OpenOptions; /* Control the MQOPEN call */ MQGMO GetMsgOpts = {MQGMO_DEFAULT}; /* Get Message Options */ MQLONG MsgBuffLen; /* Length of message buffer */ CSQ4BCAQ MsgBuffer; /* Message structure */ MQLONG DataLen; /* Length of message */ MQPMO PutMsgOpts = {MQPMO_DEFAULT}; /* Put Message Options */ CSQ4BQRM PutBuffer; /* Message structure */ MQLONG PutBuffLen = sizeof(PutBuffer); /* Length of message buffer */ ⋮
void Process_Query(void) { /* */ /* Build the reply message */ /* */ ⋮ /* */ /* Set the object descriptor, message descriptor and */ /* put message options to the values required to */ /* create the reply message. */ /* */ strncpy(ObjDesc.ObjectName, MsgDesc.ReplyToQ, MQ_Q_NAME_LENGTH); strncpy(ObjDesc.ObjectQMgrName, MsgDesc.ReplyToQMgr, MQ_Q_MGR_NAME_LENGTH); MsgDesc.MsgType = MQMT_REPLY; MsgDesc.Report = MQRO_NONE; memset(MsgDesc.ReplyToQ, ' ', MQ_Q_NAME_LENGTH); memset(MsgDesc.ReplyToQMgr, ' ', MQ_Q_MGR_NAME_LENGTH); memcpy(MsgDesc.MsgId, MQMI_NONE, sizeof(MsgDesc.MsgId)); PutMsgOpts.Options = MQPMO_SYNCPOINT + MQPMO_PASS_IDENTITY_CONTEXT; PutMsgOpts.Context = Hobj_CheckQ; PutBuffLen = sizeof(PutBuffer); MQPUT1(Hconn, &ObjDesc, &MsgDesc, &PutMsgOpts, PutBuffLen, &PutBuffer, &CompCode, &Reason); if (CompCode != MQCC_OK) { strncpy(TS_Operation, "MQPUT1", sizeof(TS_Operation)); strncpy(TS_ObjName, ObjDesc.ObjectName, MQ_Q_NAME_LENGTH); Record_Call_Error(); Forward_Msg_To_DLQ(); } return; } ⋮Parent topic: C language examples