Computational Fields and the Value it can store.

Author Message
Chetan Kumar

New User

Joined: 03 Dec 2012
Posts: 42
Location: India

 Posted: Tue Jul 07, 2015 1:50 pm We all know that PIC S9(4) COMP consumes 2 bytes of memory. But the maximum value it can store (i.e. +32767) and why is it not possible to store greater value then this +32767 ? I mean why not +92767?
Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7311
Location: Inside the Matrix

 Posted: Tue Jul 07, 2015 2:42 pm Find out what +92767 is in hex and you'll have the answer to that part. In COBOL, with a USAGE of COMP/COMP-4/BINARY (they are all the same, just synonyms to the compiler) the maximum value that can be held in a PIC 9(4) field is 9999 and the minimum is zero. In a PIC S9(4) the maximum value is +9999 and the minimum is -9999. Now, with a USAGE of COMP-5 (native binary) the maximum is 65535 and minimum is zero, and +32767 and -32768 (for unsigned and signed fields respectively). The effect of COMP-5 can be applied to all binary USAGEs by specifying compiler option TRUNC(BIN). This is a bad thing to do. So for a COBOL binary the maxima are limited by the PICture. For a native binary, the maxima are limited by the bits, the number of bits in a field being to do with the PICture. A PICture of 1-4 digits is a two-byte field, 5-9 a four-byte field, 10-18 an eight-byte field.
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8569
Location: Dubuque, Iowa, USA

 Posted: Tue Jul 07, 2015 5:47 pm There is a very good write up in the Enterprise COBOL Language Reference manual on the internal representation of data. If you find and read this material, you will learn much that you need to know about COBOL.
Rohit Umarjikar

Global Moderator

Joined: 21 Sep 2010
Posts: 2573
Location: NYC,USA

 Posted: Thu Jul 09, 2015 10:12 pm In computer architecture, 16-bit integers, memory addresses, or other data units are those that are at most 16 bits (2 octets) wide. Also, 16-bit CPU and ALU architectures are those that are based on registers, address buses, or data buses of that size. 16-bit is also a term given to a generation of microcomputers in which 16-bit microprocessors were the norm. A 16-bit register can store 2 * 16 different values. The signed range of integer values that can be stored in 16 bits is -32,768 through 32,767 (unsigned: 0 through 65,535). Hence, a processor with 16-bit memory addresses can directly access 64 KiB of byte-addressable memory.
himanshu_pant

New User

Joined: 08 Jul 2014
Posts: 14
Location: India

 Posted: Thu Jul 09, 2015 11:01 pm Sign is stored in Most significant bit in case of binary. Hence 15 1s(111 1111 1111 1111) in 2-byte binary make the maximum value = +32767).
Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7311
Location: Inside the Matrix

 Posted: Thu Jul 09, 2015 11:15 pm Bearing in mind that the answer to the question is +9999 as the maximum and -9999 as the minimum, I think we're sliding into repetition and unclarity.
Chetan Kumar

New User

Joined: 03 Dec 2012
Posts: 42
Location: India

 Posted: Wed Jul 15, 2015 7:59 pm Himanshu, I agree with you. As sign is stored in most significant bit it will utilize a bit and rest 15 binary bits leads to a value of 32767. Thank you.
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8569
Location: Dubuque, Iowa, USA

 Posted: Wed Jul 15, 2015 8:05 pm Himanshu: you are giving the maximum possible value. COBOL limits variables to the PICTURE size unless a compiler option is set. Hence the value will be 9999 not 32767 unless the compiler option is changed.
himanshu_pant

New User

Joined: 08 Jul 2014
Posts: 14
Location: India

 Posted: Wed Jul 15, 2015 10:43 pm Sure Robert. I had also faced this issue a while back. Then I had to include TRUNC(BIN) cobol compiler option in my program to resolve the problem. Chetan, This maximum value only applies to S9(4) COMP variables if the TRUNC(BIN) cobol complier option is in effect. If not, then the value is delimited by the number of 9s in the PICture clause (+9999 max and -9999 min). Bill has also explained everything clearly in his reply (use of COMP-5 as well).
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Break a record into fields, each fiel... SYNCSORT 2 FIELDS OVERLAPPING WITH MODE = IN OR ... CICS 3 Sort on different fields, removing du... SYNCSORT 8 Please help - SORT with SUM fields an... DFSORT/ICETOOL 6 Need a Macro to compare datasets and ... All Other Mainframe Topics 2
Search our Forums:

 © 2003-2021  IBM MAINFRAMES Software & Support Division Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us