Thanks
Here is a routine to read them. I never needed to write them.
Probably someone else has.
/*
UNPACK
Convert packed number to char string.
Input args: (1:req'd) Packed number (binary)
(2:opt) 'S' = signed (default), 'U' unsigned
Unless 'U' is specified, the rightmost 4 bits
is assumed to be a sign.
(3:opt) positions to right of decimal point
default = no decimal point inserted.
(4:opt) Desired output length. Result will be
truncated from the left or extended with
zeros on the left.
output: Three blank seperated items as follows:
Return code
sign (c'+' or c'-')
Decimal equivalant without sign (characters)
Return codes: 0 = No error
1 = non-decimal chars in numeric part
2 = Invalid sign
anything else = unknown error.
*/
false = (1=0)
true = (1=1)
trace O
/*
Get packed decimal (binary) number,
sign option, decimal position, and o/p length.
*/
parse arg pv, opt, dp_pos, op_len
upv = c2x(pv) /* Convert binary to hex */
if opt = 'U' /* Is it an unsigned packed fragment? */
then do
num = upv /* Numeric part */
sign = 'F' /* sign */
end
else do
num = left(upv,length(upv)-1) /* Numeric part */
sign = right(upv,1) /* sign */
end
/*
Validate the results.
*/
if verify(num,'0123456789') > 0 /* Bad digit? */
then return '1 ?' num
/*
Insert decimal point if so requested.
*/
if dp_pos ª= ''
then do
l_num = length(num)
num = left(num,l_num-dp_pos) || '.' || right(num,dp_pos)
end
/*
Set output length if so requested.
*/
if op_len ª= ''
then num = right(num,op_len,'0')
/*
Return answer.
*/
select
when sign = 'F'
then return '0 +' num
when sign = 'C'
then return '0 +' num
when sign = 'D'
then return '0 -' num
otherwise
return '2 ?' num
end
Note: the "\xaa" strings in the above are not symbols, x'5F' (ebcdic)
--
Rich Greenberg Work: Rich.Greenberg atsign worldspan.com +1 770-563-6656
N6LRT Marietta, GA, USA Play: richgr atsign panix.com +1 770-321-6507
Eastern time zone. I speak for myself & my dogs only. VM'er since CP-67
Canines:Val(Chinook,CGC,TT), Red & Shasta(Husky,(RIP)) Owner:Chinook-L
Atlanta Siberian Husky Rescue. www.panix.com/~richgr/ Asst Owner:Sibernet-L
If you don't need to create new packed decimal numbers, or display them in PD
format, you should be able to read and write without caring whether the data is
packed, binary, etc.
For packed decimal to Rexx strings: given a few bytes which are packed decimal,
first try the C2X function. That will give you the digits. Then handle the last
character to determine the sign.
For the other direction, append the sign nibble (character) then use X2C.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Mike Cowlishaw, IBM Fellow
mailto:m...@uk.ibm.com -- http://www2.hursley.ibm.com