How to emulate in Java the behavior of RPG Z-ADD or other assignment that would be an overflow?

238 views Asked by At

I have to mimic RPG behavior in Java. In RPG, there are 2 zoned decimal fields FLDA is length 2 with 0 decimals FLDB is length 5 with 1 decimals FLDA value = 0 FLDB value = 1234.5

RPG line of code

 C                     Z-ADDFLDB      FLDA     

FLDA value would then be 34. By default RPG does not throw an overflow exception, it truncates to fit.

How can I do this with Java BigDecimal?

1

There are 1 answers

0
Charles On BEST ANSWER

Old versions of RPG had this design flaw...RPG IV corrects it when using either the EVAL op-code or the TRUNCNBR(*NO) compiler option.

You're going to need to write Java equivalents of RPG's ADD, SUB, Z-ADD and Z-SUB op-codes. MOVE would be another problematic op-code.