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

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


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
guruji
Warnings : 1

New User


Joined: 13 Apr 2007
Posts: 59
Location: Chennai

PostPosted: Tue Jul 08, 2008 12:18 pm
Reply with quote

Hi,
Could you please tell me How much bytes do S9(7)V99 COMP-3 occupy?
could you please explain the same?
Thanx,
reni
Back to top
View user's profile Send private message
radha reddy

New User


Joined: 15 May 2008
Posts: 9
Location: hyderabad

PostPosted: Tue Jul 08, 2008 1:08 pm
Reply with quote

It occupies 5 bytes.

no of 9's = 9
(9+1)/2 = 5
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Jul 08, 2008 1:08 pm
Reply with quote

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

New User


Joined: 11 Jun 2008
Posts: 1
Location: Beijiing

PostPosted: Tue Jul 08, 2008 3:36 pm
Reply with quote

Hi dick,

So you mean the sign also occupys one byte, do you?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jul 08, 2008 3:47 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Tue Jul 08, 2008 7:50 pm
Reply with quote

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

New User


Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

PostPosted: Thu Jul 10, 2008 11:21 am
Reply with quote

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

New User


Joined: 15 Jul 2008
Posts: 3
Location: bangalore

PostPosted: Wed Jul 16, 2008 10:29 am
Reply with quote

The formula for it is INT(N/2+1)
Back to top
View user's profile Send private message
radha reddy

New User


Joined: 15 May 2008
Posts: 9
Location: hyderabad

PostPosted: Wed Jul 16, 2008 11:08 am
Reply with quote

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

New User


Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

PostPosted: Wed Jul 16, 2008 12:27 pm
Reply with quote

Hi Radha

I feel both of them are correct.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 16, 2008 1:02 pm
Reply with quote

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

New User


Joined: 15 May 2008
Posts: 9
Location: hyderabad

PostPosted: Wed Jul 16, 2008 1:07 pm
Reply with quote

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

New User


Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

PostPosted: Wed Jul 16, 2008 1:10 pm
Reply with quote

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

New User


Joined: 09 Jan 2007
Posts: 20
Location: Mumbai

PostPosted: Wed Jul 16, 2008 8:42 pm
Reply with quote

Hi radha,

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

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jul 16, 2008 9:16 pm
Reply with quote

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

New User


Joined: 16 Jul 2008
Posts: 5
Location: Tennessee

PostPosted: Fri Jul 18, 2008 1:18 am
Reply with quote

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

New User


Joined: 02 Jun 2008
Posts: 87
Location: Bangalore

PostPosted: Fri Jul 18, 2008 8:22 pm
Reply with quote

Quote:

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


Is this
(In Hex) 4D2 ? . Please clear me .
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: Fri Jul 18, 2008 8:30 pm
Reply with quote

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

New User


Joined: 02 Jun 2008
Posts: 87
Location: Bangalore

PostPosted: Fri Jul 18, 2008 8:45 pm
Reply with quote

Robert ,

Understood .. Thax
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
Search our Forums:

Back to Top