Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data conversion error

Status
Not open for further replies.

YL5956

MIS
Jul 11, 2001
73
US
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 &quot;cmqc.h&quot;

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 o_Options; /* 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(&quot;Sample AMQSGET0 start\n&quot;);
if (argc < 2)
{
printf(&quot;Required parameter missing - queue name\n&quot;);
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(&quot;MQCONN ended with reason code %ld\n&quot;, 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 */
/* */
/******************************************************************/
o_Options = 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 */
o_Options, /* open options */
&Hobj, /* object handle */
&OpenCode, /* completion code */
&Reason); /* reason code */

/* report reason, if any; stop if failed */
if (Reason != MQRC_NONE)
{
printf(&quot;MQOPEN ended with reason code %ld\n&quot;, Reason);
}

if (OpenCode == MQCC_FAILED)
{
printf(&quot;unable to open queue for input\n&quot;);
}

/******************************************************************/
/* */
/* 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 */
gmo_Options = 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(&quot;no more messages\n&quot;);
}
else /* general report for other reasons */
{
printf(&quot;MQGET ended with reason code %ld\n&quot;, 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(&quot;message <%s>\n&quot;, 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(&quot;MQCLOSE ended with reason code %ld\n&quot;, 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(&quot;MQDISC ended with reason code %ld\n&quot;, Reason);
}
}

/******************************************************************/
/* */
/* END OF AMQSGET0 */
/* */
/******************************************************************/
printf(&quot;Sample AMQSGET0 end\n&quot;);
return(0);
}


 
Data conversion is found in the channel definitions. Have your administrator do a conversion on the sender.
 
YL5956,

can you not define your channels so that both the MVS and NT sides agree that your messages are TEXT messages? this way perhaps you do not need data conversion.
 
Only do conversion at the channel level if it is absolutely necessary - it is much better practice to do conversion at the receiving end.

I notice in your code that the MQGMO_CONVERT option is commented out. You need this to do conversion. Also, ensure that the format of the message (in the Message Descriptor)is MQSTRING otherwise conversion won't work.

Cheers,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top