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

Question on IS NUMERIC clause


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

New User


Joined: 27 Mar 2006
Posts: 68

PostPosted: Wed Dec 17, 2008 5:28 pm
Reply with quote

Can we use IS NUMERIC clause on COMP (Binary) data item.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Dec 17, 2008 5:59 pm
Reply with quote

Any values in a comp field would be valid, so the test would be worthless.
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: Wed Dec 17, 2008 6:34 pm
Reply with quote

From the COBOL Language Reference manual:
Quote:
6.1.6.2 Class condition


The class condition determines whether the content of a data item is alphabetic, alphabetic-lower, alphabetic-upper, numeric, DBCS, KANJI, or contains only the characters in the set of characters specified by the CLASS clause as defined in the SPECIAL-NAMES paragraph of the Environment Division.


___ Format _____________________________________________________________
| |
| >>__identifier-1__ ____ __ _____ __ _NUMERIC__________ _____________>< |
| |_IS_| |_NOT_| |_ALPHABETIC_______| |
| |_ALPHABETIC-LOWER_| |
| |_ALPHABETIC-UPPER_| |
| |_class-name_______| |
| |_DBCS_____________| |
| |_KANJI____________| |
| |
|________________________________________________________________________|

identifier-1
Must reference a data item described with one of the following usages:

* DISPLAY, NATIONAL, COMPUTATIONAL-3, or PACKED-DECIMAL when NUMERIC is specified
so the answer to your question is no, you cannot use a NUMERIC test on COMP data fields. Were you attempting to do this and getting a compile error?
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed Dec 17, 2008 7:03 pm
Reply with quote

Hi,

Quoted by robert:

Quote:
identifier-1
Must reference a data item described with one of the following usages:

* DISPLAY, NATIONAL, COMPUTATIONAL-3, or PACKED-DECIMAL when NUMERIC is specified


According to above statement.
IS NUMERIC works for Comp-3.
IS NUMERIC doesn't work for Comp.

I am a bit confused with above statements, why does cobol treat two numeric data types differently. Comp & comp-3 are both numeric data types, its just the storage format which is different for them.

any comments!!!
Thanks,
-Kapil.
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: Wed Dec 17, 2008 7:12 pm
Reply with quote

A COMP variable is always numeric. You cannot have a non-numeric COMP value since it is a 2, 4, or 8 byte field and every possible bit pattern represents a numeric value. Asking if a COMP field is numeric would be like asking if 1 = 1: always gonna be true.

The IS NUMERIC test looks at bit patterns to determine whether or not a variable has numeric bit patterns -- for example COMP-3 fields must have zero through nine in all nibbles (half-bytes) except the last, which must be C, D, or F. An A through F in any nibble except the last is not numeric, so the test would fail -- as it would if the variable had a zero through nine in the last nibble.
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed Dec 17, 2008 7:30 pm
Reply with quote

So, you mean to say that :

Comp can never have any non-numeric values.
Comp-3 can have non-numeric values at times.

I don't know abt Comp but yes, I have seen scenario's where spaces were moved to group level variables and the lower level var were defined as comp-3.

I don't know if the above scenario could be recreated with comp. If we can replicate it on comp. Then we must allow IS NUMERIC on comp fields as well.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Dec 17, 2008 8:04 pm
Reply with quote

Robert,

have fun with Kapil.
I have tried three posts, but none of them passed the
'am I being an asshole with my comments?' test.

I will have to be content with this remark:

IS NUMERIC will indicate if arithmetic instructions can be used against a field w/o error/abend.
Since any possible content of a BINARY field is valid BINARY data,
any arithmetics would be problem free.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Dec 17, 2008 8:31 pm
Reply with quote

Code:
02  WS-GROUP.
   03  WS-COMP   PIC S9(4) COMP.
 

MOVE SPACES TO WS-GROUP.


WS-GROUP now contains two spaces, WS-COMP since it is the same storage location contains a value of x'4040' that is a valid numeric value that is = 16448 in decimal.

Any bit configuration in a COMP (binary) field is valid, it may not be logically correct as used in the program but it is still a valid numeric field.
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed Dec 17, 2008 9:03 pm
Reply with quote

Hi,

I would like to thank all of you for your comments and bearing few of my silly questions.

Sometimes things do get stuck in mind. Finally, Craq Giegerich's post made things crystal clear to me.

Apollogise, if I wasted your time.
Thanks,
-Kapil.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Dec 17, 2008 9:07 pm
Reply with quote

Kapil,

you would have wasted our time had you not responded.

Not only have you responded, apparently you now understand,
and that was our goal.

thx for the feedback.
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: Wed Dec 17, 2008 9:25 pm
Reply with quote

Here's a series of scenarios which could rear their ugly head and raise a false positive.

Examples -

You issue a NUMERIC check against a 4-Byte COMP-3 Signed field, but for some reason, if the sign-nibble is "F", your NUMERIC check will FAIL.

You issue a NUMERIC check against a 4-Byte COMP-3 Unsigned field, but for some reason, if the sign-nibble is valid but is NOT an "F", your NUMERIC check will FAIL.

This same type of mismatched signs can occur for Signed/Unsigned DISPLAY-NUMERIC.

Unreliable sign-nibbles can occur when you have data passed which was created with different PICTURE clauses. So, if you have this situation and the data is questionable, a definition/redefinition of both types of associated PICTURE clauses will allow you to issue a NUMERIC check against both fields and ensure you don't raise the false positive.

COBOL will build and use different translate-tables, based on PICTURE clause definitions during the NUMERIC check. So (for example), sign-nibble "F" validation is not included in the translate-table when a NUMERIC check is issued against a COMP-3 Signed field and instead, the NOT NUMERIC condition will be raised.

HTH....

Regards,

Bill
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 Question for file manager IBM Tools 7
No new posts To search DB2 table based on Conditio... DB2 1
No new posts question for Pedro TSO/ISPF 2
No new posts Convert HEX to Numeric DB2 3
Search our Forums:

Back to Top