ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Using Handlers with CAST

Post new topic  Reply to topic
 Using Handlers with CAST « View previous topic :: View next topic » 
Author Message
Vitor
PostPosted: Mon Jan 23, 2012 10:11 am    Post subject: Using Handlers with CAST Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

I have a requirement to parse an XML element which can contain an integer value or "N/A". A sensible solution to the problem would seem be the addition of an XML attribute "applicable" that took a value of yes or no but it seems this would cost $6,000,000, take 5 months and require a UN resolution. The downstream app that's consuming the XML has already complained that the XSD clearly describes this field as an xsd:integer and they keep getting "N/A" in it. So here I am, scrubbing the XML so it matches it's schema and not feeling bitter at all.

Because this value can be 0, +ive or -ive I thought to use a handler to detect the cast failure. When a character value is passed the handler fires as expected but there's not SQLCODE to indicate the reason. A few moment with the search facility turned up this which contains this year old comment:

mgk wrote:
Unfortunately only CASTS involving Char-> Decimal and the Base64Decode function currently use the S22018 SQL state code which is why you do not see it on a CAST of a char -> integer...


Casting my value to a DECIMAL not an INTEGER yields a SQLCODE as this post indicates.

I have 2 questions resulting:

1) Is this documented anywhere? The InfoCenter entry for CAST has examples that use handlers (though not for CHAR -> INTEGER) and at least it's a bit misleading for the feeble minded.

2) What, in the opinion of the readership, is the best solution given this feature? I've come up with:

- Explicitly test for "N/A", only cast if it's not that and rely on the front end to put "N/A" in the field rather than "NA", "MISSING", "NOT SURE", etc
- Use a handler, cast the value to a decimal to trigger the handler then cast again to an integer
- Put a default in the cast of some mad value and test for that coming out
- A more ingenious option I've not thought of
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Jan 23, 2012 10:18 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Code:
TRANSLATE(UPPER(inputInteger),'ABCDEFGHIJKLMNOPQRSTUVWXYZ/',);


?
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Jan 23, 2012 10:28 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqjeff wrote:
Code:
TRANSLATE(UPPER(inputInteger),'ABCDEFGHIJKLMNOPQRSTUVWXYZ/',);


?


Valid.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mgk
PostPosted: Mon Jan 23, 2012 10:50 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

You don't say what you want to do when the data is "N/A", but have you tried using the DEFAULT clause on the CAST statement:

DECLARE answer DECIMAL CAST( input AS DECIMAL DEFAULT DECIMAL 'NAN');

Kind Regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Jan 23, 2012 10:55 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mgk wrote:
You don't say what you want to do when the data is "N/A", but have you tried using the DEFAULT clause on the CAST statement:

DECLARE answer DECIMAL CAST( input AS DECIMAL DEFAULT DECIMAL 'NAN');


Now that's ingenious!

All I have to do with this is detect it and route the inbound message into a bucket for manual intervention. In theory this is a mandatory integer value, in practice the end user's don't always know it when they key the records so put in "N/A".

Don't laugh.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mgk
PostPosted: Mon Jan 23, 2012 11:05 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Quote:
Now that's ingenious!


Glad you like it

Detecting NAN after the CAST is easy:

Code:
IF answer IS NAN THEN
  --deal with invalid case
ELSE
  --deal with valid case
END IF;


Kind Regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
adubya
PostPosted: Mon Jan 23, 2012 11:40 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

I use the DEFAULT clause for situations just like that, a handy tool to have in the kitbag
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Mon Jan 23, 2012 9:44 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Vitor wrote:
mgk wrote:
You don't say what you want to do when the data is "N/A", but have you tried using the DEFAULT clause on the CAST statement:

DECLARE answer DECIMAL CAST( input AS DECIMAL DEFAULT DECIMAL 'NAN');


Now that's ingenious!

All I have to do with this is detect it and route the inbound message into a bucket for manual intervention. In theory this is a mandatory integer value, in practice the end user's don't always know it when they key the records so put in "N/A".

Don't laugh.

If the field is nillable, have you thought about using xsi:nil='true' for your non applicable case?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Tue Jan 24, 2012 12:50 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

fjb_saper wrote:
If the field is nillable, have you thought about using xsi:nil='true' for your non applicable case?


This would be valid if the field really was nillable, but it's a mandatory integer. As I said above, the root problem is that the sending application isn't validating the XML against their own schema & allowing this field to be a character. The business rules insist this value must be provided by this message so why they allow the users to finish the transaction when they don't know the value to put in this field is beyond me.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Using Handlers with CAST
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.