Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Packed decimals in REXX

682 views
Skip to first unread message

Sean Jeffries

unread,
Jan 3, 2002, 10:35:17 AM1/3/02
to
I have a need to read and write packed decimal numbers in REXX. Any tips on
how to do this?

Thanks

Rich Greenberg

unread,
Jan 3, 2002, 11:43:02 AM1/3/02
to
In article <VS_Y7.29253$8e2.11...@typhoon.southeast.rr.com>,

Sean Jeffries <sjef...@carolina.rr.com> wrote:
>I have a need to read and write packed decimal numbers in REXX. Any tips on
>how to do this?

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

Bob h

unread,
Jan 3, 2002, 5:24:04 PM1/3/02
to
I think there was a routine on this forum or maybe www.mvshelp.com

bobh

JP

unread,
Jan 3, 2002, 8:18:51 PM1/3/02
to

"Sean Jeffries" <sjef...@carolina.rr.com> wrote in message
news:VS_Y7.29253$8e2.11...@typhoon.southeast.rr.com...

> I have a need to read and write packed decimal numbers in REXX. Any tips on
> how to do this?

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.


Mike Cowlishaw

unread,
Jan 4, 2002, 12:07:14 PM1/4/02
to
> I have a need to read and write packed decimal numbers in REXX. Any tips on
> how to do this?

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


0 new messages