Ideally the storage would be addressed via a /data pointer/ and the attributes of the data pointer established as P(30,9). I believe in past forays, I found little support in RPG to do that directly, and while I do not recall specifically my experience using the MI instructions via RPG, I do experience an unpleasant pang when attempting to recall ;-)

I find the SQL is very easy to effect the desired conversion. The same concept is easily effected purely in RPG, but I have already written the SQL several times in the past.

Using an SQLRPGLE module source, instead of RPGLE:

d rtn30p09 s 30p09
d rawLen s 5i00
d rawSgn s 5i00
Exec SQL
set :rtn30p9=cast(
left( hex( substr( :pHex, 1, :rawLen ) ), :pDecLen )
* case when right( hex( substr( :pHex, :rawSgn, 1 ) ), 1 )
in ('B', 'D') then -1 else 1 end
as decimal(30, 09) ) ;
// deal with sqlcode\sqlstate as necessary
return rtn30p09;

The above SQL was copied and modified [hopefully correctly] from another response to a similar inquiry on 05 Aug 2011:

Per rtn30p09 being typed P(30,9), the CAST should be redundant; e.g. if paring the expression is desirable.

Regards, Chuck

On 23 Apr 2012 09:04, Matt Lavinder wrote:
I am trying to write a generic procedure to retrieve a data area that
is a decimal value. Currently, we have to adjust the procedure every
time we need to handle a new size, and then we have to add variables
and specific code for that size.

I am trying to use the QWCRDTAA to retrieve the value and ultimately
want return a decimal of 30p 9 that contains what ever was found in
the data area. Problem is, the data comes back as hex from QWCRDTAA
(the raw decimal data). Obviously I could just MOVE the data if I
wanted to define decimals of all possible sizes, but then I am back
to the very thing I am trying to avoid.

As a part of my procedure, I pass in the definition of the data area,
so I know that at run time. What is the quickest way to get that
raw/hex data into a decimal variable I can work with? If you were to
put the logic I am looking for into a procedure, the prototype to
convert this character/hex data would need to look something like

D HexToPacked pi 30p 9
D pHex 2000a
D pDecLen 5i 0
D pDecPrecision 5i 0


This thread ...

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].