Crystal Reports for Eclipse Designer Guide

Using the If expression (Crystal syntax)

The If expression is one of the most widely used features of Crystal syntax. It also provides insight into the nature of expressions. Consider the earlier If expression as a separate formula. Notice that because this formula is a single expression, it does not need a semicolon:
If {Orders Detail.Quantity} > 1 Then
   "multiple units"
Else
   "one unit"
Suppose you wanted to modify this formula so that it either prints "multiple units" or the number 1.
//An erroneous formula
If {Orders Detail.Quantity} > 1 Then
   "multiple units"
Else
   1
This formula will result in an error. This is because the values in this expression are different types: "multiple units" is a String value and 1 is a Number value. Crystal Reports requires that the value of an expression always be of a single type.

Note: This example can be corrected by using the CStr function to convert the Number 1 to a String value. For example, the Number 1 is converted to the string "1" by calling CStr (1, 0).
//A correct formula
If {Orders Detail.Quantity} > 1 Then
   "multiple units"
Else
   CStr (1, 0) //Use 0 decimals



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/