Author |
Message
|
rons |
Posted: Mon Jan 20, 2003 1:58 pm Post subject: IsNumeric |
|
|
Newbie
Joined: 20 Jan 2003 Posts: 3
|
Does anyone have some source code to check an ASCII string (after triming it for spaces) to see if it is numeric? I did not see where MQSI had the IsNumeric funciton. I am a newbie. Thanks in advance.
Last edited by rons on Mon Jan 20, 2003 4:56 pm; edited 1 time in total |
|
Back to top |
|
 |
yaakovd |
Posted: Mon Jan 20, 2003 2:30 pm Post subject: |
|
|
Partisan
Joined: 20 Jan 2003 Posts: 319 Location: Israel
|
You can convert your string to integer and back, and compare source string with new one. _________________ Best regards.
Yaakov
SWG, IBM Commerce, Israel |
|
Back to top |
|
 |
rons |
Posted: Mon Jan 20, 2003 5:02 pm Post subject: IsNumeric |
|
|
Newbie
Joined: 20 Jan 2003 Posts: 3
|
Wouldn't it give me an error trying to convert it to Integer? |
|
Back to top |
|
 |
yaakovd |
Posted: Tue Jan 21, 2003 6:09 am Post subject: |
|
|
Partisan
Joined: 20 Jan 2003 Posts: 319 Location: Israel
|
It wil be problem when casting to integer...
You can try this trick (only in case when it appears ones in input message):
In filter node : IF( CAST(Root.<your path> AS INT))
Connect true, false and unknown connectors to your regular node and failer connector to another node when messages with non-integer will processed.
Or you can use this (tested) code:
---------------------------------------------------------
DECLARE I INT;
DECLARE TMP_C CHAR;
DECLARE TMP_C1 CHAR;
DECLARE FLAG BOOLEAN;
SET FLAG = TRUE;
SET TMP_C = InputRoot.XML."Data" ; -- change to <your path>
SET I = 1;
WHILE(I <= LENGTH(TMP_C)) DO
SET TMP_C1 = SUBSTRING(TMP_C FROM I FOR 1);
IF(TMP_C1 < '0' OR TMP_C1 > '9') THEN
SET FLAG = FALSE;
END IF;
SET I = I +1;
END WHILE;
------------------------------------------------------
In MQSI 2.1 you can create procedure isInteger with this code _________________ Best regards.
Yaakov
SWG, IBM Commerce, Israel |
|
Back to top |
|
 |
rons |
Posted: Tue Jan 21, 2003 6:34 am Post subject: IsNumeric |
|
|
Newbie
Joined: 20 Jan 2003 Posts: 3
|
Thanks yaakovd for your help. The code is exactly what I was looking for. I just need to make a procedure out of it, since I will be checking multiple fields.  |
|
Back to top |
|
 |
yaakovd |
Posted: Tue Jan 21, 2003 10:21 am Post subject: |
|
|
Partisan
Joined: 20 Jan 2003 Posts: 319 Location: Israel
|
Any time
I also tried:
SUBSTRING('<largest number value>' || STR FROM LENGTH(STR)-1 FOR 19) and compare it with largest integer number (some 19-digits number you can find its value in ESQL reference)
or
SUBSTRING('9999999999999999999' || STR FROM LENGTH(STR)-1 FOR 19) and compare it with '9999999999999999999' etc..
You cat try in this direction... _________________ Best regards.
Yaakov
SWG, IBM Commerce, Israel |
|
Back to top |
|
 |
|