IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Computational Fields and the Value it can store.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Chetan Kumar

New User


Joined: 03 Dec 2012
Posts: 46
Location: India

PostPosted: Tue Jul 07, 2015 1:50 pm
Reply with quote

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?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Tue Jul 07, 2015 2:42 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Tue Jul 07, 2015 5:47 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu Jul 09, 2015 10:12 pm
Reply with quote

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.
Back to top
View user's profile Send private message
himanshu_pant

New User


Joined: 08 Jul 2014
Posts: 14
Location: India

PostPosted: Thu Jul 09, 2015 11:01 pm
Reply with quote

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).
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu Jul 09, 2015 11:15 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Chetan Kumar

New User


Joined: 03 Dec 2012
Posts: 46
Location: India

PostPosted: Wed Jul 15, 2015 7:59 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Jul 15, 2015 8:05 pm
Reply with quote

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.
Back to top
View user's profile Send private message
himanshu_pant

New User


Joined: 08 Jul 2014
Posts: 14
Location: India

PostPosted: Wed Jul 15, 2015 10:43 pm
Reply with quote

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).
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SDSF like solution in EJES (store com... All Other Mainframe Topics 4
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
No new posts VSAM ESDS File to store large data 4GB JCL & VSAM 5
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts Converting unpacked fields to pack us... SYNCSORT 4
Search our Forums:

Back to Top