Previous Topic: CPUTIME()

Next Topic: DASD()

D2P()

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.

Syntax

The D2P() function has this syntax:

pdec = D2P(number,bytes,[resultform])

Arguments

The D2P() function takes these arguments:

pdec

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.

number

Whole number. You can include a leading sign.

bytes

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.

resultform

Result's format. Specify one of the following:

SIGN

Indicates that a hexadecimal F (positive) or B (negative) occupies the right-most four bits of the result.

NOSIGN

Indicates that the packed-decimal number occupies the entire result string and no indication of sign is present.

Default: SIGN

Return Codes

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')