Report-Writer Expressions and Formats
Expressions in Report-Writer
In Report-Writer, expressions are used to obtain data values in your report. Expressions are composed of constants, variables, columns, aggregates, and functions that are combined with operators to produce a single value. Each of these types of expressions is described in this chapter.
Many Report-Writer statements accept expressions that provide users control and flexibility in determining report values. In general, Report-Writer statements can be divided into the following two categories:
• Statements that accept only variables and are evaluated once during the loading of the report specification before retrieving the report data.
• Statements that accept any expression appropriate in the context of the statement and are evaluated each time the statement is executed.
For ways to use expressions in a given statement, see each individual statement in the chapter "Report-Writer Statements."
The .print and .query statements are two statements in which you often use variables and expressions. One way you use variables in the .query statement is in the where clause to retrieve a subset of the data. In the .print statement, you can use expressions to print multi‑column functions, such as adding columns together, or to determine the printing format.
You can compare expressions to other expressions in conditions for the .if statement, or use them in the .let statement to specify a value to be assigned to a variable. For details on conditional and assignment statements, see the chapter "Report-Writer Statements."
The following example uses several expressions. The example uses a database, which has a table of shipments featuring part number, number of defective parts in a shipment, and the total number of parts in a particular shipment. Suppose you want a report of the shipments grouped by part number, with the calculated percentage of defective parts for all the shipments of that part. The following report fragment would accomplish this:
.sort partno
.
.
.
.footer partno
.print partno, ' IS '
.print (sum (defective)/sum (total)) * 100,
' % DEFECTIVE '
.newline
In the previous example, the following are expressions:
partno
' IS '
(sum(defective)/sum(total)) * 100
'% DEFECTIVE'
Because no print formats have been explicitly specified in the preceding report code, Report-Writer automatically uses predetermined ones.