[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Alphanumeric to Numeric MOVE (was: [open-cobol-list] Two errors of Open-
From: |
William M. Klein |
Subject: |
Alphanumeric to Numeric MOVE (was: [open-cobol-list] Two errors of Open-Cobol 09.7-11 |
Date: |
Thu Nov 14 22:49:10 2002 |
See comments below:
> -----Original Message-----
> This program give wrong results.
> ================
>
> *****************************************************************
> IDENTIFICATION DIVISION.
> PROGRAM-ID. ERR02.
>
> *****************************************************************
> ENVIRONMENT DIVISION.
> CONFIGURATION SECTION.
> SPECIAL-NAMES.
> DECIMAL-POINT IS COMMA.
> INPUT-OUTPUT SECTION.
>
> *****************************************************************
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 77 PGM PIC X(8) VALUE 'ERR02 '.
> 77 PIC-X PIC X(8).
> 77 PIC-9 PIC 9(5).
> PROCEDURE DIVISION.
> MAIN.
> DISPLAY PGM.
> MOVE ' 2A' TO PIC-X.
> a) MOVE PIC-X TO PIC-9.
> DISPLAY 'PIC-X >' PIC-X '<'.
> b) DISPLAY 'PIC-9 >' PIC-9 '<'.
> c) IF PIC-9 IS NUMERIC
> DISPLAY 'PIC-9 IS NUMERIC'
> ELSE
> DISPLAY 'PIC-9 IS NOT NUMERIC'
> END-IF.
> d) ADD 1 TO PIC-9.
> DISPLAY 'PIC-9 >' PIC-9 '<'.
> STOP RUN.
> ----------------------------
> This is the output of pgm:
> ERR02
> PIC-X > 2A <
> PIC-9 >00002<
> PIC-9 IS NUMERIC
> PIC-9 >00003<
>
> The correct output must be:
> ERR02
> PIC-X > 2A <
> PIC-9 > 2A <
> PIC-9 IS NOT NUMERIC
> Run-time error in line 28: wrong decimal data
>
> Move a) must be permitted to permit c) test.
This is SORT-of true. The ANSI Standard requires that you must be able
to move an alphanumeric elementary item to a numeric-integer data item.
HOWEVER, there are rules that allow for "optimization" to detect
invalid data, so the compiler COULD issue a message. If the compiler
DOES allow this to compile, then the results of the MOVE are
UNDEFINED
See: CIB-24, A-44 and CIB-26, A-286.
The results of a move from an ALPHANUMERIC to a numeric-integer
elementary is ONLY defined if the alphanumeric sending item includes an
unsigned integer value.
Display b) must show the field.
Not True - as the value in the field PIC-9 is UNDEFINED (becuase the
MOVE was undefined)
> Every aritmetic operation must break the program with an error.
NOT true. When a field contains "incompatible data" - then the use of
such a field is UNDEFINED - it may (or may not) cause an error - or "odd
results" - or anything else the compiler & run-time "want" (including
different results on odd-days of the months!!)
> A
> move of PIC-9 in a field pic-edited (ZZ.ZZZ, for example) must give
> error, too.
Only if the compiler & run-time "want" it to.
> ================
> Thank you, and sorry for my english!
>
> Enrico Ceppi
>