Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
Chetan Kumar

New User

Joined: 03 Dec 2012
Posts: 42
Location: India

 Posted: Tue Jul 07, 2015 1:50 pm    Post subject: Computational Fields and the Value it can store. 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

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Tue Jul 07, 2015 2:42 pm    Post subject: Reply to: Computational Fields and the Value it can store. 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: 8417
Location: Dubuque, Iowa, USA

 Posted: Tue Jul 07, 2015 5:47 pm    Post subject: 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

Senior Member

Joined: 21 Sep 2010
Posts: 2105
Location: NY,USA

 Posted: Thu Jul 09, 2015 10:12 pm    Post subject: 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    Post subject: Reply to: Computational Fields and the Value it can store. 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

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Thu Jul 09, 2015 11:15 pm    Post subject: Reply to: Computational Fields and the Value it can store. 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    Post subject: 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: 8417
Location: Dubuque, Iowa, USA

 Posted: Wed Jul 15, 2015 8:05 pm    Post subject: 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    Post subject: Reply to: Computational Fields and the Value it can store. 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).
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Query on summing up the fields abdulrafi DFSORT/ICETOOL 10 Mon Jan 21, 2019 7:18 pm remove the gap b/w 2 fields shymala COBOL Programming 5 Thu Aug 02, 2018 12:05 pm Comparing Comp-3 fields with greater ... Prateeksichem1 DFSORT/ICETOOL 11 Fri Jul 13, 2018 8:45 am KSDS file fields update by passing va... Anil Kumar Prajapati TSO/ISPF 5 Wed Jul 11, 2018 5:59 am Need an info to store Hexadecimal val... SENTHIL MURUGAAN DB2 5 Wed Jun 13, 2018 12:18 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us