Here is one, of many ways to get the last two digits.
This could easily be put into a sub-procedure.
HOWEVER YOU WOULD HAVE TO SHOOT ME BEFORE I WOULD USE IT!
D Fld1 s 2 0 inz(20)
D Fld2 s 2 0 inz(30)
D wrkFLDDS ds
D wrkFLD 15S 0
D fld3 14 15S 0
C eval wrkFLD = Fld1 * Fld2
- I can understand situations where the results won’t fit
- I cannot understand when you would not want an error message or some corrective code when that occurs.
If the customer orders 100 pieces at $1000.00 each you would bill them 000.00? because the correct value
wouldn’t fit in your field?
RPG III/400 masked the error and you don’t like errors?
Correct procedure might be:
D Fld1 s 2 0 Inz(20)
D Fld2 s 2 0 Inz(10)
D Fld3 s 2 0 Inz
C EVAL Fld3 = Fld1 * Fld2
C eval fld3 = 00
c eval ERRFLG = *ON
Oh not for invoice amount, then when is it
appropriate to drop the most significant digits?
MOVE will work in RPGLE like it did in RPG/400 if you add
TRUNCNBR(*YES) to the H spec. The MOVE is not available in Free Format.
So there is no reason to use RPG/400 but this is all covering up
a serious design problem.
60 * 2 is not 20, never will be 20, not even in new math!
If the 60 was due to a communication error then the report should say ‘* COMMUNICATION ERROR *’ not 20!
I rarely miss the loose behavior of MOVE and don’t even use it any more since it’s not supported in free format. Assignment statements (via an implicit EVAL operation) combined with the built in functions plus the ability to create our own provide more control over the end result, which I think is preferable.
Thus, I don’t look at the non-availability of MOVE and its variants as a problem, but rather a tightening up on the rules which led to bad practices in the past. Its use with numeric data tends to create some unintended problems which are out of sight and out of mind until they’re discovered down the line and require research to figure out and correct. I think this was one of IBM’s good reasons for not implementing MOVE in free format. And this is more consistent with other environments and languages such as Java and .Net.