Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Computational Fields and the Value it can store.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Chetan Kumar

New User


Joined: 03 Dec 2012
Posts: 35
Location: India

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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Tue Jul 07, 2015 2:42 pm    Post subject: Reply to: Computational Fields and the Value it can store.
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: 7909
Location: Bellevue, IA

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

Senior Member


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

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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Jul 09, 2015 11:15 pm    Post subject: Reply to: Computational Fields and the Value it can store.
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: 35
Location: India

PostPosted: Wed Jul 15, 2015 7:59 pm    Post subject:
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: 7909
Location: Bellevue, IA

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

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts Need Help to Define 36 Input Fields (... satish.ms10 CLIST & REXX 2 Sat May 07, 2016 3:08 pm
No new posts FileAid to compare(logical operations... anand1204 Compuware & Other Tools 3 Wed Apr 06, 2016 2:55 am
No new posts Fields in File-Aid Browse menu screen boyti ko Compuware & Other Tools 5 Mon Apr 04, 2016 4:51 pm
No new posts SUM FIELDS=NONE with INCLUDE kranthikumarb DFSORT/ICETOOL 17 Mon Dec 28, 2015 12:18 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us