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 » How to validate if a value of a tag is numeric

Post new topic  Reply to topic
 How to validate if a value of a tag is numeric « View previous topic :: View next topic » 
Author Message
schroederms
PostPosted: Mon Sep 19, 2005 11:05 am    Post subject: How to validate if a value of a tag is numeric Reply with quote

Disciple

Joined: 21 Jul 2003
Posts: 169
Location: IA

Anyone out there know how to check to see if a value of a tag is a NUMBER ? I've looked through the documentation on functions and can not seem to find what I'm looking for.

Thanks,
Mike
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Sep 19, 2005 11:10 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I guess it depends on what you mean by "tag".

If you mean, the value of an XML element, then you could always model the data using MRM, and validate it that way.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Mon Sep 19, 2005 7:39 pm    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

If the domain is XML and the mxsd defines the "tag value" to be number then it will be validated at the input, else when you try to get the value to store in a string and it throws an exception then you know its a number and can only be stored in a integer variable.
Back to top
View user's profile Send private message Send e-mail
jsware
PostPosted: Tue Sep 20, 2005 4:14 am    Post subject: Reply with quote

Chevalier

Joined: 17 May 2001
Posts: 455

Another way is to translate all the digits into nothing, and if you've got anything left, it can't be a valid numeric.

This only works with positive integers however:

Code:
IF LENGTH(TRANSLATE(TRIM(integerString), '0123456789', '')) = 0 THEN
  -- String is a valid integer
ELSE
  -- String contains something other than 0-9 digits.
END IF;

_________________
Regards
John
The pain of low quaility far outlasts the joy of low price.
Back to top
View user's profile Send private message
mgk
PostPosted: Tue Sep 20, 2005 4:31 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

And in Message Broker V6 there is a DEFAULT clause on a CAST so that if the CAST fails, instead of an exception being thrown, the value in the DEFAULT clause is used instead.

Like:

Code:
SET result = CAST( myString INTEGER DEFAULT NULL);


or

Code:
SET result = CAST( myString INTEGER DEFAULT -1);


Then you can check result for -1 or NULL or any other value you placed in the DEFAULT clause.
_________________
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
schroederms
PostPosted: Tue Sep 20, 2005 5:38 am    Post subject: Reply with quote

Disciple

Joined: 21 Jul 2003
Posts: 169
Location: IA

thanks all.

Based on what I'm doing, it looks like mgk solution would work for me if I was on V6, but we are not there yet. So I'll try using a SUBSTRING thru the data of the field checking each byte. Not what I really wanted to do.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Sep 20, 2005 11:12 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Also, IS NUM
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
schroederms
PostPosted: Tue Sep 20, 2005 3:05 pm    Post subject: Reply with quote

Disciple

Joined: 21 Jul 2003
Posts: 169
Location: IA

jefflowrey,

I see no IS NUM function in the help. Could you expand?

Thanks
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Sep 20, 2005 3:59 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

http://publib.boulder.ibm.com/infocenter/wbihelp/index.jsp?topic=/com.ibm.etools.mft.doc/ak01040_.htm wrote:
Operator IS
The operator IS allows you to test whether a value is NULL.

This includes testing values INF, +INF, -INF, NAN (not a number), and NUM in any mixture of case. The alternative forms +INFINITY, -INFINITY, and NUMBER are also accepted.

If applied to non-numeric types, the result is FALSE.

The comparison operator (=) does not allow this because the result of comparing with NULL is NULL. It also allows you to use a more natural English syntax when testing boolean values.

Syntax diagram format: Railroad diagram Dotted decimal

Read syntax diagramSkip visual syntax diagram
IS operator

.-TRUE----.
>>-Operand--IS--+-----+--+-FALSE---+---------------------------><
'-NOT-' +-UNKNOWN-+
'-NULL----'


The result is TRUE if the value of the left operand is equal (or not equal if the NOT clause is present) to the specified value (TRUE, FALSE, UNKNOWN, or NULL). Otherwise the result is FALSE.

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
mgk
PostPosted: Wed Sep 21, 2005 1:36 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Hi,

I know the docs could be improved in this area, but, IS NUM (or IS NUMBER) does not allow you to check if a character string represents a number. It will always return FALSE if given a none numeric datatype
(that is anything other that FLOAT, DECIMAL INTEGER). For FLOAT and INTEGER it will always return TRUE because they are by definiton numeric (unless they are null in which case it will return FALSE)

It is really only useful when used with a DECIMAL, where it is designed to check that a DECIMAL numer is valid, which means that it checks that it is not NAN or INFINITY or NULL in one operation.

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
jefflowrey
PostPosted: Wed Sep 21, 2005 3:41 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I thought, without checking it, that this might be a case where an implicit cast was done.

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
mgk
PostPosted: Wed Sep 21, 2005 3:55 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Hi,

There is an implicit cast done here, but only from CHARACTER to BOOL, which is only really useful if you are testing for IS TRUE or IS FALSE.

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
schroederms
PostPosted: Wed Sep 21, 2005 4:40 am    Post subject: Reply with quote

Disciple

Joined: 21 Jul 2003
Posts: 169
Location: IA

mgk,

Any change of


SET result = CAST( myString INTEGER DEFAULT NULL);


or

Code:
SET result = CAST( myString INTEGER DEFAULT -1);


Getting into version 5 FixPack 7?

Thanks,
Mike
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 » How to validate if a value of a tag is numeric
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.