The result of a formula, or the value that is printed when the formula is placed in a report, is called the value returned by the formula. Every formula in Crystal Reports must return a value. For example, here is a simple Crystal syntax formula that returns a value of 10:
10
The value returned by a formula can be one of the seven simple data types supported. These are Number, Currency, String, Boolean, Date, Time, and DateTime.
Note Crystal Reports also supports range types and array types, but these cannot be returned by a formula.
For example, suppose a company has a shipping policy in which orders over $1,000 are insured, but orders below that amount are not insured:
//A formula that returns a String value If {Orders.Order Amount} >= 1000 Then "Insured shipping" Else "Regular shipping"
The formula returns the text string value "Insured shipping" if the value of the database field {Orders.Order Amount} is greater than or equal to 1000; otherwise, it returns the text string value "Regular Shipping" otherwise.
A Crystal syntax formula consists of a sequence of expressions. An expression is any combination of keywords, operators, functions, and constant values that result in a value of a given type. The value of the final expression is the value returned by the formula and what gets printed. Each expression must be separated from the previous expression by a semicolon (;).
The fact that a Crystal syntax formula is a sequence of expressions whose result is the value of the final expression is the most important concept in understanding Crystal syntax. This expression-based syntax allows you to write very short formulas with a lot of functionality.
All variable names, functions, and keywords used in a Crystal syntax formula are not case-sensitive. For example, the keyword Then could equivalently be typed in as then or THEN.
The only exception to this rule is for strings. The string "Hello" is not the same as the string "hello".
Many of the examples in this section refer to the Xtreme sample database, which can be downloaded from the Java Developer Zone. To download the Xtreme sample database, go to http://www.businessobjects.com/products/dev_zone/java/default.asp.