I might have found some inconsistenties. If some of these are expected, please write so in a comment. I am learning COBOL.
Here they are:
:::cobolfree
01 foo pic a(2) value '""' *> gives warning
01 foo pic a(2) value quotes *> doesn't.
I'd expect them to both have the same behaviour
:::cobolfree
01 foo pic a(2) value zero *> gives error
01 foo1 pic a(2) value 0 0 *> gives warning.
I'd expect them to both have the same behaviour
:::cobolfree
01 foo pic 9(2) value all 2 *> gives error
add all 2 to foo *> doesn't.
01 foo pic 9(2) value 22 *> doesn't.
I'd expect them to all have the same behaviour
:::cobolfree
01 foo pic 9(2)v9(2) value all 11 *> gives error
01 foo pic 9(2)v9(2) value all '11' *> doesn't.
I'd expect them to both have the same behaviour
:::cobolfree
1 boo.
2 boo2 pic 9(2)v9(2) value all '#'.
display boo. *> ####
display boo2. *> ##.00
I would expect both items to be consistent on whether the decimal part has been populated or no.
:::cobolfree
if person is equal to 0 display "#" *> Compiles.
if person is equal to to 0 display "#" *> Compiles!
if person is equal to to to 0 display "#" *> Compilation error
:::cobolfree
multiply "foo" by "foo" *> Error not numetic type.
Same for all math operations except of:
:::cobolfree
divide "foo" by "foo" *> Not error.
I'd expect all math operations to either work or not work with non numeric items/literals.
Starting at the top :
You used simgle quotes and default (unless changed) uses double so hence the error.
What version of the compiler are you using and what platform ?
Hi, I use this image: hurriedreformist/gnucobol:3.1-builder
Regarding the answers, I cant say I understood them unfortunately... I do not mean to be pedantic, but I would really love an explanation so as to know how to proceed with the IDE syntax highlighting in these cases.
value quotes fills item with "", value '""' gives warning, although string literals can be wrapped either in " or '. So one would expect '""' to be no differnet than 'foo'. In short, is '""' not an OK string literal?
Yes, it is alphabetic, so value 00 correctly gives a warning, in the same way that all "non-matching" initial values give warnings (for example value "foo" to a numeric). So it is inconistent that only value zero gives an error.
I agree, it is weird to write that, but in case someone does, why does value all 2 give an error and value 22 doesnt? Isnt a literal that got constructed by a figurative constant (all 2) the same as the "normal" literal value 22?
I am not sure it is the same issue, let me try to phrase that better: It is unclear to me what is wrong with filling a decimal numeric with all 11, while it is OK to fill it with all "11"
Also the second and third from the bottom (boo2 pic 9(2)v9(2) value all '#' and if person is equal to to 0 display) did not get a reply.
Thanks :)
Last edit: Nikos Papageorgiou 2020-07-16
Simply put -
Please read the Programmers Guide manual regarding data fields and the rules for moving data.
But in a nut shell -
You must only use numbers when moving to a numeric field.
You must only use alphabetic characters when moving to a Alpha field (A).
If the field might hold any thing other than A to Z or a to z then set the field type to X.
When using numeric field (99) etc, you can only use a number 0 to 9, - (for minus), " . " (period/full stop to indicate a edited decimal point).
Any thing else read the rules for moving data.
You can also read any good book on Cobol.
It seems like we do not speak of the same things.
I am aware of these basic things. I do not contest them.
What I write is that for some cases the behaviour of the compiler is inconsistent. It is surprising. It treats seemingly same scenarios as different.
For example, the point:
01 foo pic a(2) value zero gives error
01 foo1 pic a(2) value 0 0 gives warning.
I d expect them to both have the same behaviour
is not contesting any of the rules about what data can be assigned to what type. Thats not the point. The point is that it reveals an inconsintency. Same as all the other issues.
You say
I agree. That is why one of the things I report is that:
01 foo pic 9(2)v9(2) value all 11 gives error
01 foo pic 9(2)v9(2) value all '11' doesn't.
I d expect them to both have the same behaviour
And so on. I am, pointing out inconsistenties. I am pointing out cases the compiler behaves surprisingly considering the rules we all know and that you just wrote. It contradicts them.
Last edit: Nikos Papageorgiou 2020-07-17
On 17/07/2020 13:27, Nikos Papageorgiou wrote:
Diff:
Thank you for the report. Some of the inconsistencies are problems with the compiler and some are just idiosyncracies of COBOL.
pretty-displayis enabled and this clearly leads to odd results with invalid data. Compiling with-fno-pretty-displaygives consistent output.Related
Bugs:
#663