Previous  Next          Contents  Index  Navigation  Glossary  Library

Statements

Statements are instructions that Oracle FastFormula carries out. There are six types of statement you can use:

An If statement can have Assignment, Return, and other If statements nested within it, enabling you to build up powerful formulas.

Order of Statements

1) Alias statements (if any)

2) Default statements (if any)

3) Input statement (if any)

4) Other statements


Alias Statement

The format of the Alias statement is:

	ALIAS varname1 AS varname2

where varname1 is the name of an existing database item or global value, and varname2 is a unique name not currently known to the system nor used previously in your formula.

Use the Alias statement to define another name, or alias, for existing variables in the system. You can declare aliases for database items and global values.

Alias statements must appear before any other statements in a formula.


Default Statement

The format of the Default statement is:

	DEFAULT FOR <varname> IS <constant>

where varname is an input value or database item, and constant is a constant value matching the data type of varname.

Use the Default statement to set a default value for an input value or database item. The formula uses the default value if the database item is empty or the input value is not provided when you run the formula.

You can use the Default statement with the 'WAS DEFAULTED' test to detect when a default value has been used. For example:

	DEFAULT FOR hourly_rate IS 3.00
	X = hours_worked * hourly_rate
	IF hourly_rate WAS DEFAULTED
	  THEN
	    MESG = 'Warning: hourly rate defaulted'

This example sets a default of 3.00 for the database item hourly_rate. If hourly_rate is empty (NULL) in the database, the formula uses the default value of 3.00 and issues a warning message.

Attention: You must use the Default statement for database items that can be empty. The Database Items window includes a check box labelled Default Required. This check box is checked for database items that can be empty. The Database Items window appears when you click the Show Items button on the Formulas window.


Inputs Statement

The format of the Inputs statement is:

	INPUTS ARE varname1(data type)[, varname2 (data type)] ...

Use the Inputs statement to pass input values from an element into a formula.

For example,

	INPUTS ARE bonus	(number),
	           start_date	(date)

You do not need to declare the type of number variables because this is the default data type. You can define up to 15 input values for an element.

The Inputs statement must appear before the other formula statements except:

Input Variables or Database Items

Always use the Inputs statement to retrieve the input values of the element associated with the formula. Using a database item forces the formula to execute the code and work out the path to retrieve the database item.

For example, the formula below:

	INPUTS ARE wage_rate,
	           hours_worked
	wage = wage_rate * hours_worked
	RETURN wage

is more efficient than the second formula:

	wage = wage_wage_rate * wage_hours_worked
	RETURN wage


Assignment Statement

Use the Assignment statement to set a value for a local variable. The format of the Assignment statement is:

	varname = expression

For example:

	rate = hourly_rate + 14
	wage = hours_worked * rate

Oracle FastFormula evaluates the expression on the right hand side of the statement, and places its result in the variable you name in the left hand side. The left side of an Assignment statement must always be a local variable because a formula can only change the value of local variables.


IF Statement

Use the If statement to set a condition that controls whether a sequence of statements is executed.

There are two clauses in the If statement: the THEN and ELSE clauses.

The If statement is the only statement that can have other statements nested within it, including other IF statements.

Format of Statement

The format of the If statement is:

	IF [NOT] condition
	[logical operator] [NOT] condition
	THEN
	    statement [statement ..]
	ELSE
	    statement [statement ..]

The If statement can consist of a single condition, or two or more conditions combined with logical operators. A logical operator is either AND or OR. These have the effect of combining the conditions logically:

Also, each condition can be preceded by the NOT operator, which inverts the truth of the condition. That is, if condition X is true, then NOT X is false.

Format of Conditions

A condition itself has a valid format. This is:

	expression comparator expression

The values represented by each expression are compared together in the way described by the comparator. The two expressions must both return the same data type. There are eight comparators, and the way they work depends upon the data type of the values they are comparing.

Comparator Symbols Data Types Meaning
Equals = All The condition is true if both expressions have exactly the same value. For text, the case of the expression must be the same. So, for example, 'Smith' is not equal to 'SMITH'.
Not Equal to != <> >< All The condition is true if the result of the first expression does NOT have the same value as the result of the second expression.
Greater than > All The condition is true if the first expression is alphabetically after, or has a numerically greater value, or a later date than the second expression.
Less than < All The condition is true if the first expression is alphabetically before, or has a numerically smaller value, or an earlier date than the second expression.
Greater than or equal to >= => All The condition is true if either the greater than OR the equal to comparator returns a true result.
Less than or equal to <= =< All The condition is true if either the less than OR the equal to comparator returns a true result.
Like LIKE Text The condition is true if the two text expressions match according to the rules of the LIKE syntax. You can include Wildcards in the text to allow searching for text that matches a pattern, or words that begin with a certain sequence of letters. - percent sign (%) matches any number of characters in that position - underscore (_) matches a single character occurrence in that position.
Not Like NOT LIKE Text The condition is true if the two text expressions do NOT match according to the rules of the LIKE syntax.

There is a special comparator called WAS DEFAULTED that you can use to test database items and input values. If there is no value available for an input value or database item, the formula uses a default value. The condition containing the WAS DEFAULTED comparator is True if a default value was used. For example:

	DEFAULT FOR employee_middle_name IS ' '
	  IF  employee_middle_name WAS DEFAULTED
	    THEN
	     /* special processing */

Correct Use of Brackets

If you group more than one statement under the THEN or ELSE clauses, enclose the group of statements within brackets, that is ( and ). In the absence of brackets, Oracle FastFormula conditionally executes only the statement that immediately follows the THEN or ELSE clause. Any other statements are executed unconditionally. For example, when the following formula runs, High_salary is always set to Y:

	High_salary = 'N'
	IF Salary > 20000 
	  THEN Tax = Salary * .25
	       High_salary = 'Y'

To prevent this, use brackets as follows:

	High_salary = 'N'
	IF Salary > 20000
	  THEN 
	 (
	  Tax = Salary * .25
	  High_salary = 'Y'
	  )


Return Statement

Use the Return statement to return values in local variables to the application. Oracle FastFormula can pass back any number of variables. The variable does not need to contain a value.

Example:

	/* Formula: LONDON ALLOWANCE FORMULA */
	INPUTS ARE this_months_extra (number)
	London_allowance = (grade_pay/20 + this_months_extra)
	RETURN London_allowance

Notice that you do not have to declare the data type of local variables in the Return statement (as the formula already knows the data type).

Oracle FastFormula stops executing the formula when it reaches the Return statement. Any statements after the Return statement are ignored.


         Previous  Next          Contents  Index  Navigation  Glossary  Library