Archive for September 2013

AS400 (RPG ILE/RPG4) : Character to Numeric

Wednesday, September 25, 2013 · Posted in

To convert character to numeric it is possible by using %DEC. It convert character for example '100000.00' to 100000.00.

But when your character having commas, the %DEC cant proceed the conversion. So you need to change the commas(,) in to blanks. For example : '100,000.00' into '100 000.00'. You can achieve this using %XLATE.

Both the %DEC and %XLATE can be combined an achieve the character to numeric conversion. Example code as below :

D Character S 10 INZ('100,000.00)
D Numeric S 9S2
*
C EVAL Numeric = %DEC(%XLATE(',':' ':Character):10:2)
C Character DSPLY
*
C MOVE '1' *INLR C RETURN

Powered by Blogger.