How to: |
Available Languages: reporting, Maintain
The PTOA function converts a packed-decimal number from numeric format to alphanumeric format. It retains the decimal positions of the number and right-justifies it with leading spaces. You can also add edit options to a number converted by PTOA.
When using PTOA to convert a number containing decimals to a character string, you must specify an alphanumeric format large enough to accommodate both the integer and decimal portions of the number. For example, a P12.2C format is converted to A14. If the output format is not large enough, the right-most characters are truncated.
PTOA(number, '(format)', output)
where:
Numeric P (packed-decimal)
Is the number to be converted, or the name of the field that contains the number.
Alphanumeric
Is the format of the number enclosed in both single quotation marks and parentheses.
Only packed-decimal format is supported. Include any edit options that you want to display in the output.
The format value does not require the same length or number of decimal places as the original field. If you change the number of decimal places, the result is rounded. If you make the length too short to hold the integer portion of the number, asterisks appear instead of the number.
If you use a field name for this argument, specify the name without quotation marks or parentheses. However, parentheses must be included around the format stored in this field. For example:
FMT/A10 = '(P12.2C)';
You can then use this field as the format argument when using the function in your request:
COMPUTE ALPHA_GROSS/A20 = PTOA(PGROSS, FMT, ALPHA_GROSS);
Alphanumeric
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. The length of this argument must be greater than the length of number and must account for edit options and a possible negative sign.
PTOA is called twice to convert the PGROSS field from packed-decimal to alphanumeric format. The format specified in the first call to the function is stored in a virtual field named FMT. The format specified in the second call to the function does not include decimal places, so the value is rounded when it appears:
DEFINE FILE EMPLOYEE PGROSS/P18.2=GROSS; FMT/A10='(P14.2C)'; END TABLE FILE EMPLOYEE PRINT PGROSS NOPRINT COMPUTE AGROSS/A17 = PTOA(PGROSS, FMT, AGROSS); AS '' COMPUTE BGROSS/A37 = '<- THIS AMOUNT IS' | PTOA(PGROSS, '(P5C)', 'A6') | ' WHEN ROUNDED'; AS '' IN +1 BY HIGHEST 1 PAY_DATE NOPRINT BY LAST_NAME NOPRINT END
The output is:
2,475.00 <- THIS AMOUNT IS 2,475 WHEN ROUNDED 1,815.00 <- THIS AMOUNT IS 1,815 WHEN ROUNDED 2,255.00 <- THIS AMOUNT IS 2,255 WHEN ROUNDED 750.00 <- THIS AMOUNT IS 750 WHEN ROUNDED 2,238.50 <- THIS AMOUNT IS 2,239 WHEN ROUNDED 1,540.00 <- THIS AMOUNT IS 1,540 WHEN ROUNDED 1,540.00 <- THIS AMOUNT IS 1,540 WHEN ROUNDED 1,342.00 <- THIS AMOUNT IS 1,342 WHEN ROUNDED 1,760.00 <- THIS AMOUNT IS 1,760 WHEN ROUNDED 1,100.00 <- THIS AMOUNT IS 1,100 WHEN ROUNDED 791.67 <- THIS AMOUNT IS 792 WHEN ROUNDED 916.67 <- THIS AMOUNT IS 917 WHEN ROUNDED