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

How many bytes does comp-3 take?


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

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Sun Apr 29, 2007 5:24 pm
Reply with quote

Hi,

can you please let me know how many bytes will the following take? can you please explain in detail?

1. S9(12)V9(5) COMP-3
2. S9(17)V9(8) COMP-3
3. S9(18)V9(18) COMP-3

will any of these give compilation error?

Thanks in advance,
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: Sun Apr 29, 2007 9:42 pm
Reply with quote

Hello,

For "normal" processing the maximum number of digits is 18 (with the ARITH(EXTEND) compiler option, it may be 31).

To calculate the byte-length of a comp-3 field, start with the total number of digits and divide by 2 giving a result (discarding the remainder if any), then add 1 to the result.

So, a field with "pic s9(6) comp-3" would take 4 bytes (6/2 +1). A field with "pic s9(9) comp-3" would take 5 bytes (9/2 +1) - the .5 remainder is discarded. It does not matter if there are any decimal places - decimal places do not alter the field length, they are just another digit.

Using the above (and the Fine Manual linked to from this site), you can calculate the lengths of your fields and decide which might be valid in which condition(s).

After you do the calculations and look in the Fine Manual, let us know if you have any questions.

As a rule, always define an odd number of digits for a comp-3 item. Defining comp-3 fields with an even number of digits only leads to confusion.
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Sun Apr 29, 2007 11:29 pm
Reply with quote

Thanks a lot for this. It was relly helpful
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: Mon Apr 30, 2007 12:38 am
Reply with quote

You're welcome icon_smile.gif

What did you decide were your 3 answers? If you tell me yours, i'll tell you mine icon_smile.gif
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Mon Apr 30, 2007 4:51 pm
Reply with quote

I think 2 and 3 would give compilation error and the first one would take 9 bytes. please correct me if I am wrong.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Apr 30, 2007 5:12 pm
Reply with quote

Vedam,

Good. icon_smile.gif
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: Mon Apr 30, 2007 7:24 pm
Reply with quote

Hello,

One clarification - depending on the ARITH compiler option setting, this
"2. S9(17)V9(8) COMP-3" may or may not compile successfully.

Normally, the EXTEND is not used, so your assessment is on target icon_smile.gif
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