View previous topic :: View next topic
|
Author |
Message |
Vedam
New User
Joined: 24 Apr 2007 Posts: 23 Location: India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Vedam
New User
Joined: 24 Apr 2007 Posts: 23 Location: India
|
|
|
|
Thanks a lot for this. It was relly helpful |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
What did you decide were your 3 answers? If you tell me yours, i'll tell you mine |
|
Back to top |
|
|
Vedam
New User
Joined: 24 Apr 2007 Posts: 23 Location: India
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Vedam,
Good. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
|