.Tformat Statement--Change Format of Column Output Temporarily
The .tformat statement changes the format temporarily for the output of a column.
This statement has the following format:
.tformat | .tfmt columnname{, columnname} (format)
{, columnname{, columnname} (format)}
The parameters for the .tformat statement are as follows:
columnname
The name of a column in the report. You can specify the column name as a delimited identifier by enclosing it in double quotes ("), if you have previously specified the .delimid statement.
format
A valid printing format, as described in Format Specifications. The format must be the correct type for the column(s).
The columnname and format can be expressed as variables. The comma (,) and the parentheses () must be stated explicitly and cannot be part of the columnname or format variables.
$columnvariable
Variable whose value is a name of a column in the report. Precede the variable with a dollar sign ($).
$formatvariable
Variable whose value is a name of a printing format described in Format Specifications. The format must evaluate to the correct type for the column(s). Precede the variable with a dollar sign ($).
Description
The .tformat statement temporarily changes the format used to print out the value of a column. After Report-Writer prints the column using this format, the effect of the temporary format is discarded, and when Report-Writer prints the next value in the column, it uses the default format.
For example, reports often include columns containing currency data. If you want to print a leading dollar sign for the currency figure only the first time it appears on a page, you could use the .tformat statement to specify a format of $$$,$$$,$$n.nn for the column in the header action for page breaks. If the normal format for printing the column is zzz,zzz,zzn.nn, then Report-Writer prints the column with a leading dollar sign only the first time it is printed on each page.
Another common use of the .tformat statement is for blanking out the unchanged values of break columns in the detail action for a report. You use the B type format (described in the Blanking Format B section of the chapter "Report-Writer Expressions and Formats") to accomplish this. Specifying a B format, with an appropriate field width as the standard format for printing a column in the detail section, causes Report-Writer to print blanks instead of the value of that column as the default action.
To ensure that Report-Writer prints each new value in the column, specify a printing format in a .tformat statement in the break header for that column. Refer to the use of the .tformat statement for the date column in Account Examples or the examples in this section.
If you specify a variable for columnname, position, and/or width, Report-Writer evaluates the variable during the loading of the report specification, before retrieving any report data.
Examples
1. Print out the value of a break column only when it changes. The acct num column is a delimited identifier.
/*
** In the detail section, blank out the
** account number. When the account number
** changes, print it.
*/
.header report
.format "acct num"(b10),
transact('$$$,$$$,$$$.nn')
.heading "acct num"
.tformat "acct num"(c10)
.detail
.print "acct num"
.tab +2
.print transact
.newline
This is the sample report output for the above specification:
01-34567-8 $345.21
$14.10
$1,143.23
04-35999-2 $1.99
$177.00
2. Print dollar sign at top of page only. The variable thous_dollar evaluates to '$$$,$$n' and thous evaluates to 'ZZZ,ZZn':
.declare thous_dollar = c8 with value '\'$$$,$$n\'',
thous_dollar = c8 with value '\'zzz,zzn\''
.header page
.print 'Top of page' .nl 2,
.tformat salary($thous_dollar)
.detail
.print name(c14), salary($thous)
...
This is the sample report output for the above specification:
Top of page
Jones, A. $23,145
Jones, B. 16,145
Jost, C. 32,143
Last modified date: 08/28/2024