Convert character field in decimal field.

225 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
ASKED: March 17, 2009  6:58 PM
UPDATED: March 21, 2009  12:51 PM

Answer Wiki

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

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BUG68
    HI Phil, i appreciated your answer, and sorry for my confuse questions, so my solution based in your answer are: waval = 15A wnval = 15 2 waval = '123456789012345' or '123456789012,45' ',' scan waval if %found eval wnval = %dec(waval:15:2) else '.' scan waval if %found eval wnval = %dec(waval:15:2) else ' ' scan waval if %found eval wnval = %dec(waval:15:2) else move waval wnval endif endif endif this is a solution that i implemented in my source, what do you think? thank's my friend
    225 pointsBadges:
    report
  • graybeard52
    BUG, You are making way this too complex. The %dec automatically aligns the decimal based on the incoming value, then the result has the number of decimal positions that is specified. You don't have to do any scanning at all. The period or the comma can be the decimal, depending on your system and /or job values. If you get data both ways (commas and periods) becuase you are multinational, you may want to use a %replace to replace the character. BTW, %dec will ignore any spaces in the input feld.
    3,115 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following