[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[open-cobol-list] Re: compare numeric - alphanumeric
From: |
Thomas Biehler |
Subject: |
[open-cobol-list] Re: compare numeric - alphanumeric |
Date: |
Sat May 8 04:46:00 2004 |
User-agent: |
KMail/1.4.2 |
On Saturday, May 8 2004 11:55 you wrote:
> Hmm, interesting.
> Firstly, note that the COMP field is only 2 bytes.
> If you change the definition to S9(8) COMP - (4 bytes), then
> both MF and OpenCob fail test 2 and 4.
>
> I believe MF is wrong.
> Synopsis :
> From MF Lang Ref
> Conditional expressions/comparison of nonnumeric operands :
> "If the nonnumeric operand is an elementary data item or a
> nonnumeric literal, the numeric operand is treated as though
> it were moved to an elementary alphanumeric data item of the
> same size as the numeric data item, and the contents of this
> alphanumeric data item were compared to the nonnumeric item."
"same size" is number of digits / bytes ? I think digits is meant!
>
> So, internally, the 2-byte COMP field should get moved to a 2-byte
> alphanumeric field. Now the comparison should be 2-byte display
> against 4-byte display. The 2-byte gets expanded on the right with spaces.
I think you are wrong here, see later ...
> And this should give a not-equal.
> QED or ?
>
> Roger While
Hi Roger,
IMO with the "the same size" the number of digits in the picture clause is
meant!
--> PIC S9(4) --> size = 4. --> MF is ok at this point!
ANSI - 1985 (here is not the best definition for size = "in terms of standard
data format characters")
==================================================================
§6.3.1.1.2 (1) (Comparision of Nonnumeric Operands)
... the numeric operand is treated as though it were move to an
elementary
alphanumeric data item of the same size as the numeric data item ( in
terms of
standard data format characters), ...
and clearer (IMHO much better!) formulated in
ISO/IEC 2002
===================================================================================
§8.8.4.1.1.4 (Comparsion of a numeric integer operand with an operand of class
alphanumeric or national)
...
The integer is threated as though it were moved to an elementary data
item of a length the same as the
number of digits in the integer ...
If you change my testprogram:
from : X-FIELD PIC X(4) VALUE "0001"
t o : X-FIELD PIC X(6) VALUE "0001 " --> two trailling
blanks
it should generate the same results.
The problem what i want to show is the USAGE COMP clause at the integer.
(= one example for all other "NON USAGE DISPLAY" clauses of the integer!)
again excerpts from the standards:
===========================================================================
first the "better" ISO/IEC 2002 standard:
§8.8.4.1.1.4
The numeric integer operand shall be an integer literal or integer numeric
data item
of usage display or national ....
==> NO !! USAGE COMP, USAGE BINARY, USAGE PACKED-DECIMAL ...;
"shall be" = synonym for "is required" in ISO/IEC 2002)
or harder to read in ANSI 1985 standard: (IMHO "confusing")
===========================================================================
§ 6.3.1.1
... Comparision of two numeric operands is permitted regardless of the
formats specified
in their respective USAGE clauses. However, for all other comparisions,
the operands must
have same usage. ...
(my conclusion: same usage as alphanumeric operand with PIC X
--> USAGE DISPLAY is also a must for the numeric operand! )
So IMHO allowing the NON USAGE DISPLAY USAGE
for the numeric operand is the bug.
--> But how to handle this with existing programs ? (warning / error ?)
And this bug seems to be in all compilers which i haved used.
This is the critical point which i want to demonstrate and discuss here public.
There are no "substantial changes" between ANSI 1985 and ISO 2002 listed
at this topic.
--> So i think the intention from the standard in ANSI 1985 was the same as it
now is in ISO/IEC 2002.
Thank you for your fast answer!
Further comments are welcome!
Regards
Thomas