.Format Statement--Set Default Printing Format
The .format statement sets up a default printing format for a column or set of columns.
This statement has the following format:
.format | .fmt columnname{, columnname} (format)
{, columnname{, columnname} (format)}
The parameters for the .format 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.
The columnname can be expressed as a variable. The comma (,) and the parentheses ( ) must be stated explicitly and cannot be part of the columnname or format variable.
format
A valid printing format, as described in
Format Specifications. The format must be the correct type for the column(s).
The format can be expressed as a variable. The comma (,) and the parentheses ( ) must be stated explicitly and cannot be part of the columnname or format variable.
$columnvariable
Variable whose value is a name of a column. Precede the variable with a dollar sign ($).
$formatvariable
The variable whose value is a name of a printing format described in
Format Specifications. The format must evaluate to the correct type for the columns. Precede the variable with a dollar sign ($).
Description
The .format statement sets up a default format associated with a column to be used whenever Report-Writer prints the column or an aggregation of a column.
If you specify variables for the column and/or format, Report-Writer evaluates columnvariable and formatvariable during the loading of the report specification, before retrieving any report data.
Because the format for a column can determine the default width for that column (used in the .center, .right, and .left statements), you can use the .format statement to control the default width of a column. Report-Writer uses this statement to determine the default width only in the absence of the .width or .position statements, which also specify the default width for a column. You can use .tformat to override the format of a column during the run of the report.
If you do not specify a .format statement for a column, Report-Writer determines the print format by scanning the printing statements in the report. If the printing statements do not specify a format, Report-Writer determines the default.
By default, breaks use the formatted values for any column whose format has been specified in a .format statement. That is, a break occurs for such a column only when the formatted value changes. Otherwise, no break occurs, even if the unformatted value changes. To force Report-Writer to use the actual, rather than the formatted, values to determine breaks, specify the ‑t flag on the
report Command--Run a Report.
Examples
1. This example shows a .format statement that declares formats for several columns, followed by a .print statement that uses the formats specified in the .format statement to print the information.
.format trans, balance ('$$$,$$$,$$$.nn')
.print trans,balance
.newline
2. This example shows a .format statement that declares formats for date columns where date_fmt evaluates to a date format and column names are delimited identifiers.
.format "trans date", "cur date" ($date_fmt)
Last modified date: 08/14/2024