Number Formats
Question: I have one question regarding computational fields. Which is the better one, is it comp or comp-3? Look For The Below Example :
77 B PIC S9(4) USAGE IS COMP-3. (USING 3 BYTES)
Result : If you look in the above coding comp-3 is the better one.
77 B PIC S9(10) USAGE IS COMP-3. (USING 6 BYTES)
Result : If you look in the above coding comp is the better one.
I want to know that which one is the better one, when
> compare to the other.
ganapathy
Answer:
77 A PIC 9(10) USAGE IS COMP. --- you said 8 bytes but this only uses 2 bytes and wastespart of one of the two it is using as you need to specfy 9(15) to access the full 2 bytes.
- comp-3 fields should always be specified using odd numbers. Using even numbers as you have wastes half a byte for each field. The field size in bytes will always be the number of digits in the largest allowed number plus one divided by two.
- comp fields should always be specifed using 15 or 31 as they only come in 2 and 4 byte varieties allowing numbers up to 65536 and 4292 millon respectively.
Which is best depends on what you are doing with it and whether you want decimal or binary numbers. If you mean which uses less space then storing in binary format using comp uses less space for any mumber bigger than 999. If you mean which is more readable when working with a program dump then comp-3 allows you to read the value directly rather than having to convert from hexadecimal.


