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

validate comp field as numeric


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

New User


Joined: 16 Sep 2008
Posts: 19
Location: illinois

PostPosted: Thu Jul 15, 2010 7:11 pm
Reply with quote

how would you validate a comp field to determine it is numeric?

The class test only works for display fields and with the IBM extension, for comp-3 fields.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Thu Jul 15, 2010 7:25 pm
Reply with quote

if FIELD is NUMERIC ?
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 15, 2010 7:26 pm
Reply with quote

Quote:
how would you validate a comp field to determine it is numeric?
There is no possible COMP field that is not numeric -- which is why you cannot perform a NUMERIC check on it. The COMP variable is always numeric, by definition.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Jul 15, 2010 7:29 pm
Reply with quote

Xsray,

Comp fields are binary fields that will always hold a numeric value no matter what you put in it. So there is no test for numeric contents for this type of field.

Example:

4 bytes x'C1C1C1C1' will be interpreted as 3.250.700.737 if it is interpreted as binary numeric (comp), but will be seen as 'AAAA' if treated as alphanumeric.
Back to top
View user's profile Send private message
xsray

New User


Joined: 16 Sep 2008
Posts: 19
Location: illinois

PostPosted: Thu Jul 15, 2010 7:48 pm
Reply with quote

Thanks, I tried explaining that - but my manager insists that I check it for numeric value in case there is a "blank" in the field??????. I'll try explainig again.
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 15, 2010 7:54 pm
Reply with quote

A four-byte binary field that has X'40404040' has a numeric value of 1077952576. You can use a Windows calculator to find the 2-byte and 8-byte values.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Jul 15, 2010 8:05 pm
Reply with quote

xsray wrote:
Thanks, I tried explaining that - but my manager insists that I check it for numeric value in case there is a "blank" in the field??????. I'll try explainig again.
Well, if the manager is willing to call the rare occurrence of the comp value for all blanks, you could check for them and throw an error if it does occur......
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 15, 2010 8:38 pm
Reply with quote

Keep in mind, unless the binary field is defined as COMP-5 or the TRUNC(BIN) compiler option is active, check for SPACES needs to be done, using a redefinition of the COMP field as PIC X.

Code:

03  WS-COMP-FIELD PIC S9(09) COMP.
03  WS-COMP-FIELD-X REDEFINES WS-COMP-FIELD PIC  X(04).

IF  WS-COMP-FIELD-X = SPACES

If the above field was defined as COMP-5 then you could test it for the decimal equivalent of SPACES, which is 1077952576.

If the above field was defined as COMP and you're using TRUNC(BIN) then you can check it for this same decimal value as TRUNC(BIN) ensures that there's no high-order truncation.

However, COMP field tests using TRUNC(OPT) will cause high-order truncation (due to the picture clause of 9(9)) and therefore, you would need to test the redefined PIC X COMP field.

FWIW, if you perform a NUMERIC test on a COMP field, you'll get an "E" compilation error and your program won't compile cleanly.

You probably then need to show this to your manager. icon_eek.gif

Bill
Back to top
View user's profile Send private message
xsray

New User


Joined: 16 Sep 2008
Posts: 19
Location: illinois

PostPosted: Thu Jul 15, 2010 8:40 pm
Reply with quote

Thank you for your help - much appreciated.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jul 15, 2010 9:50 pm
Reply with quote

Quote:
but my manager insists that I check it for numeric value in case there is a "blank" in the field
It is unfortunate that you have such a clueless manager. . . icon_sad.gif

d
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Jul 15, 2010 11:53 pm
Reply with quote

If business rules specify a valid numeric range for the field, or a range can be derived, a test for a value inside the valid range would be more appropriate to implement.

Try to suggest that to your clueless manager (does he also look like Dilbert's manager do?)
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top