# Natural Formating of Numeric Data

**URL:** <https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-News-and-General-Topics\
**Created:** [October 10, 2006, 6:43pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574 "2006-10-10T18:43:03Z")\
**Posts on this page:** 18\
**Page:** 1

<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:** [October 10, 2006, 6:43pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/1 "2006-10-10T18:43:03Z")

</div>

Help!

I have the following Problem given:  
A Copycode which gets

&1& a numeric variable / value  
&2& an alphanumeric variable

How could i transfer the numeric value to the alphanumeric variable with decimal point and thousands separators without defining any other help- or counter variable?

E.g.:

&1& = -123456.789  
&2& should be -123.456,789

another example:

&1& = 1234567.12  
&2& should be 1.234.567,12

and one more:

&1& = -0.213  
&2& should be -0,213

And don’t forget i could not define a new variable at this context. I tried move edited with examine what would not solve the problem because the inputvariable could have dynamic lenghts. I also tried compress numeric but there i don’t know how i could get the thousands separators.

I use Natural 4.1.4 on BS2000

Greetings  
Sascha

p.s. i know how to make it as an subprogram or with defining new variables.

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@Finn\_the\_Dane](https://techcommunity.softwareag.com/u/Finn_the_Dane)\
**Post date:** [October 10, 2006, 7:26pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/2 "2006-10-10T19:26:22Z")

</div>

Hi Sascha,  
I know you may think this is cheating, but what about making an external subroutine with two parameters “by value” and “by value return”  
and then put the call of this subroutine into a piece of copycode with placeholders ?

Finn

---

<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:** [October 10, 2006, 7:47pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/3 "2006-10-10T19:47:47Z")

</div>

Sounds nice. Hmmm i think i would try that first. But if someone have an other better solution please post.

Greetings  
Sascha

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [October 10, 2006, 8:18pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/4 "2006-10-10T20:18:05Z")

</div>

Hi Sascha,  
I hope this fits to your requirement:

DEFINE DATA LOCAL  
1 #N1 (N17.3) INIT \<-123456.789\>  
1 #N2 (N8.2) INIT \<1234567.12\>  
1 #N3 (N1.3) INIT \<0.213\>  
1 #N4 (N22.7)  
INIT \<-1234567890123456789012.1234567\>  
1 #A (A40)  
END-DEFINE  
INCLUDE T-COMMC ‘#N1’ ‘#A’  
WRITE #A  
INCLUDE T-COMMC ‘#N2’ ‘#A’  
WRITE #A  
INCLUDE T-COMMC ‘#N3’ ‘#A’  
WRITE #A  
INCLUDE T-COMMC ‘#N4’ ‘#A’  
WRITE #A  
\*  
END

The Copycode T-COMMC:

- 

MOVE EDITED &1&  
(EM=-Z’$‘ZZZ’$‘ZZZ’$‘ZZZ’$‘ZZZ’$‘ZZZ’$‘ZZZ’$'ZZ9.9999999)  
TO &2&  
EXAMINE FULL &2& FOR ‘.’ REPLACE ‘,’  
EXAMINE FULL &2& FOR ‘$’ REPLACE ‘.’  
MOVE RIGHT JUSTIFIED &2& TO &2&

---

<div class="post-metadata">

**Author:** ![Steve3](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Steve3](https://techcommunity.softwareag.com/u/Steve3)\
**Post date:** [October 10, 2006, 8:26pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/5 "2006-10-10T20:26:35Z")

</div>

I am running Natural 4.1.3 on MVS, so I am not sure what the differences are, but what kind of problems does this code create for you:

The program looks like:

RESET #A (A9) #N(N5.2)  
MOVE 2345.55 TO #N  
INCLUDE SLBCOPY ‘#N’ ‘#A’  
END

The copy code looks like:

MOVE EDITED &1& (EM=ZZZ,ZZZ,ZZ9.99) TO &2&  
WRITE ‘=’ &1& ‘=’ &2&

This works on the mainframe with different size variables being passed to it.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [October 10, 2006, 8:43pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/6 "2006-10-10T20:43:48Z")

</div>

I hope, I understand your problem correctly. How about that copycode:

```auto
*
if frac(&1&) eq 0
  move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9) to &2&
  move left &2& to &2&
else
  move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9.99999999999999) to &2&
/* cut trailing zeros
  examine &2& for '0' replace ' '
  move left &2& to &2&
  examine &2& for ' ' replace '0'
end-if
```

Only disadvantage is, that the receiving alpha-field must be at least 15 byte long in case of frac(&1&) ne 0.

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [October 10, 2006, 9:02pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/7 "2006-10-10T21:02:51Z")

</div>

> [@Matthias](#):
>
> I hope, I understand your problem correctly. How about that copycode:
> 
> ```auto
> *
> if frac(&1&) eq 0
> move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9) to &2&
> move left &2& to &2&
> else
> move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9.99999999999999) to &2&
> /* cut trailing zeros
> examine &2& for '0' replace ' '
> move left &2& to &2&
> examine &2& for ' ' replace '0'
> end-if
> ```
> 
> Only disadvantage is, that the receiving alpha-field must be at least 15 byte long in case of frac(&1&) ne 0.

If the variable contains the value 0.123, the 0 gets lost because of the EXAMINE REPLACE

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [October 10, 2006, 9:11pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/8 "2006-10-10T21:11:27Z")

</div>

> [@Helmut Spichtinger](#):
>
> If the variable contains the value 0.123, the 0 gets lost because of the EXAMINE REPLACE

You’re right. The code for cutting trailing zeros should be:

```auto
/* cut trailing zeros 
move left &2& to &2& 
examine &2& from 2 for '0' replace ' ' 
examine &2& for ' ' replace '0' 
```

---

<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:** [October 10, 2006, 9:19pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/9 "2006-10-10T21:19:14Z")

</div>

> [@Matthias](#):
>
> I hope, I understand your problem correctly. How about that copycode:
> 
> ```auto
> *
> if frac(&1&) eq 0
> move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9) to &2&
> move left &2& to &2&
> else
> move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9.99999999999999) to &2&
> /* cut trailing zeros
> examine &2& for '0' replace ' '
> move left &2& to &2&
> examine &2& for ' ' replace '0'
> end-if
> ```
> 
> Only disadvantage is, that the receiving alpha-field must be at least 15 byte long in case of frac(&1&) ne 0.

Hmmm i think this is an [PEBKAC](http://en.wikipedia.org/wiki/Pebcak) i tried this myself before i wrote the first posting and got an Compileerror for the Editmask. If i try it now i don’t get such an error :?

But thanks i will try it again. And write if i get the Error again 😃

Greetings  
Sascha

---

<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:** [October 10, 2006, 9:47pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/10 "2006-10-10T21:47:38Z")

</div>

I tried the whole Copycode:

```auto

*
0020 IF FRAC(&1&) EQ 0
0030 MOVE EDITED &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9) TO &2&
0040 MOVE LEFT &2& TO &2&
0050 ELSE
0060 MOVE EDITED &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9.99999999999999) TO &2&
0070 /* cut trailing zeros
0080 MOVE LEFT &2& TO &2&
0090 EXAMINE &2& FROM 2 FOR '0' REPLACE ' '
0100 EXAMINE &2& FOR ' ' REPLACE '0'
0110 END-IF
```

and if i use it i get an NAT0285 in Line 0090, FROM using

Greetings  
Sascha

---

<div class="post-metadata">

**Author:** ![Steve3](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Steve3](https://techcommunity.softwareag.com/u/Steve3)\
**Post date:** [October 10, 2006, 10:26pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/11 "2006-10-10T22:26:08Z")

</div>

In the Cut Trailing Zeros, try this:

/\* CUT TRAILING ZEROS  
MOVE LEFT &2& TO &2&  
EXAMINE &2& FOR ‘0’ REPLACE ’ ’  
EXAMINE &2& FOR ’ ’ REPLACE ‘0’

I am not sure what the from parameter does, it’s not valid in MVS, but if its valid in BS2000, you may just need the & around the 2 after from. The original look like:  
EXAMINE &2& FROM 2 FOR ‘0’ REPLACE ’ ’

Maybe it was suppose to be

EXAMINE &2& FROM &2& FOR ‘0’ REPLACE ’ ’

---

<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:** [October 10, 2006, 11:09pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/12 "2006-10-10T23:09:56Z")

</div>

Natural 6 allows a position clause in the EXAMINE statement with which you can set the starting and ending bytes with FROM and THRU keywords. This is not available in Natural 4.

On the mainframe, use the SUBSTRing clause instead.

```auto
EXAMINE SUBSTR (&2&, 2) FOR '0' REPLACE ' '
```

---

<div class="post-metadata">

**Author:** ![Arnold\_Carreon](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Arnold\_Carreon](https://techcommunity.softwareag.com/u/Arnold_Carreon)\
**Post date:** [October 11, 2006, 3:03am UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/13 "2006-10-11T03:03:43Z")

</div>

Just wishful thinking… It would be nice if SAG can add a keyword (to include the thousands separator) to the COMPRESS NUMERIC statement to do what Sascha requires.

---

<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:** [October 11, 2006, 3:58am UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/14 "2006-10-11T03:58:03Z")

</div>

I think I know the answer to my own question, but will ask it anyway. Do you have existing code with INCLUDEs and two arguments?

If not, I would ask why you are going to do this with copycode. Can we not trust a Natural programmer to write a simple MOVE EDITED statement? That way we do not have to write code to deal with the possibility that we have N7.2 or N9.1 or N6.0 etc.

Except for the possibility that you might reverse your commas and periods , it does not seem to me there is a likelihood of changing everything that would use this copycode.

Okay, if a format changes from N7.2 to N9.3, I would have to SCAN a program for where the variable is used, and would have to alter an edit mask.

steve

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [October 11, 2006, 12:38pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/15 "2006-10-11T12:38:16Z")

</div>

> [@Arnold Carreon](#):
>
> It would be nice if SAG can add a keyword (to include the thousands separator) to the COMPRESS NUMERIC statement to do what Sascha requires.

ACK! Compress numeric would be a proper way to solve this. MOVE EDITED produces a runtime error if the target field is too small. COMPRESS doesn’t. And COMPRESS would even work with floats.

---

<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:** [October 11, 2006, 1:56pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/16 "2006-10-11T13:56:02Z")

</div>

> [@Steve Robinson](#):
>
> I think I know the answer to my own question, but will ask it anyway. Do you have existing code with INCLUDEs and two arguments?

Hi Steve yes i have existing Code. This Copycode would be Part of a Framework to Convert Dates, Numerics and logical Variables to Alphanumeric and back. I wrote an Generator which writes Programms using this Copycodes. (The generated Code should also be Humanreadable ;-)) Thats why i could not invent an new Variable without changing existing Programms and/or changing the Generator

But the solutions here in this Thread would work for me. (I solved the “from”-Problem with an “if” where i every time when i have a positive Value between 0 and 1 compress the “0” to the first position so i could use the other code from Matthias.

Greetings  
Sascha

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [October 11, 2006, 8:14pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/17 "2006-10-11T20:14:00Z")

</div>

If the copycode has to work for floats, we can use a compress numeric before doing an move edited…

```auto
compress numeric &1& to &2&
/* float or number less than thousand
if substr(&2&,3,1) = '.' or substr(&2&,2,1) = '.'
    or &1& < 1000 and &1& > -1000
  ignore /* use compress numeric as a result
else
  if frac(&1&) eq 0
    move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9) to &2&
    move left &2& to &2&
  else
    move edited &1& (EM=-Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9.9(14)) to &2&
    /* cut trailing zeros
    move left &2& to &2&
    examine &2& from 2 for '0' replace ' '
    examine &2& for ' ' replace '0'
  end-if
*
end-if
```

---

<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:40pm UTC](https://techcommunity.softwareag.com/t/natural-formating-of-numeric-data/61574/18 "2021-04-02T14:40:53Z")

</div>


