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?
&1& = -123456.789
&2& should be -123.456,789
&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
p.s. i know how to make it as an subprogram or with defining new variables.
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 ?
/* 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 ’ ’
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.
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.
If the copycode has to work for floats, we can use a compress numeric before doing an move edited…
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
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&
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'