# Incorrect write of negative numbers in the file

**URL:** <https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Linux\
**Created:** [September 23, 2013, 1:58pm UTC](https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670 "2013-09-23T13:58:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Andreev1](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@Alexander\_Andreev1](https://techcommunity.softwareag.com/u/Alexander_Andreev1)\
**Post date:** [September 23, 2013, 1:58pm UTC](https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670/1 "2013-09-23T13:58:01Z")

</div>

Hi!

I use the function WRITE WORK FILE to write data in the file.

If fields are the negative number, the data is written not correct.

Example:  
Data field: -2.15  
Write as : 21u  
Correct : -215

As I understand, this happening when data converted to a string.

How to get around this problem?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Todd\_Beckwith](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/todd_beckwith/32/388_2.png) [@Todd\_Beckwith](https://techcommunity.softwareag.com/u/Todd_Beckwith)\
**Post date:** [September 23, 2013, 3:02pm UTC](https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670/2 "2013-09-23T15:02:18Z")

</div>

Alexander,

Is the output you are looking for -215 or is -2.15 acceptable? Is a delimited file acceptable?

If -2.15 is acceptable, you can define your work file type as CSV. When using type CSV, numeric fields will be written out correctly, regardless if N, P or I. This is probably the cleanest solution but a delimited file must be acceptable.

If you need the output to be -215, or CSV is not acceptable you can move the numeric field to a alpha field for writing out to the work file. You can suppress the decimal by either using a redefinition as shown below, or MOVE EDITED the N7.2 then deleting the decimal from the alpha variable using an EXAMINE DELETE (you may also need to do a MOVE RIGHT to get the desired output).

```auto

DEFINE DATA
1 #N7_2 (N7.2) INIT <-2.15>
1 REDEFINE #N7_2
  2 #N9 (N9)
1 #A (A10)
END-DEFINE
MOVE EDITED #N9 (EM=-ZZZZZZZZ9) TO #A
WRITE WORK FILE 1 #A
END
```

---

<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:** [September 23, 2013, 3:12pm UTC](https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670/3 "2013-09-23T15:12:44Z")

</div>

What you’re seeing is an overstruck sign. If you read the numeric field with the same format definition as was used to write it, you won’t have this problem. If you need to read the number into a numeric field, you can force a trailing sign.

```auto
DEFINE DATA LOCAL
1 #A (A2) INIT <'Ab'>
1 #N (N3.2) INIT <-123.45>
1 #E (A7)
1 #W (A14)
END-DEFINE
MOVE EDITED #N (EM=999.99-) TO #E
WRITE WORK 1 #A #N #E
READ WORK 1 ONCE #A #N #E
WRITE '=' #A '=' #N '=' #E
*
WRITE WORK 1 #A #N #E
READ WORK 1 ONCE #W
WRITE '=' #W
END
```

```auto
#A: Ab #N: -123.45 #E: 123.45-
#W: Ab1234u123.45-
```

---

<div class="post-metadata">

**Author:** ![Alexander\_Andreev1](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@Alexander\_Andreev1](https://techcommunity.softwareag.com/u/Alexander_Andreev1)\
**Post date:** [September 24, 2013, 7:52am UTC](https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670/4 "2013-09-24T07:52:11Z")

</div>

Thanks guys!

Best Regards,

---

<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, 3:29pm UTC](https://techcommunity.softwareag.com/t/incorrect-write-of-negative-numbers-in-the-file/172670/5 "2021-04-02T15:29:29Z")

</div>


