FPRINT: Converting Fields to Alphanumeric Format

How to:

Reference:

The FPRINT function converts any type of field except for a text field to its alphanumeric equivalent for display. The alphanumeric representation will include any display options that are specified in the format of the original field.

Available Languages: reporting

Syntax: How to Convert Fields Using FPRINT

FPRINT(in_value, 'usageformat', output)

where:

in_value

Any format except TX

Is the value to be converted.

usageformat

Alphanumeric

Is the usage format of the value to be converted, including display options. The format must be enclosed in single quotation marks.

output

Alphanumeric

Is the name of the output field or its format enclosed in single quotation marks.

The output format must be long enough to hold the converted number itself, with a sign and decimal point, plus any additional characters generated by display options, such as commas, a currency symbol, or a percent sign.

For example, D12.2 format is converted to A14 because it outputs two decimal digits, a decimal point, a possible minus sign, up to eight integer digits, and two commas. If the output format is not large enough, excess right-hand characters may be truncated.

Reference: Usage Notes for the FPRINT Function

  • The USAGE format must match the actual data in the field.
  • The output of FPRINT for numeric values is right-justified within the area required for the maximum number of characters corresponding to the supplied format. This ensures that all possible values are aligned vertically along the decimal point or units digit.
  • By default, the column title is left justified for alphanumeric fields. To right justify the column title, use the /R reformatting option for the field.
  • Maintain Data does not support the FPRINT function. However, you can do the same type of conversion in Maintain Data using the COMPUTE command.

Example: Converting Numeric Fields to Alphanumeric Format

The following request against the EMPLOYEE data source uses FPRINT to convert the CURR_SAL, ED_HRS, and BANK_ACCT fields to alphanumeric for display on the report output. Then, the STRREP function replaces the blanks in the alphanumeric representation of CURR_SAL with asterisks. CURR_SAL has format D12.2M, so the alphanumeric representation has format A15. The ED_HRS field has format F6.2, so the alphanumeric representation has format A6. The BANK_ACCT field has format I9S, so the alphanumeric representation has format A9. The alphanumeric representations of the numeric fields are right-justified. The /R options in the PRINT command cause the column titles to be right-justified over the values:

DEFINE FILE EMPLOYEE
ASAL/A15 = FPRINT(CURR_SAL, 'D12.2M', ASAL);
ASAL/A15 = STRREP(15, ASAL, 1, ' ', 1, '*', 15, ASAL);
AED/A6 = FPRINT(ED_HRS, 'F6.2', AED);
ABANK/A9 = FPRINT(BANK_ACCT, 'I9S', ABANK);
END
TABLE FILE EMPLOYEE 
PRINT CURR_SAL ASAL
ED_HRS AED/R
BANK_ACCT ABANK/R
WHERE BANK_NAME NE ' '
ON TABLE SET PAGE NOPAGE
END

The output is:

  CURR_SAL  ASAL             ED_HRS     AED  BANK_ACCT      ABANK
  --------  ----             ------  ------  ---------  ---------
$18,480.00  *****$18,480.00   50.00   50.00   40950036   40950036
$29,700.00  *****$29,700.00     .00     .00     160633     160633
$26,862.00  *****$26,862.00   30.00   30.00  819000702  819000702
$21,780.00  *****$21,780.00   75.00   75.00  122850108  122850108
$16,100.00  *****$16,100.00   50.00   50.00  136500120  136500120
$27,062.00  *****$27,062.00   45.00   45.00  163800144  163800144

Example: Converting Alphanumeric and Numeric Date Fields to Alphanumeric Format

The following request against the EMPLOYEE data source converts the HIRE_DATE field to alphanumeric format. It also creates an alphanumeric date field named ADATE and converts it to its alphanumeric representation. The HIRE_DATE field has format I6YMD and the ADATE field has format A6YMD, so the alphanumeric representations have format A8 to account for the slashes between the date components. The /R option right-justifies the column titles over the field values:

DEFINE FILE EMPLOYEE 
AHDATE/A8 = FPRINT(HIRE_DATE,'I6YMD', AHDATE);
ADATE/A6YMD = EDIT(HIRE_DATE);
AADATE/A8 = FPRINT(ADATE,'A6YMD', AADATE);
END
TABLE FILE EMPLOYEE
PRINT HIRE_DATE AHDATE/R 
ADATE AADATE/R
ON TABLE SET PAGE NOPAGE
END

The output is:

HIRE_DATE    AHDATE  ADATE       AADATE
---------  --------  -----     --------
 80/06/02  80/06/02  80/06/02  80/06/02
 81/07/01  81/07/01  81/07/01  81/07/01
 82/05/01  82/05/01  82/05/01  82/05/01
 82/01/04  82/01/04  82/01/04  82/01/04
 82/08/01  82/08/01  82/08/01  82/08/01
 82/01/04  82/01/04  82/01/04  82/01/04
 82/07/01  82/07/01  82/07/01  82/07/01
 81/07/01  81/07/01  81/07/01  81/07/01
 82/04/01  82/04/01  82/04/01  82/04/01
 82/02/02  82/02/02  82/02/02  82/02/02
 82/04/01  82/04/01  82/04/01  82/04/01
 81/11/02  81/11/02  81/11/02  81/11/02

Example: Converting a Date Field to Alphanumeric Format

The following request against the VIDEOTRK data source converts the TRANSDATE (YMD) field to alphanumeric format. The alphanumeric representation has format A8 to account for the slashes between the date components:

DEFINE FILE VIDEOTRK
ALPHA_DATE/A8  = FPRINT(TRANSDATE,'YMD', ALPHA_DATE);
END 
TABLE FILE VIDEOTRK
PRINT TRANSDATE ALPHA_DATE
WHERE TRANSDATE LE '91/06/20'
ON TABLE SET PAGE NOPAGE 
END

The output is:

TRANSDATE  ALPHA_DATE
---------  ----------
91/06/19   91/06/19
91/06/17   91/06/17
91/06/20   91/06/20
91/06/19   91/06/19
91/06/18   91/06/18
91/06/17   91/06/17
91/06/17   91/06/17
91/06/17   91/06/17
91/06/20   91/06/20
91/06/19   91/06/19
91/06/18   91/06/18
91/06/19   91/06/19
91/06/18   91/06/18
91/06/20   91/06/20
91/06/18   91/06/18
91/06/20   91/06/20
91/06/19   91/06/19
91/06/17   91/06/17

Example: Converting a Date-Time Field to Alphanumeric Format and Creating a HOLD File

The following request against the VIDEOTR2 data source converts the TRANSDATE (HYYMDI) field to alphanumeric format. The alphanumeric representation has format A16 to account for a four-digit year, two-digit month, two-digit day, two slashes between the date components, a space between the date and time, a two-digit hour, a colon between the hour and minute components, and a two-digit minute:

DEFINE FILE VIDEOTR2 
DATE/I4 = HPART(TRANSDATE, 'YEAR', 'I4');
ALPHA_DATE/A16 = FPRINT(TRANSDATE,'HYYMDI', ALPHA_DATE);
END
TABLE FILE VIDEOTR2
PRINT TRANSDATE ALPHA_DATE/R
WHERE DATE EQ '1991'
ON TABLE SET PAGE NOPAGE
END

The output is:

TRANSDATE               ALPHA_DATE
---------         ----------------
1991/06/27 02:45  1991/06/27 02:45
1991/06/20 05:15  1991/06/20 05:15
1991/06/21 07:11  1991/06/21 07:11
1991/06/21 01:10  1991/06/21 01:10
1991/06/19 07:18  1991/06/19 07:18
1991/06/19 04:11  1991/06/19 04:11
1991/06/25 01:19  1991/06/25 01:19
1991/06/24 04:43  1991/06/24 04:43
1991/06/24 02:08  1991/06/24 02:08
1991/06/25 01:17  1991/06/25 01:17
1991/06/27 01:17  1991/06/27 01:17
1991/11/17 11:28  1991/11/17 11:28
1991/06/24 10:27  1991/06/24 10:27

If you hold the output in a comma-delimited or other alphanumeric output file, you can see that while the original field propagates only the numeric representation of the value, the converted field propagates the display options as well:

DEFINE FILE VIDEOTR2 
DATE/I4 = HPART(TRANSDATE, 'YEAR', 'I4');
ALPHA_DATE/A16 = FPRINT(TRANSDATE,'HYYMDI', ALPHA_DATE);
END 
TABLE FILE VIDEOTR2
PRINT TRANSDATE ALPHA_DATE/R
WHERE DATE EQ '1991'
ON TABLE HOLD FORMAT COMMA
END

The HOLD file follows. The first field represents the original data, and the second field contains the converted values with display options:

"19910627024500000","1991/06/27 02:45"
"19910620051500000","1991/06/20 05:15"
"19910621071100000","1991/06/21 07:11"
"19910621011000000","1991/06/21 01:10"
"19910619071800000","1991/06/19 07:18"
"19910619041100000","1991/06/19 04:11"
"19910625011900000","1991/06/25 01:19"
"19910624044300000","1991/06/24 04:43"
"19910624020800000","1991/06/24 02:08"
"19910625011700000","1991/06/25 01:17"
"19910627011700000","1991/06/27 01:17"
"19911117112800000","1991/11/17 11:28"
"19910624102700000","1991/06/24 10:27"