Previous | Next | Contents | Index | Navigation | Glossary | Library |
You can use formulas to:
Formulas for QuickPaint reports and assignment sets can be generated from criteria you enter in windows. You can edit these generated formulas to add more functionality.
To start with a simple example, suppose you wanted to calculate the pay value for the element Wage by multiplying the number of hours an employee works each week by his hourly rate. You could write this formula:
wage = hours_worked * hourly_rate
RETURN wage
The first line is an Assignment statement that simply assigns a value to the element Wage. The second line is a Return statement that passes back the Wage value to the payroll run.
In this example, the Wage value is calculated, but it could be a constant value, such as: wage = 200. To calculate the Wage value, Oracle FastFormula needs to get values for the variables hours_worked and hourly_rate. They are called variables because they can contain different values depending, in this example, on which assignment the payroll run is processing.
INPUTS ARE hours_worked
wage = hours_worked * hourly_rate
RETURN wage
The name you use in the Inputs statement must be the same as the name of the element input value, and multiple words must be joined by underscores. In this example, the input value hours_worked is numeric. If the input value is not numeric, you must tell Oracle FastFormula whether it is text or date. For example:
INPUTS ARE start_date (date)
In the Formulas window, you pick database items from a list. You will see that the name of the database item for a grade rate called hourly_rate is actually grade_hourly_rate_value. This is the name you must use in your formula.
By this naming convention, Oracle FastFormula knows that hourly_rate is a database item from the Grade Rate table. But how does it know which hourly_rate to use from this table? It works this out from the context the payroll run provides for each element entry. The context identifies:
Attention: You should use an Inputs statement in preference to database items where possible because this is more efficient.
See: Writing Efficient Payroll Calculation Formulas.
wage = hours_worked * hourly_rate
Note: You cannot change the value of input values, database items, or global values within a formula.
bonus = GREATEST(days_at_work,163) + bonus_rate
Here the function GREATEST tells Oracle FastFormula to use the value of the variable days_at_work, if it is greater than 163, and otherwise to use the constant 163.
The data type of variables and constants determines how operators and functions act on the values. For example, the addition operator (+) can be used with numeric or text data, while division can be used with numeric data only.
There are special functions that convert variables from:
ANNUAL_BONUS = trunc(((((salary_amount/100)*
bonus_percentage)/183)*(days_between(end_period_date,
start_date) + 1)), 2)
Oracle FastFormula begins calculating inside the brackets and from left to right, in the following steps:
IF age < 20 THEN
training_allowance = 30
ELSE
training_allowance = 0
The formula checks whether the condition (age < 20) is true or false. If it is true, the formula processes the statement that follows the word THEN. If the condition is not true, the formula ignores this statement and processes any statement that follows the word ELSE. The ELSE clause is optional.
IF (DAYS_BETWEEN(end_period_date, start_date)+1) >= threshold
DAYS_BETWEEN is another function.
We have seen two comparators: less than (<) and greater than or equal to (>=). A full list of the comparators you can use appears in the Reference section.
See: Oracle FastFormula Reference
DEFAULT FOR hourly_rate IS 3.00
X = hours_worked * hourly_rate
IF hourly_rate WAS DEFAULTED
THEN
MESG = 'Warning: hourly rate defaulted'
In this example, if the database item hourly_rate is empty (NULL), the formula uses the default value of 3.00 and issues a warning message.
IF (days_between(end_period_date, start_date) + 1) >= 183
AND employee_status = 'FULL TIME'
THEN . . .
IF stock_level < 10000
OR order_size >= 1500
THEN . . .
IF NOT (months_between(purchase_date, system_date) => 60
THEN . . .
As with Assignment statements, you may need to use brackets to tell Oracle FastFormula in which order to test conditions. By default, NOT has the highest precedence, followed by AND then OR. So the following condition:
IF X = 6 AND NOT Y = 7 OR P >= 6
is interpreted as:
IF (X = 6 AND (NOT Y = 7)) OR P >= 6
How you use brackets can change dramatically the meaning of a formula.
Suggestion: Use brackets whenever you create multiple conditions, so that the meaning of the formula is clear to other readers.
For example, suppose you must check whether there are sufficient funds in a bank account before processing a withdrawal:
INPUTS ARE acct_balance,
acct (text),
debit_amt
IF acct_balance >= debit_amt
THEN
(
new_balance = acct_balance - debit_amt
RETURN new_balance
)
ELSE
(
message = 'Account No. ' + acct + ' - Insufficient Funds'
message2 = 'Account Balance is ' + TO_TEXT(acct_balance)
RETURN message, message2
)
Notice that you can return two variables in the same Return statement.
Attention: The brackets following THEN and ELSE are essential when you have multiple actions based on a condition. Without them, Oracle FastFormula processes the first statement conditionally and the other statements unconditionally.
So, for example, you can name your formula:
/* Formula: Attendance Bonus */
and write an explanation of your formula:
/* Use this formula to calculate the annual bonus for clerical staff. Employees receive either a percentage of their salary (if they have been present for 183 or more days in the last six months), or a pro rata bonus (if they have been in attendance for less than 183 days in the last six months). */
Oracle FastFormula ignores everything between the comment delimiters: /* and */. You can place comments anywhere in a formula without affecting the formula's performance.
Warning: Do not put a comment within a comment. This causes Oracle FastFormula to return a syntax error.
You can use a comment to explain what part of your formula does. So, for example, you might want a comment explaining who decides the bonus percentage:
INPUTS ARE salary_amount,
start_date (date),
end_period_date (date),
bonus_percentage /* decided at board level */
You can also use comments to `comment out' parts of the formula you do not currently want to use. So, for example, you can include a fifth input of employee_status, ensuring that employees with a status of full time are awarded a bonus. However, as you do not yet have a range of statuses, you do not currently need the fifth input.
INPUTS ARE salary_amount,
start_date (date),
end_period_date (date),
bonus_percentage /* decided at board level */
/* employee_status (text) */
We have already looked at four types of statement:
ALIAS as_overtime_qualifying_length_of_service AS ot_qls
In the rest of the formula, you can use the alias (in this example, ot_qls) as if it were the actual variable.
Attention: Using an Alias is more efficient than assigning the database item to a local variable with a short name.
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. The formula uses the 'WAS DEFAULTED' test to detect when a default value is used, in which case it 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 choose the Show Items button on the Formulas window.
1) ALIAS statements (if any)
2) DEFAULT FOR statements (if any)
3) INPUT statement (if any)
4) Other statements
Previous | Next | Contents | Index | Navigation | Glossary | Library |