Page 1 of 1

Doubt related to picture clause of a COMP item

PostPosted: Tue May 25, 2010 4:02 pm
by upendra_water
I have following doubt regarding COMP items.
In a famous COBOL book which is reffered by many programmers I found below description about COMP items.
Book name is: COBOL PROGRAMMING (2nd Edition)
Author Name: M K ROY, D GHOSH DASTIDAR
COMP item is described there on page no. 127 as follows:
"When usage is specified as COMP, the numeric data item is represented in pure binary. The item must be in integer (no assumed decimal point is allowed). Such data items are often used as subscripts. Depending on the size of the data item, it can be stored either in half-word or in full-word (32 bits). Only integral numbers in the range -32768 to +32767 can be accomodated in half word. A full word can store any integral number in the range -2147483648 to 2147483647. The picture of a COMP item should not contain any character other than 9,S."

I have coded a test program wherein I have defined a variable as PIC S9(2)V99 COMP. I moved non-integer value to this variable e.g. 30.56. The job completed successfully and I am able to view this value 30.56 populated correctly in this variable.
So my Question is can COMP items contain decimal part?

Re: Doubt related to picture clause of a COMP item

PostPosted: Tue May 25, 2010 4:29 pm
by Robert Sample
The book quote you reference is contradicted by the COBOL Language Reference manual, section 5.3.17.1 which says
The PICTURE of a computational item can contain only:

9
One or more numeric character positions

S
One operational sign

V
One implied decimal point

P
One or more decimal scaling positions
In the case of such a conflict, I would be guided by what the manual says.

Re: Doubt related to picture clause of a COMP item

PostPosted: Tue May 25, 2010 5:53 pm
by upendra_water
Thanks a lot Robert for your quick response and clarifying my doubt.

Re: Doubt related to picture clause of a COMP item

PostPosted: Tue May 25, 2010 6:00 pm
by Robert Sample
And actually, the book is wrong in another respect. A COMP variable can be 2 bytes (half-word), 4 bytes (full-word), or 8 bytes (double-word). PIC 9(10) through 9(18) are double words.

Re: Doubt related to picture clause of a COMP item

PostPosted: Wed May 26, 2010 12:38 am
by dick scherrer
Hello,

Regardless of which text book or other study material is available, i'd suggest making sure you have the link to the COBOL Language Reference and Progrmming Guide handy (actually downloading a copy periodically works well for me) as you should use these manuals often.

For Enterprise COBOL
Language Reference:
http://publibz.boulder.ibm.com/cgi-bin/ ... 0/CONTENTS

Programming Guide:
http://publibz.boulder.ibm.com/cgi-bin/ ... 0/CONTENTS