Was this helpful?
.If Statement--Specify Alternative Statements
The .if statement specifies alternative blocks of statements to be executed under specified conditions.
This statement has the following format:
.if condition .then {statement}
    {.elseif condition .then {statement}}
    [.else {statement}]
.endif
The parameters for the .if statement are as follows:
condition
A boolean expression that evaluates to true or false.
statement
Any action statement, including the .if statement (this excludes the setup and structure statements in the sections, Report Setup Statements and Report Structure Statements).
Both the expression in the condition and/or the parameters to statement can contain column names that are delimited identifiers enclosed in double quotes ("), if you have previously specified the .delimid statement.
Description
The .if statement specifies alternative blocks of statements to be executed depending upon the value of the specified condition.
Report-Writer evaluates the conditions in the .if and .elseif clauses one after another. When a condition is met, Report-Writer executes the statements following the subsequent .then statement. If none of the specified conditions is met, Report-Writer does nothing. If none of the conditions is met and there is an .else clause included in the .if statement, Report-Writer executes the statements following the .else statement.
Examples
1. This example illustrates the use of the .if statement to take different actions based on the current condition of the Report-Writer environment. It tests the current character position, and starts a new line if the current position is past the end of a line:
.if position_number > 80 .then
        .newline
.endif
2. This example tests the data and prints different things, depending on the value of some of the report data:
.if balance < 0 .then
        .print '(',-balance, ')'
.else
        .tab +1
        .print balance
.endif
3. This example tests a column value and uses .if statements to translate a numeric code number from the database to a text string for the report, and to selectively print column values accordingly. Notice that both the conditional expression and the .then statements reference column names that are delimited identifiers.
.if "dept code" = 1 .then
        .print 'Books: ', "book sales"
.elseif "dept code" = 2 .then
        .print 'Furniture: ', "furniture sales"
.elseif "dept code" = 3 .then
        .print 'Jewelry: ', "jewelry sales"
.else
        .print 'Misc: ', "misc sales"
.endif
Last modified date: 01/30/2023