Was this helpful?
.Print and .Println Statements--Print Text of Report
The .print and .println statements print literal text strings, columns from the database, or expressions on the report.
These statements have the following formats:
.print | .pr | .p expression[(format)]{, expression[(format)]}
.println | .prln | .pln expression[(format)]{, expression[(format)]}
The parameters for the .print statement are as follows:
expression
Any legal expression. For more information, see the chapter "Report-Writer Expressions and Formats." You can specify a column name in an expression as a delimited identifier by enclosing it in double quotes ("), if you have previously specified the .delimid statement.
format
An optional printing format for the expression, as described in Format Specifications. The format must be the correct type for the expression. If you do not specify a format, Report-Writer uses one of the default formats listed in the chapter "Report-Writer Expressions and Formats."
The format can be expressed as a variable ($formatvariable). The parentheses ( ) must be stated explicitly and cannot be part of the format variable. The comma (,) must be stated explicitly and cannot be part of the expression.
$formatvariable
Variable whose value is the name for 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 ($). Report-Writer evaluates $formatvariables, but not expressions, at load time.
Description
The .print statement specifies text to be included in the body of the report. Text can be character strings printed directly, data items from the data table, variables, aggregates, or a combination of these. Report-Writer includes the text at the place in the report where it encounters the .print statement. By preceding the .print statement with the positioning statements such as .newline, .tab, .center, .right, or .left, you can specify the location of the text. By default, Report-Writer includes the text immediately after the last text output with the .print statement.
Report-Writer evaluates any print expressions that are used as parameters to the .print statement during runtime. You can include as many expressions as you want in the .print statement; Report-Writer adds them to the report in the order specified.
If the expression is a runtime variable for a column name (for example, .print $account_type), Report-Writer prints the name of the column as entered at runtime, rather than its data. To print the data rather than the column name, you use the select column_list as resultcolumn_list construct in the query and reference the resultcolumn_list name in the .print statement. For more information, see the .Query statement.
If you use the optional .println form of the statement, the current print position advances to the next line after the specified text is printed.
Data that formats into a single logical line can wrap to yield a default maximum of 310 physical lines as protection against omitted explicit .newline and/or .newpage statements. You can override this limit by specifying the ‑wmxwap parameter in the report command.
IMPORTANT!   Embedding tabs in a string can truncate the string if it is printed with a default format or with a format that is not large enough to allow the tab to be expanded into spaces. To print string sthat contain tabs, use a specified format wide enough for the expanded tab(s).
Examples
1. Assume a report specification with the following literals:
.print 'Text may'
    ' span several lines.'
It would print the following output:
Text may span several lines.
Because there was no specification statement such as a .tab or a .newline to separate the fields, the two text strings printed immediately adjacent to each other on the same line of the output.
2. In this example, assume that page_numberis equal to 3.
.pr 'Page number:', page_number(zz)
Report-Writer would print the following text:
Page number: 3
3. The following example shows the specifications you need to print a data value (represented by a delimited identifier for the column name) and an aggregate, using a numeric template for the aggregate where the value of millions_fmt is 'nnn,nnn,nnn.nn':
.print "acct bal", sum("acct bal")($millions_fmt)
4. A complex .print statement that displays a large number of data items can look like the following:
.print 'Values of the data are: ', var1,
                 var2(e20.4) cvar1(c40), ' and finally',
                 lastvar (' $$$,$$$,$$$.nnCR')
Note that in the previous example, the field, var1, was listed without a format. Report-Writer prints the value with the default format for the data type, according to the table in Default Formats, in the chapter "Report-Writer Expressions and Formats." It is acceptable to mix the default data formats with extremely complex templates. Using an acceptable default format saves you the time and effort of specifying every format in detail.
Last modified date: 01/30/2023