how much length will s9(6)v9 occupy ?
-
- Registered Member
- Posts: 22
- Joined: Thu Mar 17, 2016 9:54 pm
- Robert Sample
- Global Moderator
- Posts: 1900
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: how much length will s9(6)v9 occupy ?
COBOL has different formats for numbers -- binary (COMP), packed decimal (COMP-3), and zoned decimal. The length will depend upon which format is used.
-
- Registered Member
- Posts: 22
- Joined: Thu Mar 17, 2016 9:54 pm
- Robert Sample
- Global Moderator
- Posts: 1900
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: how much length will s9(6)v9 occupy ?
The V in a PICTURE is an IMPLIED decimal point -- as in, it does not exist in the data. When moving numeric data around, COBOL aligns to the decimal point and the V will be important for that. S9(6)V9 COMP-3 will require 4 bytes. COMP-3 stores two decimal digits in each byte except for the last one, which has one decimal digit and the half-byte sign.
-
- Registered Member
- Posts: 22
- Joined: Thu Mar 17, 2016 9:54 pm
Re: how much length will s9(6)v9 occupy ?
Thanks.
Why COBOL is so rigid, can not the use of the variable be used to define the type of variable?
Why COBOL is so rigid, can not the use of the variable be used to define the type of variable?
- Robert Sample
- Global Moderator
- Posts: 1900
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: how much length will s9(6)v9 occupy ?
COBOL dates back to 1959. z/OS dates back to OS/360 in 1964. IBM is strongly committed to backward compatibility so things that worked in 1965 will still work on a z16 today. COBOL's processing rules were defined in a totally different environment and while it has been extended to include object-oriented, JSON, and XML (to name a few) the original parts of COBOL still work as they did. COBOL supports a dozen or more types of variables, and there's no convention in place for telling the type of variable (other than looking at the PICTURE clause for it).
Re: how much length will s9(6)v9 occupy ?
In general, most compiled languages tend to use pre-declared variables in some form whereas interpretters are more inclined towards using an ad-hoc definition-on-use declaration system. Yes, languages like C or Java may express their variable declarations in a simpler manner than COBOL, but they still use strictly pre-determined types.
As for COBOL and rigidity, it's a matter of perspective. While the language may appear to be a colossal pain in the backside when you start using it, it's actually extremely good at what it does which is expressing business ideas. As someone who has written a report program in C, I can attest to the fact that it is nowhere near as easy to perform that task in that lanuguage compared to doing it in COBOL. What may appear to be rigid ideas can actually be incredibly helpful. For example, moving a number to a field defined as "ZZZ,ZZZ,ZZ9.99" results in a nicely formatted human-friendly presentation without having to do a whole lot of work to get there.
As for COBOL and rigidity, it's a matter of perspective. While the language may appear to be a colossal pain in the backside when you start using it, it's actually extremely good at what it does which is expressing business ideas. As someone who has written a report program in C, I can attest to the fact that it is nowhere near as easy to perform that task in that lanuguage compared to doing it in COBOL. What may appear to be rigid ideas can actually be incredibly helpful. For example, moving a number to a field defined as "ZZZ,ZZZ,ZZ9.99" results in a nicely formatted human-friendly presentation without having to do a whole lot of work to get there.
-
- Registered Member
- Posts: 22
- Joined: Thu Mar 17, 2016 9:54 pm
Re: how much length will s9(6)v9 occupy ?
What does implied mean? It should either be there or not, why it's just implied? How does that help?
Re: how much length will s9(6)v9 occupy ?
The implied decimal helps with packed decimal representation where there is no decimal point present in the data. The same is true for binary coded decimal but it can also be used on text-based numbers (if you're looking to save space). However, I'll concentrate on packed since that is where you are more likely to find implied decimal point being used.
Packed decimal consists of up to 31 digits encoded as half-byte values plus a sign which will usually be "C" for positive or "D" for negative (although there are other valid values). For example, +123.45 in a four-byte packed format would be defined as "S9(5)V99" and come out as "0012345C" in hex. The underlying data format has no way of saying where the decimal point is because it is not actually necessary in order to perform decimal arithmetic.
There comes a point at which that data has to be presented to the user and the position of the decimal point then becomes relevant. The implied decimal provides a means of identifying where the decimal point belongs even though it does not actually exist within the data. If, for instance, we needed to move the "S9(5)V99" representation of 123.45 to a field defined as "ZZ,ZZ9.99", the compiler will generate code to produce the correct output; if the implied decimal is not there (i.e. "S9(7)"), we'd get "12,345.00" instead.
Packed decimal consists of up to 31 digits encoded as half-byte values plus a sign which will usually be "C" for positive or "D" for negative (although there are other valid values). For example, +123.45 in a four-byte packed format would be defined as "S9(5)V99" and come out as "0012345C" in hex. The underlying data format has no way of saying where the decimal point is because it is not actually necessary in order to perform decimal arithmetic.
There comes a point at which that data has to be presented to the user and the position of the decimal point then becomes relevant. The implied decimal provides a means of identifying where the decimal point belongs even though it does not actually exist within the data. If, for instance, we needed to move the "S9(5)V99" representation of 123.45 to a field defined as "ZZ,ZZ9.99", the compiler will generate code to produce the correct output; if the implied decimal is not there (i.e. "S9(7)"), we'd get "12,345.00" instead.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute