There has just been a thread on SAG-L regarding this very issue. Natural has always permitted the REDEFINE of any format to any other format, so long as the lengths are compatible.
The responsibility for not not making a mess of things resides with the programmer. In the program you posted, it is not Natural’s “fault” if w-num has a non numeric value, it is the programmers fault. The programmer coded such that a long alpha value moved into w-alf created a non numeric value (an e) in w-num. Natural assumed you knew what you were doing.
Here is one of my favorite programs to demonstrate why NOT to redefine an alpha as numeric (or visa versa) (I posted this on SAG-L)
DEFINE DATA LOCAL
1 #A (A5)
1 REDEFINE #A
2 #N (N5)
END-DEFINE
*
INPUT ‘#A HERE==>’ #A
*
WRITE 5T ‘#N BEFORE ADD ==>’ #N #N (EM=H(5))
ADD 1 TO #N
WRITE 5T ‘#N AFTER ADD ==>’ #N #N (EM=H(5))
END
I entered 123 for #A. Please note below I am on my PC, hence the Hex may look unfamiliar. HOWEVER, the exact same thing happens on the mainframe.
PAGE # 1 DATE: 09-11-10
PROGRAM: REDEF01 LIBRARY: INSIDE
#N BEFORE ADD ==> 123 0 3132332020
#N AFTER ADD ==> 12301 3132333031
Not only do we have the floating zero on the first WRITE; not only is 123 + 1 = 12301; But, even worse, look what happened to the blank in the fourth position. It is now a zero.
Now look what happens when I change the ADD statement to: ADD 0 TO #N (123 as INPUT again)
PAGE # 1 DATE: 09-11-10
PROGRAM: REDEF01 LIBRARY: INSIDE
#N BEFORE ADD ==> 123 0 3132332020
#N AFTER ADD ==> 12300 3132333030
Note that the ADD of zero still changes the last two characters from 2020 (blanks) to 3030 (zeroes).
SO, Suppose I move #A (or #N) to #HOLD, then ADD #EXTRA TO #N, then try an IF #HOLD = #N (or #A; basically to see if we added to #N); and suppose #EXTRA is zero. We will be “told” that the IF is not true; WRONG !!!
Now for more fun, enter -123 into #A.
Alpha and Numeric are NOT the same format. There is a limited subset of values where you can successfully get away with this (e.g. enter 12345 for #A). For other values you are just asking for trouble.
Do I do this while “playing” with Natural, or for code that will never be used by anyone but myself? Yes. Would I ever do this (or recommend doing this) in someone elses production code? Absolutely NOT. It is a time bomb waiting to go off.
steve