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

Validate if a Value from the file is numeric


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

New User


Joined: 19 Jun 2017
Posts: 5
Location: India

PostPosted: Mon Jun 19, 2017 11:52 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jun 20, 2017 12:39 am
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: 5
Location: India

PostPosted: Tue Jun 20, 2017 9:48 am
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jun 20, 2017 10:44 am
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: 5
Location: India

PostPosted: Tue Jun 20, 2017 1:33 pm
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: 1306
Location: Vilnius, Lithuania

PostPosted: Tue Jun 20, 2017 8:05 pm
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: 1353
Location: Israel

PostPosted: Tue Jun 20, 2017 8:37 pm
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Tue Jun 20, 2017 9:24 pm
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: 5
Location: India

PostPosted: Wed Jun 21, 2017 11:28 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top