View previous topic :: :: View next topic

Author 
Message 
ram_vizag
New User
Joined: 21 Aug 2008 Posts: 90 Location: hyd




Hi,
suppose if i declare a field in db2 table with decimal data type
field decimal(9,2) in a table,
1)how many bytes it will take in db2 and how many bytes it will take in cobol??
2) In COBOL, above declaration would result in 9(9)V2 or 9(7)v2.
Kindly clarify.
Ram 

Back to top 




Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA




It's most likely 5Bytes packeddecimal with two implied decimal points.
This is similar to a PL/I definition.
COBOL would be S9(07)V99 COMP3.
HTH....
Mr. Bill 

Back to top 


dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix




Hello,
Quote: 
1)how many bytes it will take in db2 and how many bytes it will take in cobol?? 
Why would you think the number of bytes would not be the same every this was used? If you have a field that takes 5 or 7 or 9 bytes in a file, how could it ever differ by programming language or tool usage?
Data is the same regardless of where used  it cannot be otherwise. Imaging the disaster if the sort created 7 bytes and Easytrieve believed the length was 5.
Possibly i misunderstand the concern. . . 

Back to top 


enricosorichetti
Global Moderator
Joined: 14 Mar 2007 Posts: 10176 Location: italy


Back to top 


Manish Prabhakar Gokhare
New User
Joined: 20 Aug 2011 Posts: 3 Location: INDIA


Back to top 


jerryte
Active User
Joined: 29 Oct 2010 Posts: 183 Location: Toronto, ON, Canada




When a column is defined as DECIMAL(#,#) then the first number is the total number of digits including the ones to the right of the decimal point. The second number is the number of digits to the right of the decimal point. So the number of digits to the left of the decimal point is the first number minus the second number.
Thus the largest number that can be stored in DECIMAL(9,2) is 9999999.99 (there are 7 digits to the left and 2 digits to the right).
In COBOL this is a packed decimal field which uses 1 byte for every 2 digits plus an extra nibble (half a byte) for the sign. It is recommended to use an odd number as the precision so that you can make best use of the total bytes allocated.
For DECIMAL(9,2) the cobol field is PIC S9(7)V99 COMP3.
The DB2 SQL Reference manual chapter 2 has a section on Data Types. 

Back to top 


