IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Convert numeric to packed signed decimal


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
oerdgie

New User


Joined: 22 Nov 2007
Posts: 64
Location: Germany

PostPosted: Mon May 02, 2011 9:04 pm
Reply with quote

Hi Folks,

how can I convert a numeric value into a packed signed decimal in REXX ?

Examples :
123 converted to '123C'x (positiv)
4456 converted to '04456D'x (negativ)
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Mon May 02, 2011 9:12 pm
Reply with quote

Add these to your collection of common procedures:

/* packed to decimal */
p2d: procedure
arg pd
Return (translate(right(C2X(pd),1),'-- ','BDACEF')||left(C2X(pd),length(C2X(pd))-1)) + 0

/* decimal to packed */
d2p: procedure
arg dec
If dec < 0 then s = 'D'; else s = 'C'
n = space(translate(dec,,'+-.')s,0)
Return X2C(right(n,length(n)+length(n)//2,'0'))
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon May 02, 2011 9:16 pm
Reply with quote

oerdgie wrote:

how can I convert a numeric value into a packed signed decimal in REXX ?

Examples :
123 converted to '123C'x (positiv)
4456 converted to '04456D'x (negativ)


4456 is positive.

Anyway, strip the sign, concatenate the number with 'C' (+) or 'D' (-) and use x2c(whatever). REXX will take care of the potential added initial zero.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon May 02, 2011 9:31 pm
Reply with quote

see
here
ibmmainframes.com/viewtopic.php?t=27921&highlight=rexx+pack+unpack
and here
ibmmainframes.com/viewtopic.php?t=41407&highlight=rexx+pack+unpack
and here
ibmmainframes.com/viewtopic.php?t=31547&postdays=0&postorder=asc&start=15
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Mon May 02, 2011 9:41 pm
Reply with quote

Hey guys, quite a few of us are getting on in years, what's going to happen when we're gone and nobody can ever work out how to search or find a manual icon_evil.gif
Back to top
View user's profile Send private message
oerdgie

New User


Joined: 22 Nov 2007
Posts: 64
Location: Germany

PostPosted: Mon May 02, 2011 10:19 pm
Reply with quote

Thanks for help ! icon_smile.gif

Regards
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Mon May 02, 2011 10:28 pm
Reply with quote

expat wrote:
Hey guys, quite a few of us are getting on in years, what's going to happen when we're gone and nobody can ever work out how to search or find a manual icon_evil.gif

See if you can find the short story "MS Found in a Library" (not to be confused with Poe's "MS Found in a Bottle").
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
Search our Forums:

Back to Top