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
 
Numeric Equivalent to COMP .

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
poul_motiram
Currently Banned

New User


Joined: 05 Dec 2006
Posts: 13
Location: chennai

PostPosted: Wed Dec 20, 2006 12:29 pm    Post subject: Numeric Equivalent to COMP .
Reply with quote

Hi,

I am using

w-s section.
01 var1 pic s9(4) comp.

procedure div.

if var1 is numeric
do something........
end-if.

but it gives error in compilation saying : data type is not compatable with class clause.

i know, for that i need to

move var1 to 'temp'

and then compare it as below

if temp is numeric
do something........
end-if.

what size of 'temp' variable is to be taken i.e.
01 TEMP PIC 9(???).
(while moving there shoudnt be any truncation.)

please expalain how to decide for a given comp variable the equivalent numeric variable.

Regards,
Motiram
Back to top
View user's profile Send private message

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2285
Location: @my desk

PostPosted: Wed Dec 20, 2006 12:37 pm    Post subject:
Reply with quote

Hi Motiram

If you defined the variable var1 as s9(4) COMP, it is supposed to contain numeric data only.Then why do you want to check for numeric data?.

Thanks
ARUN
Back to top
View user's profile Send private message
poul_motiram
Currently Banned

New User


Joined: 05 Dec 2006
Posts: 13
Location: chennai

PostPosted: Wed Dec 20, 2006 12:49 pm    Post subject: Re: Numeric Equivalent to COMP .
Reply with quote

Hi.

give me the procedure to convert into numeric.
don't worry abt the logic in IF stm. its a issue pertaining to my project.

regards,

Motiram
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2285
Location: @my desk

PostPosted: Wed Dec 20, 2006 1:15 pm    Post subject:
Reply with quote

Hi Motiram,

Just Remove the If statement where U checking for the "Is Numeric" . directly write the Logic . Reason for sayng as S9(4) Comp can have numeric value ONLY. Once U remove the If Cluase, U'll not get the error which you are getting.

Directly Use VAR1 for logic. NO NEED TO CHECK FOR NUMERIC CONDITION.

Thanx
Arun.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 965
Location: Richmond, Virginia

PostPosted: Wed Dec 20, 2006 8:13 pm    Post subject:
Reply with quote

Since COMP is binary - any value at all is numeric. Lead bit=0 means positive, 1 means negative using complement arithmetic.
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: Wed Dec 20, 2006 11:06 pm    Post subject:
Reply with quote

Hello,

By definition ALL binary values are numeric.

The lead bit will be the sign or not depending on the picture. 9(4) comp will be only positive values. S9(4) comp may be positive or negative.
Back to top
View user's profile Send private message
sundar28

New User


Joined: 30 Jul 2005
Posts: 12
Location: Mysore

PostPosted: Thu Dec 21, 2006 3:00 am    Post subject: Numeric Equivalent to COMP .
Reply with quote

Hi poul_motiram,

'NUMERIC' condition checks every byte of the data against EBCDIC* code range
for the character set 0-9. And optional decimal point and sign symbols.

All possible values in the EBCDIC byte do not represent Numeric value - so that it can compared
with a predefined subset**.

All possible values in the COMP class repreasent an equivalent numeric value - so its impossible
for COMP class to arrive at a nonnumeric condition.

*ASCII is the other possibility.
**For the table http://www.natural-innovations.com/computing/asciiebcdic.html.

The Logic of the program may changed like comparing the values of the victim variable before
and after the non-numeric data pollutes.

Hi arcvns,

Though a variable is defined as COMP, it can be loaded (of coarse, by miastake) with a non-numeric
value by REDEFINE-ing with a nonnumeriac vriable name. REDEFINE clause overrides the typechecking
capability of the COBOL.

If This is wrong, please correct.
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 Dec 21, 2006 3:11 am    Post subject:
Reply with quote

Hello,

Quote:
Though a variable is defined as COMP, it can be loaded (of coarse, by miastake) with a non-numeric
value by REDEFINE-ing with a nonnumeriac vriable name. REDEFINE clause overrides the typechecking
capability of the COBOL.

If This is wrong, please correct.


To rephrase - a COMP field will ALWAYS be numeric. Redefining the field cannot cause a non-numeric condition regardless of what value is moved into the redefinition. It is simply a binary value. When all of the binary ones and zeros are evaluated, SOME number will result.

As was pointed out in an earlier post, the compiler did not even allow the compare for numeric on the (4) comp field - because the field can only be a number.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2285
Location: @my desk

PostPosted: Thu Dec 21, 2006 10:38 am    Post subject:
Reply with quote

Hi Motiram

Please be more precise on what your problem is.

COMP fields wont allow class test.

Thanks
Arun
Back to top
View user's profile Send private message
santosh_dorge

New User


Joined: 03 Dec 2006
Posts: 8
Location: Mumbai

PostPosted: Thu Dec 21, 2006 7:38 pm    Post subject:
Reply with quote

Hi
I agree to everyone that there is no need to use numeric check but
If you want to convert usage comp to usage display
usage comp use the storage as follows

s9(1) to s9(4) half word
5 to 9 full word
10 to 18 two words

And usage display uses one bye per digit/char
so considering this you can convert comp to usage display
by calculating what the maximum value half word can contain.


Thanks
Santosh
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 File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts Validate if a Value from the file is ... balacsv2 COBOL Programming 8 Mon Jun 19, 2017 11:52 pm

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