Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Validate if a Value from the file is numeric

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
balacsv2

New User


Joined: 19 Jun 2017
Posts: 4
Location: India

PostPosted: Mon Jun 19, 2017 11:52 pm    Post subject: Validate if a Value from the file is numeric
Reply with quote

I am reading a comma delimited file which comes from another vendor using unstring.I have a field from the file which could have values with the decimal point for ex.95.6 .I am receiving the field from the input file with the declaration

05 WS-PERCENT PIC X(06) JUST RIGHT

I need to check if WS-PERCENT which comes from the vendor is numeric.After receiving the field as mentioned above with JUSTIFIED RIGHT i did an inspect to make sure that i remove the leading spaces

code:
INSPECT WS-PERCENT REPLACING LEADING SPACES BY ZEROES
DISPLAY "WS-PERCENT" WS-PERCENT
IF WS-PERCENT IS NUMERIC
Do some statements
else
set Error swtich to true
END-IF

After the inspect it displayed
DISPLAY "WS-PERCENT" 0099.5

but the IF WS-PERCENT IS NUMERIC check is failing.Can someone correct me what is it that i am doing wrong here?? My ultimate aim is to make sure that the percentage value has valid numeric ,any other ideas are welcome
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Tue Jun 20, 2017 12:39 am    Post subject: Reply to: Validate if a Value from the file is numeric
Reply with quote

From the Enterprise COBOL Language Reference manual, page 210 (V6.1):
Quote:
For all numeric fields, the PICTURE character-string can contain only the symbols 9, P, S, and V.
Decimal points are not considered numeric characters, although signs are. You can check each character to be what you want or you can try using FUNCTION NUMVAL to convert the data to a numeric variable (which may cause problems if you have true non-numeric data in the variable).
Back to top
View user's profile Send private message
balacsv2

New User


Joined: 19 Jun 2017
Posts: 4
Location: India

PostPosted: Tue Jun 20, 2017 9:48 am    Post subject:
Reply with quote

Thanks a lot for the response ! Yes ,I tried using FUNCTION NUMVAL for converting but there are chances that it may cause an abend incase of an invalid data.
Looking at the options would you think using a special names to be better?

CLASS VALID-NUM IS "0" THRU "9"
"."
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Tue Jun 20, 2017 10:44 am    Post subject:
Reply with quote

If the value can have a sign, you would need to add '+' and '-' to the user-defined class. Properly defined, that is one way to validate your data.
Back to top
View user's profile Send private message
balacsv2

New User


Joined: 19 Jun 2017
Posts: 4
Location: India

PostPosted: Tue Jun 20, 2017 1:33 pm    Post subject:
Reply with quote

Since the Value we receive is a Percentage field there are no chances of us getting signed values .We could get spaces but I am REPLACING LEADING SPACES BY ZEROES and only then am checking for VALID-NUM .I tried testing it and it seems to be fine..

Thanks a lot for helping me out !
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1027
Location: Oostende, Belgium

PostPosted: Tue Jun 20, 2017 8:05 pm    Post subject:
Reply with quote

Much better solution: Tell the other vendor that sending invalid data will incur huge processing surcharges! It's totally ridiculous that you have to cater for their incompetence!
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1232
Location: Israel

PostPosted: Tue Jun 20, 2017 8:37 pm    Post subject:
Reply with quote

I Use
balacsv2 wrote:
CLASS VALID-NUM IS "0" THRU "9" "."

and it works 99.9% of the time (that is, until I receive a number like "9.9.9").

I would not bother doing more than this basic validation.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1736
Location: NY,USA

PostPosted: Tue Jun 20, 2017 9:24 pm    Post subject:
Reply with quote

Quote:
but the IF WS-PERCENT IS NUMERIC check is failing
Unstring them into two variables delimited by '.' and perform NUMERIC check individually.
Back to top
View user's profile Send private message
balacsv2

New User


Joined: 19 Jun 2017
Posts: 4
Location: India

PostPosted: Wed Jun 21, 2017 11:28 am    Post subject:
Reply with quote

Thanks a lot everyone..I handled it using one of the options as mentioned above using SPECIAL NAMES and it's working fine
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts How to generate a new unique Input fi... for1ranjith CLIST & REXX 11 Sat Jul 01, 2017 12:09 pm
No new posts Writing a file using online program grvtomar PL/I & Assembler 3 Fri Jun 30, 2017 1:06 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us