## Convert character field in decimal field.

235 pts.
Tags:
iSeries RPG programming
RPG ILE
RPG IV
RPGLE
hi, everybody i need a help for this: waval = 15A wnval = 15 2 i put in my source this eval wnval = %dec(waval:15:2) but when i run the program stop with error in this line. what i need to do, because i want this example: waval = 123456789012345 wnval = 123456789012345.00 but if i put this: waval = 123456789012.34 wnval = 123456789012.34 i don´t if anybody understand, but any help is usefull. thank's

Thanks. We'll let you know when a new response is added.

waval = 15A
wnval = 15 2
waval = 123456789012345
eval wnval = %dec(waval:15:2)

1. %dec attempts to find the decimal point in waval
2. since it cannot find the decimal it assumes it is to the right of the last character
as 123456789012345.
3. %dec attempts to convert 123456789012345. to a numeric 15 wide including 2 digits
as 123456789012345.00
4. but that produces too many digits 17-2 and fails

this should work if your data doesn’t have a decimal
eval wnval = %dec(waval:15:0)/100

Typically you should enclose this command in a monitor block to capture any errors.

Phil
//// — that was a great answer but not exactly what you wanted — ////
To get what you wanted you must format wnval as 17-2 and use 17-2 in the %dec command.
Numeric fields are total width and number of decimal places.

waval = 15A
wnval = 17 2
waval = ‘123456789012345’
eval wnval = %dec(waval:17:2)

and now wnval = 123456789012345.00

Phil

_______________________________________________________________
/////////////////////////////////////////////////////////////

I think you are on the right track
1. The ‘ ‘ doesn’t work — you might have to replace the ‘ ‘ if it exists with a . or ,

2. Instead of a move I would use the code:
eval wnval = %dec(waval:15:0)/100
and I would enclose the entire block in a monitor block.

Phil