View previous topic :: View next topic
|
Author |
Message |
xsray
New User
Joined: 16 Sep 2008 Posts: 19 Location: illinois
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
if FIELD is NUMERIC ? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
xsray
New User
Joined: 16 Sep 2008 Posts: 19 Location: illinois
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.
Bill |
|
Back to top |
|
|
xsray
New User
Joined: 16 Sep 2008 Posts: 19 Location: illinois
|
|
|
|
Thank you for your help - much appreciated. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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. . .
d |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
|