Constants and Variables
Every piece of information that you can manipulate or use in a formula is a constant or a variable.
The data type of a constant or variable describes what kind of data the constant or variable holds. Generally, you use constant and variables of the same data type in an expression.
Constants are actual values you use in a formula. Oracle FastFormula uses constants directly rather than holding them in a variable.
There are three types of constant:
Numeric Constants
Enter numeric constants without quotes. Precede negative numbers with a minus sign (-). Numbers may have a decimal component after a decimal point. Do not use exponents and floating point (scientific) notations. So, for example, you cannot use 22 or 10e1.24 as numeric constants. Do not use commas or spaces in a number. So, for example, you cannot use 10,000 or 10 000.00 numeric constants.
Examples of valid numeric constants are:
Text Constants
Enclose text constants in single quotes. They may contain spaces. You can represent the single quote character in a text constant by writing it twice (''). Note that this is not the same as the double quote ("). Examples of valid text constants are:
- `The Bonus this year is 23%'
Date Constants
Date constants contain a date. Enclose dates in single quotes and follow immediately with the word date, in brackets. Use the format DD-MON-YYYY.
Examples of valid date constants are:
You use variables in a formula to access information. Variables can have frequently changing values.
The data type of a variable determines the type of information the variable holds:
You do not have to tell Oracle FastFormula what type you want a variable to be. It works this out by seeing how you use the variable. For example, if you set a variable to `J. Smith', Oracle FastFormula knows it is a text variable.
Oracle FastFormula also warns you if you try to perform any inconsistent operations, such as trying to add a number to a text string.
There are three classes of variable in Oracle FastFormula:
Local Variable
| Variables that occur in a single formula only.
|
Global Value
| Values that can occur in any formula.
|
Database Item
| Items that exist in the application's database.
|
The variable class determines how a formula uses it.
Local Variables
Local variables occur in a single formula only. You can change a local variable within the formula by assigning a value to it using an Assignment statement.
You can use local variables to store data in a formula. You might want to hold data temporarily while you perform some other calculations, or to pass data back to the application.
Below is an example showing the use of a local variable, annual_leave.
/* Formula: Annual Leave Formula */
IF years_service >= 10
THEN
annual_leave = 25
ELSE
annual_leave = 20 + FLOOR (years_service/2)
RETURN annual_leave
Global Values
Global values are visible from within any formula. Use global values to store information that does not change often, but you refer to frequently, such as company name, or a location allowance that applies to many employees. Global values are datetracked so you can make date effective changes ahead of time.
You can never change a global value using a formula. You alter global values using the Globals window. The global value is the same across all formulas within a Business Group.
See: Using the Globals Window
Below is an example using a global value.
/* Formula: HAZARD ALLOWANCE FORMULA */
IF basic_hours > hazard_limit
THEN
hazard_allowance = 2.30
ELSE
hazard_allowance = 2.00
RETURN hazard_allowance
In this example, hazard_limit is a global value, which has been preset to reflect the point at which workers' hazard payment increases.
Database Items
Database items exist in the application database and have a label, hidden from users, that the system uses to find the data.
There are two types of database item:
- Static database items are predefined. They include standard types of information, such as the sex, birth date, and work location of an employee, or the start and end dates of a payroll period.
- Dynamic database items are generated from your definitions of:
- grade rates and pay scale rates
The name of your element, pay and input values, balance, absence type, grade rate, pay scale rate, or flexfield segment becomes part of the name of the generated database item. This helps you identify the database item you need when you display a list of all available items in the Formulas window.
Definitions of flexfield segments only become database items when you initiate the Declare Descriptive Flexfield process from the Submit Requests window. The other definitions become database items immediately when you save them to the database.
See:
Static Database Items
Dynamic Database Items.
Database items are specific to the context in which you use them. For example, using the database item hourly_rate gives the appropriate hourly rate for the specific assignment being processed.
Like global values, database item values cannot be changed within a formula.
Rules for Determining Variable Class and Data Type
The rules that determine the data type and class of variables in a formula are:
1. The variable can be an input you name in the Inputs statement. For example:
INPUTS ARE salary_amount,
start_date (date)
frequency (text)
If you do not specify the variable type in the statement, Oracle FastFormula assumes it is numeric.
2. If the variable is not an input, Oracle FastFormula looks in the list of global values the first time the variable occurs. If the variable is in the list, Oracle FastFormula determines the data type from there.
3. If the variable is not in the list, Oracle FastFormula searches the list of database items. Again, if it is in the list, Oracle FastFormula knows the data type.
4. Finally, if Oracle FastFormula does not find the variable in either the global values or the database items, then it treats the variable as a local variable. It determines the data type from the way you use the variable.
Notice that if the variable is either a global value or a database item, then any attempt in your formula to alter the value of the variable causes an error.
If the variable is a local variable, it does not contain a value when it is first used in the formula. Therefore you must assign a value to the variable before you try to use it in a condition or expression. If you fail to assign a value, Oracle FastFormula fails when you attempt to verify or run the formula.
Suggestion: To avoid a failure, assign values to your local variables when they first appear in your formula.
Naming Variables
Variables have names comprising one or more words. The words must be joined by underscores. The words must each start with an alphabetic character (A-Z) and can be followed by alphanumeric characters (A-Z, 0-9). The maximum size of a variable name is 80 characters.
Oracle FastFormula is not sensitive to case. So, for example, the variable called EMPLOYEE_NAME is the same as the variable Employee_name.
There are a number of words you cannot use as the names of variables. These reserved words are:
ALIAS
| AND
| ARE
| AS
|
DEFAULT
| DEFAULTED
| ELSE
| EXECUTE
|
FOR
| IF
| INPUTS
| IS
|
NOT
| OR
| RETURN
| THEN
|
USING
| WAS
|
|
|
And any word consisting only of digits (that is, that could be treated as a number).
You may find that the name of a database item or global value is too long to use conveniently in your formula. You can set up an alternative, shorter name for use within a formula. You set this up using the Alias statement.
See: Statements