Home > Archive > Cobol > September 2004 > Comp-5 Type storage
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Comp-5 Type storage
|
|
|
| Hi,
I have been trying to figure out what the storage repn. for comp-5
types is. IBM z/os docs says that they contain values upto the
capacity of the native binary representation rather than being implied
by the number of 9's in the pic clause.
Does this mean that a comp-5 type has a fixed size specific to a
certain system .for example 4 bytes if the machine addressing is 4
bytes.
Or does it mean that the size varies with the data being put into it.
For example 12345 in hex is 3039 so we need only 2 bytes. If there is
a larger value then comp-5 stores it in 4 bytes and so on...
Regards,
Ed
| |
| JerryMouse 2004-09-02, 3:55 pm |
| Ed wrote:
> Hi,
>
> I have been trying to figure out what the storage repn. for comp-5
> types is. IBM z/os docs says that they contain values upto the
> capacity of the native binary representation rather than being implied
> by the number of 9's in the pic clause.
>
> Does this mean that a comp-5 type has a fixed size specific to a
> certain system .for example 4 bytes if the machine addressing is 4
> bytes.
>
> Or does it mean that the size varies with the data being put into it.
> For example 12345 in hex is 3039 so we need only 2 bytes. If there is
> a larger value then comp-5 stores it in 4 bytes and so on...
>
> Regards,
> Ed
Obviously you can't put ten pounds (kilograms) of stuff in a five pound
(kilogram) bag. So you already know the outer limit of capacity.
Your example, 12345, will fit in two bytes. However, 98765 will not. These
numbers, 12345 and 98765 come into being at EXECUTION time whereas storage
allocation takes place at COMPILE time.
In general, you can define a variable as 9(4) at compile time and put a
5-digit number in that field at execution time (using several stratagies),
but it's up to you to make sure the source number does not exceed the
carrying-capacity of the field.
There are compiler directives that manipulate these rules. There are
compiler actions that fiddle with the numbers at execution time. There is no
universal standard inasmuch as the rules and actions depend on both the
compiler in use and the platform. Trust me, what you ask is a complicated
and arcane expedition down into the weeds.
Let me ask you a question: Why do you ask? There may be a simpler way of
attacking the problem that generated your question.
| |
| Robert Wagner 2004-09-02, 3:55 pm |
| On 2 Sep 2004 05:14:20 -0700, ed_narayanan@yahoo.com (Ed) wrote:
>I have been trying to figure out what the storage repn. for comp-5
>types is. IBM z/os docs says that they contain values upto the
>capacity of the native binary representation rather than being implied
>by the number of 9's in the pic clause.
It means whatever the compiler manual says it means. It's not in the
standard.
On compilers that try to be compatible with IBM -- Micro Focus,
Fujitsu and Realia, maybe others -- it means 1, 2, 4 or 8 bytes,
depending on the picture (and compiler options).
>Does this mean that a comp-5 type has a fixed size specific to a
>certain system .for example 4 bytes if the machine addressing is 4
>bytes.
Yes.
>Or does it mean that the size varies with the data being put into it.
>For example 12345 in hex is 3039 so we need only 2 bytes. If there is
>a larger value then comp-5 stores it in 4 bytes and so on...
No.
|
|
|
|
|