Use the D2P() function to convert a REXX-format whole number into IBM packed-decimal format. This form is frequently used to store decimal numbers with two digits per byte.
The D2P() function has this syntax:
pdec = D2P(number,bytes,[resultform])
The D2P() function takes these arguments:
Packed decimal number. Each byte contains two decimal digits, except the right-most byte, which may contain a sign digit (hexadecimal F for positive, B for negative) in the right half of the byte. The presence of the sign is controlled by the third argument.
Whole number. You can include a leading sign.
Number of bytes to be occupied by the returned packed-decimal number. Specify a value from 1 to 8 (inclusive). Truncation and padding are performed on the left.
Result's format. Specify one of the following:
Indicates that a hexadecimal F (positive) or B (negative) occupies the right-most four bits of the result.
Indicates that the packed-decimal number occupies the entire result string and no indication of sign is present.
Default: SIGN
The D2P() function produces these return codes:
|
101 - 103 |
ARG n MISSING OR INVALID |
Example
/* Pack a Julian date to store in ISPF statistics format */ /* date as year and day */ parse arg year '.' day /* Standard form:yyddd*/ julian = right(year,2,'0')||right(day,3,'0') /* packed format (4 bytes): 00 yy dd dF*/ pdec = d2p(julian,4,'sign')
| Copyright © 2011 CA. All rights reserved. | Tell Technical Publications how we can improve this information |