Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
validate comp field as numeric

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: validate comp field as numeric
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: 2442
Location: Netherlands, Amstelveen

PostPosted: Thu Jul 15, 2010 7:25 pm    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Thu Jul 15, 2010 7:26 pm    Post subject:
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    Post subject:
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    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Thu Jul 15, 2010 7:54 pm    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Thu Jul 15, 2010 8:05 pm    Post subject:
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 15, 2010 8:38 pm    Post subject: Reply to: validate comp field as numeric
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    Post subject:
Reply with quote

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

Site Director


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

PostPosted: Thu Jul 15, 2010 9:50 pm    Post subject: Reply to: validate comp field as numeric
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    Post subject:
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    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
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm
No new posts File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Validate the Date girishb2 DFSORT/ICETOOL 9 Tue Sep 19, 2017 1:12 am
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us