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
 

 

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

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

New User


Joined: 13 Apr 2007
Posts: 59
Location: Bangalore

PostPosted: Tue Jul 08, 2008 12:18 pm    Post subject: How much bytes do S9(7)V99 COMP-3 occupy?
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    Post subject:
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

Site Director


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

PostPosted: Tue Jul 08, 2008 1:08 pm    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Jul 08, 2008 7:50 pm    Post subject:
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    Post subject:
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: 4
Location: bangalore

PostPosted: Wed Jul 16, 2008 10:29 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 7909
Location: Bellevue, IA

PostPosted: Fri Jul 18, 2008 8:30 pm    Post subject:
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    Post subject:
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    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 Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Need help to populate date in COMP-3 ... chetanambi DFSORT/ICETOOL 3 Tue Jun 21, 2016 12:25 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
No new posts SIGNED DECIMAL TO COMP-3 using cobol ... ram_vizag COBOL Programming 1 Tue Mar 01, 2016 11:32 pm


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