# How much bytes do S9(7)V99 COMP-3 occupy?

Author Message
guruji
Warnings : 1

New User

Joined: 13 Apr 2007
Posts: 59
Location: Chennai

 Posted: Tue Jul 08, 2008 12:18 pm Hi, Could you please tell me How much bytes do S9(7)V99 COMP-3 occupy? could you please explain the same? Thanx, reni

New User

Joined: 15 May 2008
Posts: 9

 Posted: Tue Jul 08, 2008 1:08 pm It occupies 5 bytes. no of 9's = 9 (9+1)/2 = 5
dick scherrer

Moderator Emeritus

Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

Posted: Tue Jul 08, 2008 1:08 pm

Hello,

5 bytes.

 Quote: There are 2 digits for each character position, except for the trailing character position, which is occupied by the low-order digit and the sign.
The quote is from the COBOL Language Reference available via the IBM Manuals link at the top of the page.
shakawa

New User

Joined: 11 Jun 2008
Posts: 1
Location: Beijiing

 Posted: Tue Jul 08, 2008 3:36 pm Hi dick, So you mean the sign also occupys one byte, do you?
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

 Posted: Tue Jul 08, 2008 3:47 pm Dick, it would be so much easier for the OP if you would just teach him what he needs to learn. Apparently he can web-browse only this site - thus no access to a site like IBM, where he could actually learn something on his own. he could learn something here if he would search... but, again, easier to ask than look.
dick scherrer

Moderator Emeritus

Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

Posted: Tue Jul 08, 2008 7:50 pm

Hello shakawa and welcome to the forums,

 Quote: So you mean the sign also occupys one byte, do you?
No, the sign in a packed-decimal (comp-3) number occupies the low-order nibble (1/2 byte) of the low order byte.

All of the information is available in the COBOL documentation i mentioned before (linked via "IBM Manuals" at the top of the page).
surya.kalyan

New User

Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

 Posted: Thu Jul 10, 2008 11:21 am Here is a short representation of how data is stored in comp-3 fields. ASSUME THE PICTURE CLAUSE IS 9(4) COMP-3. Number of bytes = (4+1)/2 = 3 (rounded). So, At Max 4 digits can be accomodated. If the number is +1234.It is stored as, (In Hex) 01 23 4C If the number is -1234.It is stored as, (In Hex) 01 23 4D C for + sign and D for -sign. If the number is +123. It is stored as (In Hex) 00 12 3C If the number is -123. It is stored as (In Hex) 00 12 3D. One byte will store two digits. And the sign is stored in the last nibble. We cannot allocate nibbles(half byte). So, thats the reason for the formula (n+1)/2. Suggest or correct me if I am wrong somewhere.
hanucob

New User

Joined: 15 Jul 2008
Posts: 3
Location: bangalore

 Posted: Wed Jul 16, 2008 10:29 am The formula for it is INT(N/2+1)

New User

Joined: 15 May 2008
Posts: 9

 Posted: Wed Jul 16, 2008 11:08 am Hi Hanucob, There is correction to your formula. For comp-3 formula is (N+1)/2 Sign byte occupies only 1/2 byte. Thanks, Radha
surya.kalyan

New User

Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

 Posted: Wed Jul 16, 2008 12:27 pm Hi Radha I feel both of them are correct.
dbzTHEdinosauer

Global Moderator

Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

Posted: Wed Jul 16, 2008 1:02 pm

surya.kalyan,

 Quote: ASSUME THE PICTURE CLAUSE IS 9(4) COMP-3. Number of bytes = (4+1)/2 = 3 (rounded

since your picture clause does not include a sign, a lot of your explanation was incorrect: there is no way you could store a negative value in that field.

other than that, you post was pretty good.

New User

Joined: 15 May 2008
Posts: 9

 Posted: Wed Jul 16, 2008 1:07 pm Hi Surya, For S9(7)V99 COMP-3 When we use N/2+1 we will have 9/2 = 4.5 4.5 + 1 = 5.5 rounding off will give 6 bytes When we use formula (N + 1)/2 We will get (9+1)/2 = 10/2 = 5 bytes. So (N+1)/2 or (N/2 +1/2) is the correct formula. Correct me if I am wrong. Thanks, Radha
surya.kalyan

New User

Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

Posted: Wed Jul 16, 2008 1:10 pm

 Quote: S9(4) COMP-3. since your picture clause does not include a sign, a lot of your explanation was incorrect: there is no way you could store a negative value in that field.

Yup, it should have been S9(4) COMP-3.
surya.kalyan

New User

Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

Posted: Wed Jul 16, 2008 8:42 pm

 Quote: The formula for it is INT(N/2+1)

INT is not rounding off.
Its extracting integer portion of a decimal number.

So,
INT(4.5) = 4 and not 5.

So, the formula is right according to me.
ashimer

Active Member

Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

 Posted: Wed Jul 16, 2008 9:16 pm You can use both ... if you are using N/2 + 1 then take only the integer part and if you are using (N+1) / 2 then roundoff ... use both on S9(7)v99 and S9(10)v99 and see ..... physically sign occupies only half a byte ...
Tom Goodhart

New User

Joined: 16 Jul 2008
Posts: 5
Location: Tennessee

 Posted: Fri Jul 18, 2008 1:18 am Not coding the S for sign in the picture will cause values to be stored with "F" as the sign. An positive integer value which mathematically equal to +1. If you code an even number of digits, the compiler will always make it 1 byte larger internally. Thus, S9(6) COMP-3 will take 4 bytes of storage S9(7) COMP-3 will take 4 bytes of storage This is the preferred way as it is clear to anyone what was intended.
Gousiya Mulla

New User

Joined: 02 Jun 2008
Posts: 87
Location: Bangalore

Posted: Fri Jul 18, 2008 8:22 pm

 Quote: If the number is +1234.It is stored as, (In Hex) 01 23 4C

Is this
(In Hex) 4D2 ? . Please clear me .
Robert Sample

Global Moderator

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

 Posted: Fri Jul 18, 2008 8:30 pm No: Hex 0004D2 is the BINARY (or COBOL COMP) value of +1234. Hex 01234C is the PACKED-DECIMAL (or COBOL COMP-3) value of +1234. Hex F1F2F3F4 is the unsigned COBOL DISPLAY value of 1234. Hex F1F2F3C4 is the signed COBOL DISPLAY value of +1234.
Gousiya Mulla

New User

Joined: 02 Jun 2008
Posts: 87
Location: Bangalore

 Posted: Fri Jul 18, 2008 8:45 pm Robert , Understood .. Thax
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2 Interviewers are surprised with my an... Mainframe Interview Questions 6 Cobol COMP-2 fields getting scrambled... Java & MQSeries 3 convert alphanumeric PIC X(02) to hex... COBOL Programming 3 total number of bytes PL/I & Assembler 10
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us