Doubt related to picture clause of a COMP item



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Doubt related to picture clause of a COMP item

Postby upendra_water » Tue May 25, 2010 4:02 pm

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?
upendra_water
 
Posts: 33
Joined: Wed Nov 25, 2009 10:58 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Doubt related to picture clause of a COMP item

 

Re: Doubt related to picture clause of a COMP item

Postby Robert Sample » Tue May 25, 2010 4:29 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Doubt related to picture clause of a COMP item

Postby upendra_water » Tue May 25, 2010 5:53 pm

Thanks a lot Robert for your quick response and clarifying my doubt.
upendra_water
 
Posts: 33
Joined: Wed Nov 25, 2009 10:58 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Doubt related to picture clause of a COMP item

Postby Robert Sample » Tue May 25, 2010 6:00 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Doubt related to picture clause of a COMP item

Postby dick scherrer » Wed May 26, 2010 12:38 am

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
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post