RPG's built in %DEC
function is generally happy with embedded spaces - but if the string that you are trying to convert is completly blank, it throws an error. This is fair enough, I suppose, but not what I want - I want a zero.
No problem, thought I. I'll throw together a quick subprocedure.
**********************************************************************************************
* Convert string to packed decimal
**********************************************************************************************
p str_to_packed b
d str_to_packed pi 31p11
d from_str 40 value
d precision 2p 0 value
d scale 2p 0 value
d return_value s 31p11
c if from_str = *blanks
c eval return_value = *zero
c else
c eval return_value = %dec(from_str:precision:scale)
c endif
c return return_value
p e
*********************************************************************************************
Does this work? Does it fuck. It fails to compile, because the %DEC
function needs its scale and precision arguments fixed at compile time, would you believe. Arse.
Update: Looks like I'll have to do it the hard way. Sigh.
And while I'm ranting about RPG, what's the bloody point of introducing exception catching if you can't raise exceptions?
Posted to iSeries by Simon Brunning at April 29, 2004 02:39 PM