MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COMP-3 bytes calculation needed

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Thu Feb 15, 2007 11:29 pm    Post subject: COMP-3 bytes calculation needed Reply with quote

I have a variable defined as below:
Code:

01 A PIC S9(05)V999 COMP-3.     

I am dislaying the length of the variable by using:
Code:

DISPLAY 'LENGTH OF A :' LENGTH OF A.

And the Output is:
Code:

LENGTH OF A :000000005

Now the length is 5 bytes.How is the length calculated as 5 bytes.My understanding is that each digit occupies 0.5 bytes so , 5 + 3 = 8 * 0.5 = 4 bytes since there are 9(05) and 999 so total i am expecting 8 that is why i am multipliying 8 by 0.5.Why should it take 5 bytes as the V does not occupy space and S (Sign) is stored in the last nibble byte.


Please help me in understanding why is it 5 bytes and how should we calculate the bytes for a COMP-3 Variable.
Back to top
View user's profile Send private message
programmer1
Beginner


Joined: 18 Feb 2004
Posts: 138
Topics: 14

PostPosted: Thu Feb 15, 2007 11:41 pm    Post subject: Reply with quote

Quote:

S (Sign) is stored in the last nibble byte


What do we mean by this ?

Any COMP-3 variable would reserve half byte for the sign.
_________________
Regards,
Programmer
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Fri Feb 16, 2007 1:06 am    Post subject: Reply with quote

Thanks for your reply.

So it should take 4 + 0.5(For Sign) = 4.5 bytes totally ,why does it take 5 bytes .Can you please explain me this?
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Feb 16, 2007 4:17 am    Post subject: Reply with quote

you are correct: 4.5 bytes. You can not define a field with 1/2 bytes, the left most 1/2 byte of the 5 is not used.

you round up.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Fri Feb 16, 2007 4:40 am    Post subject: Reply with quote

Thanks Dick,

I am very much clear now and it is wonderful answer from you.

You are great.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12382
Topics: 75
Location: San Jose

PostPosted: Fri Feb 16, 2007 7:44 am    Post subject: Reply with quote

Quote:

Please help me in understanding why is it 5 bytes and how should we calculate the bytes for a COMP-3 Variable.


yadav2005,

You need to get your basics first. Check this link which explains all about COMP items

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3PG10/1.3.4?DT=20020923143836

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Fri Feb 16, 2007 7:47 am    Post subject: Reply with quote

Dick,

I have a question as the storage required bytes is 3 bytes in both the cases.
Code:

01 A PIC 9(04) COMP-3 VALUE 123.
01 B PIC 9(04) COMP-3 VALUE 1234.

Why is it 3 bytes ? My understanding is 4 * .5 = 2 bytes .Since sign is not there we need not add .5 byte to form 2.5 and then round off to 3 bytes .Can u please explain why it is 3 bytes and my understanding is if a COMP-3 variable is declared as signed then the sign is stored on the last 4 bits.

Please help me in understanding how both the variables are stored internally for both A & B.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12382
Topics: 75
Location: San Jose

PostPosted: Fri Feb 16, 2007 7:53 am    Post subject: Reply with quote

yadav2005,

The COMP-3 data items always have the sign whether you define or not.

Also read the links in the above post of mine paying attention to section 1.3.4.7

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vak255
Intermediate


Joined: 10 Sep 2004
Posts: 384
Topics: 79

PostPosted: Fri Feb 16, 2007 3:01 pm    Post subject: Reply with quote

Thats a news for me. good, I need to refresh.
Back to top
View user's profile Send private message
ranga_subham
Intermediate


Joined: 31 Jan 2006
Posts: 255
Topics: 72

PostPosted: Sun Feb 25, 2007 3:17 am    Post subject: Reply with quote

Kolusu,

Quote:

The COMP-3 data items always have the sign whether you define or not.


how to move negative value into a comp-3 field without defining "S" (sign)?

Ex: 9(4) comp-3 - would this hold negative value too?

Please explain.

Thanks.
_________________
Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Sun Feb 25, 2007 6:32 am    Post subject: Reply with quote

Ranga,

PIC 9(4) COMP-3 is telling the compiler, always ignore the sign, value will be treated as positive.

PIC S9(4) COMP-3 is telling the compiler, there is always a valid sign associated with with the value, account for it in all math manipulations and edits.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
ranga_subham
Intermediate


Joined: 31 Jan 2006
Posts: 255
Topics: 72

PostPosted: Fri Mar 09, 2007 2:51 am    Post subject: Reply with quote

Thanks dbzTHEdinosauer. I think, I got it.
_________________
Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Back to top
View user's profile Send private message
Nithisha
Beginner


Joined: 27 May 2006
Posts: 23
Topics: 13
Location: Pune

PostPosted: Fri Mar 09, 2007 6:04 am    Post subject: Comp-3 Calculation Reply with quote

Hi

friend

we calculate the comp-3 by (N/2)+1

where N is number of total byte. So according to you question. You have
S9(5)v999.
Number of byte is 8
calulation : (8/2)+1= 5.

Hence you are getting 5 byte.

some stands what i have come accross for COMP
Code:

9(1) - 9(4) =2 BYTE
9(5)- 9(8) = 4 BYTE
9(9) -9(18)= 8 byte.

thanks
Nithisha
Back to top
View user's profile Send private message AIM Address
naveen
Beginner


Joined: 03 Dec 2002
Posts: 90
Topics: 31

PostPosted: Wed Mar 14, 2007 4:02 am    Post subject: Reply with quote

Starting half byte is Zero Padded in comp-3 in case of even number of bytes.

Example is S9(6) COMP-3 will take 4 bytes.

Number 456789 in COMP-3 , is stored in following manner: 0456789C

Remeber the "0" being padded at the start.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group