12. Report-Writer Statements : Conditional and Assignment Statements : .If Statement--Specify Alternative Statements : Examples
 
Share this page                  
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