# Redefine Alphanumeric Filed

**URL:** <https://techcommunity.softwareag.com/t/redefine-alphanumeric-filed/92080>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-News-and-General-Topics\
**Created:** [November 11, 2009, 10:18pm UTC](https://techcommunity.softwareag.com/t/redefine-alphanumeric-filed/92080 "2009-11-11T22:18:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axt](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Axt](https://techcommunity.softwareag.com/u/Axt)\
**Post date:** [November 11, 2009, 10:18pm UTC](https://techcommunity.softwareag.com/t/redefine-alphanumeric-filed/92080/1 "2009-11-11T22:18:47Z")

</div>

Look this example, running on Natural 6.3.6 ( IBM aix 5.3)

define data  
local  
01 w-alf (A10)  
01 redefine w-alf  
02 w-nome (a6)  
02 w-num (N1)  
01 w-num1 (N1)  
end-define  
\*  
w-alf := 'andreae ’  
move w-num to w-num1  
write ‘=’ w-alf ‘=’ w-nome ‘=’ w-num ‘=’ w-num1  
end  
…  
Running this program, I see that Natura can move alphanumeric data into numeric field. Is it normal? Can someone tell me why?  
is it normal? Why moving

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [November 12, 2009, 1:45am UTC](https://techcommunity.softwareag.com/t/redefine-alphanumeric-filed/92080/2 "2009-11-12T01:45:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [November 12, 2009, 3:58am UTC](https://techcommunity.softwareag.com/t/redefine-alphanumeric-filed/92080/3 "2009-11-12T03:58:29Z")

</div>

> [@](#):
>
> Running this program, I see that Natura can move alphanumeric data into numeric field. Is it normal?

Natural allows it because the underlying architectures allow it (mainframe and Open Systems).

N-format is what IBM calls external decimal or zoned decimal. The values 0 thru 9 are represented internally as H’F0’ thru H’F9’. (On ASCII machines the internal representation is different, but Natural works the same way.) The internal representations of the characters ‘0’ thru ‘9’ also are H’F0’ thru H’F9’, so in memory, there is no difference between ‘12345’ and 12345.

Natural knows that the left-most nibble is the “zone” and can be ignored in all but the right-most byte, in which the zone represents the numeric sign, because the numeric value is really in the right-most nibble. Problems can occur if you move characters other than the numeric digits to a numeric target. For example, move ‘ABCDE’ to an N5 and you get 12345. This may not be what you expected. Move any character that does not contain a numeric digit in the right-most nibble, and your program will abend.

Redefinition of alpha as numeric (or vice versa) is a similar but separate issue. There are several legitimate reasons for doing this, but you must be careful to avoid the problem described above.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:57pm UTC](https://techcommunity.softwareag.com/t/redefine-alphanumeric-filed/92080/4 "2021-04-02T14:57:44Z")

</div>


