Hi,
I'm trying to retrieve data from MVS to a NT box but encountering conversion errors. Can anyone help me resolve this. I'm modifying the sample C program from IBM to perform the get. I have the MQGMO_Convert option on but I'm still getting a error code 2110. What do I need to do to the C code to convert from EBCDIC to ASCII? I know this feature is available on the Server version but is it also available on the free Client version? Thanks. Do anyone have a sample code for this? Thanks. I have encluded the sample code but it's kind of hard to read. Thanks.
/* @(#) samples/c/amqsget0.c, samples, p000, p000-L001017 1.21 00/10/16 12:10:20 */
/********************************************************************/
/* */
/* Program name: AMQSGET0 */
/* */
/* Description: Sample C program that gets messages from */
/* a message queue (example using MQGET) */
/* <START_COPYRIGHT> */
/* Statement: Licensed Materials - Property of IBM */
/* */
/* 04L1773, 5765-B73 */
/* 04L1802, 5639-B42 */
/* 04L1788, 5765-B74 */
/* 04L1816, 5765-B75 */
/* 04L1830, 5639-B43 */
/* (C) Copyright IBM Corp. 1994, 1998 */
/* <END_COPYRIGHT> */
/********************************************************************/
/* */
/* Function: */
/* */
/* */
/* AMQSGET0 is a sample C program to get messages from a */
/* message queue, and is an example of MQGET. */
/* */
/* -- sample reads from message queue named in the parameter */
/* */
/* -- displays the contents of the message queue, */
/* assuming each message data to represent a line of */
/* text to be written */
/* */
/* messages are removed from the queue */
/* */
/* -- writes a message for each MQI reason other than */
/* MQRC_NONE; stops if there is a MQI completion code */
/* of MQCC_FAILED */
/* */
/* */
/* Program logic: */
/* Take name of input queue from the parameter */
/* MQOPEN queue for INPUT */
/* while no MQI failures, */
/* . MQGET next message, remove from queue */
/* . print the result */
/* . (no message available counts as failure, and loop ends) */
/* MQCLOSE the subject queue */
/* */
/* */
/********************************************************************/
/* */
/* AMQSGET0 has 2 parameters - */
/* - the name of the message queue (required) */
/* - the queue manager name (optional) */
/* */
/********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* includes for MQI */
#include "cmqc.h"
int main(int argc, char **argv)
{
/* Declare MQI structures needed */
MQOD od = {MQOD_DEFAULT}; /* Object Descriptor */
MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
MQGMO gmo = {MQGMO_DEFAULT}; /* get message options */
/** note, sample uses defaults where it can **/
MQHCONN Hcon; /* connection handle */
MQHOBJ Hobj; /* object handle */
MQLONG ptions; /* MQOPEN options */
MQLONG C_options; /* MQCLOSE options */
MQLONG CompCode; /* completion code */
MQLONG OpenCode; /* MQOPEN completion code */
MQLONG Reason; /* reason code */
MQLONG CReason; /* reason code for MQCONN */
MQLONG buffer[100001]; /* message buffer */
MQLONG buflen; /* buffer length */
MQLONG messlen; /* message length received */
char QMName[50]; /* queue manager name */
printf("Sample AMQSGET0 start\n"
if (argc < 2)
{
printf("Required parameter missing - queue name\n"
exit(99);
}
/******************************************************************/
/* */
/* Create object descriptor for subject queue */
/* */
/******************************************************************/
strcpy(od.ObjectName, argv[1]);
QMName[0] = 0; /* default */
if (argc > 2)
strcpy(QMName, argv[2]);
/******************************************************************/
/* */
/* Connect to queue manager */
/* */
/******************************************************************/
MQCONN(QMName, /* queue manager */
&Hcon, /* connection handle */
&CompCode, /* completion code */
&CReason); /* reason code */
/* report reason and stop if it failed */
if (CompCode == MQCC_FAILED)
{
printf("MQCONN ended with reason code %ld\n", CReason);
exit( (int)CReason );
}
/******************************************************************/
/* */
/* Open the named message queue for input; exclusive or shared */
/* use of the queue is controlled by the queue definition here */
/* */
/******************************************************************/
ptions = MQOO_INPUT_AS_Q_DEF /* open queue for input */
+ MQOO_FAIL_IF_QUIESCING; /* but not if MQM stopping */
MQOPEN(Hcon, /* connection handle */
&od, /* object descriptor for queue */
ptions, /* open options */
&Hobj, /* object handle */
&OpenCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any; stop if failed */
if (Reason != MQRC_NONE)
{
printf("MQOPEN ended with reason code %ld\n", Reason);
}
if (OpenCode == MQCC_FAILED)
{
printf("unable to open queue for input\n"
}
/******************************************************************/
/* */
/* Get messages from the message queue */
/* Loop until there is a failure */
/* */
/******************************************************************/
CompCode = OpenCode; /* use MQOPEN result for initial test */
/******************************************************************/
/* Use these options when connecting to Queue Managers that also */
/* support them, see the Application Programming Reference for */
/* details. */
/* These options cause the MsgId and CorrelId to be replaced, so */
/* that there is no need to reset them before each MQGET */
/******************************************************************/
/*gmo.Version = MQGMO_VERSION_2;*/ /* Avoid need to reset Message */
/*gmo.MatchOptions = MQMO_NONE; */ /* ID and Correlation ID after */
/* every MQGET */
gmptions = MQGMO_WAIT; /* wait for new messages */
/* + MQGMO_CONVERT; convert if necessary */
gmo.WaitInterval = 15000; /* 15 second limit for waiting */
while (CompCode != MQCC_FAILED)
{
buflen = sizeof(buffer) - 1; /* buffer size available for GET */
/****************************************************************/
/* The following two statements are not required if the MQGMO */
/* version is set to MQGMO_VERSION_2 and and gmo.MatchOptions */
/* is set to MQGMO_NONE */
/****************************************************************/
/* */
/* In order to read the messages in sequence, MsgId and */
/* CorrelID must have the default value. MQGET sets them */
/* to the values in for message it returns, so re-initialise */
/* them before every call */
/* */
/****************************************************************/
memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId));
memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));
/****************************************************************/
/* */
/* MQGET sets Encoding and CodedCharSetId to the values in */
/* the message returned, so these fields should be reset to */
/* the default values before every call, as MQGMO_CONVERT is */
/* specified. */
/* */
/****************************************************************/
md.Encoding = MQENC_NATIVE;
md.CodedCharSetId = MQCCSI_Q_MGR;
MQGET(Hcon, /* connection handle */
Hobj, /* object handle */
&md, /* message descriptor */
&gmo, /* get message options */
buflen, /* buffer length */
buffer, /* message buffer */
&messlen, /* message length */
&CompCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any */
if (Reason != MQRC_NONE)
{
if (Reason == MQRC_NO_MSG_AVAILABLE)
{ /* special report for normal end */
printf("no more messages\n"
}
else /* general report for other reasons */
{
printf("MQGET ended with reason code %ld\n", Reason);
/* treat truncated message as a failure for this sample */
if (Reason == MQRC_TRUNCATED_MSG_FAILED)
{
CompCode = MQCC_FAILED;
}
}
}
/****************************************************************/
/* Display each message received */
/****************************************************************/
if (CompCode != MQCC_FAILED)
{
buffer[messlen] = '\0'; /* add terminator */
printf("message <%s>\n", buffer);
}
}
/******************************************************************/
/* */
/* Close the source queue (if it was opened) */
/* */
/******************************************************************/
if (OpenCode != MQCC_FAILED)
{
C_options = MQCO_NONE; /* no close options */
MQCLOSE(Hcon, /* connection handle */
&Hobj, /* object handle */
C_options,
&CompCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any */
if (Reason != MQRC_NONE)
{
printf("MQCLOSE ended with reason code %ld\n", Reason);
}
}
/******************************************************************/
/* */
/* Disconnect from MQM if not already connected */
/* */
/******************************************************************/
if (CReason != MQRC_ALREADY_CONNECTED )
{
MQDISC(&Hcon, /* connection handle */
&CompCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any */
if (Reason != MQRC_NONE)
{
printf("MQDISC ended with reason code %ld\n", Reason);
}
}
/******************************************************************/
/* */
/* END OF AMQSGET0 */
/* */
/******************************************************************/
printf("Sample AMQSGET0 end\n"
return(0);
}
I'm trying to retrieve data from MVS to a NT box but encountering conversion errors. Can anyone help me resolve this. I'm modifying the sample C program from IBM to perform the get. I have the MQGMO_Convert option on but I'm still getting a error code 2110. What do I need to do to the C code to convert from EBCDIC to ASCII? I know this feature is available on the Server version but is it also available on the free Client version? Thanks. Do anyone have a sample code for this? Thanks. I have encluded the sample code but it's kind of hard to read. Thanks.
/* @(#) samples/c/amqsget0.c, samples, p000, p000-L001017 1.21 00/10/16 12:10:20 */
/********************************************************************/
/* */
/* Program name: AMQSGET0 */
/* */
/* Description: Sample C program that gets messages from */
/* a message queue (example using MQGET) */
/* <START_COPYRIGHT> */
/* Statement: Licensed Materials - Property of IBM */
/* */
/* 04L1773, 5765-B73 */
/* 04L1802, 5639-B42 */
/* 04L1788, 5765-B74 */
/* 04L1816, 5765-B75 */
/* 04L1830, 5639-B43 */
/* (C) Copyright IBM Corp. 1994, 1998 */
/* <END_COPYRIGHT> */
/********************************************************************/
/* */
/* Function: */
/* */
/* */
/* AMQSGET0 is a sample C program to get messages from a */
/* message queue, and is an example of MQGET. */
/* */
/* -- sample reads from message queue named in the parameter */
/* */
/* -- displays the contents of the message queue, */
/* assuming each message data to represent a line of */
/* text to be written */
/* */
/* messages are removed from the queue */
/* */
/* -- writes a message for each MQI reason other than */
/* MQRC_NONE; stops if there is a MQI completion code */
/* of MQCC_FAILED */
/* */
/* */
/* Program logic: */
/* Take name of input queue from the parameter */
/* MQOPEN queue for INPUT */
/* while no MQI failures, */
/* . MQGET next message, remove from queue */
/* . print the result */
/* . (no message available counts as failure, and loop ends) */
/* MQCLOSE the subject queue */
/* */
/* */
/********************************************************************/
/* */
/* AMQSGET0 has 2 parameters - */
/* - the name of the message queue (required) */
/* - the queue manager name (optional) */
/* */
/********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* includes for MQI */
#include "cmqc.h"
int main(int argc, char **argv)
{
/* Declare MQI structures needed */
MQOD od = {MQOD_DEFAULT}; /* Object Descriptor */
MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
MQGMO gmo = {MQGMO_DEFAULT}; /* get message options */
/** note, sample uses defaults where it can **/
MQHCONN Hcon; /* connection handle */
MQHOBJ Hobj; /* object handle */
MQLONG ptions; /* MQOPEN options */
MQLONG C_options; /* MQCLOSE options */
MQLONG CompCode; /* completion code */
MQLONG OpenCode; /* MQOPEN completion code */
MQLONG Reason; /* reason code */
MQLONG CReason; /* reason code for MQCONN */
MQLONG buffer[100001]; /* message buffer */
MQLONG buflen; /* buffer length */
MQLONG messlen; /* message length received */
char QMName[50]; /* queue manager name */
printf("Sample AMQSGET0 start\n"
if (argc < 2)
{
printf("Required parameter missing - queue name\n"
exit(99);
}
/******************************************************************/
/* */
/* Create object descriptor for subject queue */
/* */
/******************************************************************/
strcpy(od.ObjectName, argv[1]);
QMName[0] = 0; /* default */
if (argc > 2)
strcpy(QMName, argv[2]);
/******************************************************************/
/* */
/* Connect to queue manager */
/* */
/******************************************************************/
MQCONN(QMName, /* queue manager */
&Hcon, /* connection handle */
&CompCode, /* completion code */
&CReason); /* reason code */
/* report reason and stop if it failed */
if (CompCode == MQCC_FAILED)
{
printf("MQCONN ended with reason code %ld\n", CReason);
exit( (int)CReason );
}
/******************************************************************/
/* */
/* Open the named message queue for input; exclusive or shared */
/* use of the queue is controlled by the queue definition here */
/* */
/******************************************************************/
ptions = MQOO_INPUT_AS_Q_DEF /* open queue for input */
+ MQOO_FAIL_IF_QUIESCING; /* but not if MQM stopping */
MQOPEN(Hcon, /* connection handle */
&od, /* object descriptor for queue */
ptions, /* open options */
&Hobj, /* object handle */
&OpenCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any; stop if failed */
if (Reason != MQRC_NONE)
{
printf("MQOPEN ended with reason code %ld\n", Reason);
}
if (OpenCode == MQCC_FAILED)
{
printf("unable to open queue for input\n"
}
/******************************************************************/
/* */
/* Get messages from the message queue */
/* Loop until there is a failure */
/* */
/******************************************************************/
CompCode = OpenCode; /* use MQOPEN result for initial test */
/******************************************************************/
/* Use these options when connecting to Queue Managers that also */
/* support them, see the Application Programming Reference for */
/* details. */
/* These options cause the MsgId and CorrelId to be replaced, so */
/* that there is no need to reset them before each MQGET */
/******************************************************************/
/*gmo.Version = MQGMO_VERSION_2;*/ /* Avoid need to reset Message */
/*gmo.MatchOptions = MQMO_NONE; */ /* ID and Correlation ID after */
/* every MQGET */
gmptions = MQGMO_WAIT; /* wait for new messages */
/* + MQGMO_CONVERT; convert if necessary */
gmo.WaitInterval = 15000; /* 15 second limit for waiting */
while (CompCode != MQCC_FAILED)
{
buflen = sizeof(buffer) - 1; /* buffer size available for GET */
/****************************************************************/
/* The following two statements are not required if the MQGMO */
/* version is set to MQGMO_VERSION_2 and and gmo.MatchOptions */
/* is set to MQGMO_NONE */
/****************************************************************/
/* */
/* In order to read the messages in sequence, MsgId and */
/* CorrelID must have the default value. MQGET sets them */
/* to the values in for message it returns, so re-initialise */
/* them before every call */
/* */
/****************************************************************/
memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId));
memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));
/****************************************************************/
/* */
/* MQGET sets Encoding and CodedCharSetId to the values in */
/* the message returned, so these fields should be reset to */
/* the default values before every call, as MQGMO_CONVERT is */
/* specified. */
/* */
/****************************************************************/
md.Encoding = MQENC_NATIVE;
md.CodedCharSetId = MQCCSI_Q_MGR;
MQGET(Hcon, /* connection handle */
Hobj, /* object handle */
&md, /* message descriptor */
&gmo, /* get message options */
buflen, /* buffer length */
buffer, /* message buffer */
&messlen, /* message length */
&CompCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any */
if (Reason != MQRC_NONE)
{
if (Reason == MQRC_NO_MSG_AVAILABLE)
{ /* special report for normal end */
printf("no more messages\n"
}
else /* general report for other reasons */
{
printf("MQGET ended with reason code %ld\n", Reason);
/* treat truncated message as a failure for this sample */
if (Reason == MQRC_TRUNCATED_MSG_FAILED)
{
CompCode = MQCC_FAILED;
}
}
}
/****************************************************************/
/* Display each message received */
/****************************************************************/
if (CompCode != MQCC_FAILED)
{
buffer[messlen] = '\0'; /* add terminator */
printf("message <%s>\n", buffer);
}
}
/******************************************************************/
/* */
/* Close the source queue (if it was opened) */
/* */
/******************************************************************/
if (OpenCode != MQCC_FAILED)
{
C_options = MQCO_NONE; /* no close options */
MQCLOSE(Hcon, /* connection handle */
&Hobj, /* object handle */
C_options,
&CompCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any */
if (Reason != MQRC_NONE)
{
printf("MQCLOSE ended with reason code %ld\n", Reason);
}
}
/******************************************************************/
/* */
/* Disconnect from MQM if not already connected */
/* */
/******************************************************************/
if (CReason != MQRC_ALREADY_CONNECTED )
{
MQDISC(&Hcon, /* connection handle */
&CompCode, /* completion code */
&Reason); /* reason code */
/* report reason, if any */
if (Reason != MQRC_NONE)
{
printf("MQDISC ended with reason code %ld\n", Reason);
}
}
/******************************************************************/
/* */
/* END OF AMQSGET0 */
/* */
/******************************************************************/
printf("Sample AMQSGET0 end\n"
return(0);
}