View previous topic :: View next topic
|
Author |
Message |
sharad_shanu
New User
Joined: 03 Oct 2006 Posts: 40
|
|
|
|
Hi all,
I am facing some issue with NUMVAL function. We are working on stored procedures which is passed pipe delimited string.
The input string for this stored procedure is, input0|input1|input2|input3|input4
Also input2 is optional that is, the value of input2 may or may not be available. So the input may also be like input0|input1||input3|input4
I am doing an unstring in my stored procedure and then using to calculate
COMPUTE INPUT2-NUM = FUNCTION NUMVAL (INPUT2)
This INPUT2-NUM is used in where clause in my sql query.
When I am putting any value for input2 in input string, it is working fine. When I am not providing anything for input2 (second format for input string), calling for my stored procedure is getting failed and we are having SQL -430 and sqlstate 38503.
Even I tried with having one spaces for input2, I was getting abends. In other words, I used this input string.
input0|input1| |input3|input4
I need your help in this regard. Please let me know if additional information is required.
-Sharad |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
I'm not very sure - what might have casused the probelm. Just for hit-n-trial - please try to use NUMVAL-C instead of NUMVAL. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
FUNCTION NUMVAL causes an abend if the data is not numeric.
You have to validate the data before:
Code: |
IF (input2 is valid) THEN
COMPUTE INPUT2-NUM = FUNCTION NUMVAL (INPUT2)
ELSE
MOVE 0 TO INPUT2-NUM
END-IF
|
Number validation will be different if you have a sign (+ or -) and if you have a decimal point.
Because there will certainly be some spaces in the field, if would recommend defining a CLASS. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
After reading again.... maybe this will be enough:
Code: |
IF INPUT2 = SPACES THEN
MOVE 0 TO INPUT2-NUM
ELSE
COMPUTE INPUT2-NUM = FUNCTION NUMVAL (INPUT2)
END-IF |
|
|
Back to top |
|
|
sharad_shanu
New User
Joined: 03 Oct 2006 Posts: 40
|
|
|
|
Just one question, why it is affecting at the time of calling of stored procedure?
It should fail while processing the input data but why to fail in call itself. |
|
Back to top |
|
|
sharad_shanu
New User
Joined: 03 Oct 2006 Posts: 40
|
|
|
|
I modified code as per your suggestion and it is working fine.
I thought if there is a space in input, NUMVAL should give 0 as output but I was wrong.
Anyways, Thanks to all for your help.
Regards,
Sharad |
|
Back to top |
|
|
|