View previous topic :: View next topic
|
Author |
Message |
Amsar
New User
Joined: 26 Sep 2008 Posts: 84 Location: Chennai
|
|
|
|
Hi,
I have field ws-x pic x(7) = +004.00 . I have converted it to numeric using FUNCTION NUMVAL into variable WS-Y pic +9(3).9(2) = +004.00 .
Now when if am validating the variable WS-Y as
If ( WS-Y is Numeric )
Perform -a
Else
Perform- b
As i am expecting value to be numeric and control should go to a
but it's performing B.
Then i Tried
If ( WS-Y) >= 0
Perform -a
Else
Perform- b
Still control is going to b.
Please advise Why the comparison is happening so....
Hex value for variable WS-Y is
Thanks.. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Move the numeric value into a PIC S9(03)V9(02) field and then try the NUMERIC check.
This "feature" was introduced with COBOL/370 (the successor to VS/COBOL II) and was unofficially dubbed "De-Editing".
Bill |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
If you click on the Manuals link at the top of the page, find the COBOL Language Reference guide, and read section 6.1.6.2 on class conditions you will find
Quote: |
NUMERIC
identifier-1 consists entirely of the characters 0 through 9, with or without an operational sign.
If its PICTURE does not contain an operational sign, the identifier being tested is determined to be numeric only if the contents are numeric and an operational sign is not present.
If its PICTURE does contain an operational sign, the identifier being tested is determined to be numeric only if the item is an elementary item, the contents are numeric, and a valid operational sign is present.
Note: Valid operational signs are determined from the setting of the NUMCLS installation option and the NUMPROC compiler option. For more information, see the Enterprise COBOL Programming Guide . |
Your variable WS-Y contains somethiing other than digits 0 through 9 and an operational sign -- the decimal point. That prevents it from meeting the NUMERIC class condition.
And if you notice the hex value you posted, it starts X'4E'. Since a zero is X'F0', your IF WS-Y > 0 test will fail as well. COBOL does exactly what you told it to do -- whether or not that is what you meant for it to do. |
|
Back to top |
|
|
Amsar
New User
Joined: 26 Sep 2008 Posts: 84 Location: Chennai
|
|
|
|
Robert and Bill,
Thanks a lot for the information and your valuable time.
I have tried option suggested by Bill by moving the variable in s9(3)v(2)
and it worked perfect.
Thanks again!!! |
|
Back to top |
|
|
|