IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Issue with the numeric comparison.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Amsar

New User


Joined: 26 Sep 2008
Posts: 84
Location: Chennai

PostPosted: Thu Jul 07, 2011 10:47 pm
Reply with quote

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
Code:
4EF0F0F44BF0F0


Thanks..
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 07, 2011 11:01 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 07, 2011 11:24 pm
Reply with quote

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
View user's profile Send private message
Amsar

New User


Joined: 26 Sep 2008
Posts: 84
Location: Chennai

PostPosted: Fri Jul 08, 2011 12:11 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Convert HEX to Numeric DB2 3
No new posts Facing ABM3 issue! CICS 3
Search our Forums:

Back to Top