Teresa,

There is some code in the MO01 Support Pack that uses the Pre-Processor
macros to take most of the work out of this.  The macro looks like this:

/*********************************************************************/
/*                                                                   */
/* define some macros to print out the parameters                    */
/*                                                                   */
/*********************************************************************/
#define PRINTPARAM(param)                                          \
   case param:                                                     \
     {                                                             \
       char *p = #param;                                           \
     strncpy(thestring,pmqcfst->String,min(sizeof(thestring),      \
             pmqcfst->StringLength));                              \
     thestring[pmqcfst->StringLength] = '\0';                      \
     printf("%s %s\n",p,thestring);                           \
     }                                                        \
     break;



Then the code looks like this...



/*********************************************************************/
/* print a string parameter                                          */
/*********************************************************************/
void printfmqcfst(MQCFST* pmqcfst)
{
  char thestring[100];

  switch (pmqcfst->Parameter)
  {
    PRINTPARAM(MQCA_APPL_ID)
//  many iterations deleted here...
       .
       .
       .
    default:
      printf("Invalid parameter, %ld\n",pmqcfst->Parameter);
      break;
  }
}




Of course, extracting all the defines from the header file and keeping it
current is the trick.  I'm attaching a Perl program that will do this for
you.  If you decide to use this coding technique, I would suggest using the
Perl program to generate a file that you then #include into the C++ code.
Then set up 'make' to run the Perl script as necessary to pick up the latest
defines if /opt/mqm/inc/cmqc.h ever changes.

Since the code in MSO01 was not directly applicable, I had the Perl program
write out a simpler, albeit untested, subroutine.  It's just a starting
point, change as necessary.

-------------Perl code starts here----------------
#!/usr/bin/perl -w
#-------------------------------------------------------
# Program to extract C Header file defines to cross-
# reference values to define names
# Author: T.Rob Wyatt mailto:[EMAIL PROTECTED]
#-------------------------------------------------------
use strict;

# Change path as required...
open(HDR, "/opt/mqm/inc/cmqc.h") or die("Cannot find cmqc.h file\n");
my @Lines = <HDR>;
close HDR;

# Captures Reason Codes and Feedback codes
@Lines = grep(/#define ?(MQRC_| MQFB_)/, @Lines);

print <<EOF
#define PRINTPARAM(param)                                          \
   case param:                                                     \
     printf("%s: '%s'\n", #param, mqrc)                            \
     break;
#endif

/*********************************************************************/
/* print a string parameter                                          */
/*********************************************************************/
void printrc(int mqrc)
{
  switch (mqrc)
  {

EOF
;

foreach (sort(@Lines)) {
    s/^\s+//g;  # Delete leading spaces
    print "    PRINTPARAM(", (split(/\s+/))[1], ")\n";
}

print <<'EOF'
    default:
      printf("Invalid parameter, %ld\n",mqrc);
      break;
  }
}
EOF
;

exit;


-----Original Message-----
From: Teresa Cheung [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 23, 2003 2:12 PM
To: [EMAIL PROTECTED]
Subject: MQ reasonCode


Can someone show me some sample C++ code to
translate the MQ reason code into some kind of readable text format.

Thanks!



Do you Yahoo!?
Yahoo! Photos - Get your photo on the big screen in Times Square

Instructions for managing your mailing list subscription are provided in
the Listserv General Users Guide available at http://www.lsoft.com
Archive: http://vm.akh-wien.ac.at/MQSeries.archive

Reply via email to