**Writing Efficient Payroll Calculation Formulas**

The following statements are true as general guidelines for typical payroll runs:

- The longer an element's formula, the longer its processing time.

- The more elements entered for an assignment, the longer its processing time.

- One element associated with a lengthy formula usually processes faster than two related elements each associated with a short formula.

- The overall number of elements and formulas in the system has little effect on processing efficiency. It is the number of elements per assignment that affects processing time.

**Formula Format**

Use comments and white space freely when entering formulas. This makes the formulas easier to read and understand, and has no effect on performance or memory usage. Use indentation for the same reason, especially when you are using brackets to control the order of processing.
It is good practice to include the following information in a comment at the beginning of a formula:

- formula title and short statement of its purpose

- description of formula inputs

- list of variables and constants that may require updating

- description of the input values of the element that receives the formula's direct result

- explanation of the formula's calculations

- administrative information such as the name, address and telephone number of an office administering the earnings, deduction, or charge the formula affects

- the dates of formula modifications, the names of those entering the edits, and possibly the reasons for change

**Variable Names and Aliases**

Use names that are brief yet meaningful to improve readability. Name length has no effect on performance or memory usage. Use Aliases if the names of database items or global values are long.

**Input Statements**

Use Input statements rather than database items whenever possible. This improves formula processing by as much as a factor of ten. It speeds up the running of your payroll by eliminating the need to access the database for the input values.
*Inefficient:*

` Salary = Salary_annual_salary / 12`

` RETURN Salary`

*Efficient:*

` INPUTS ARE Annual_salary`

` Salary = Annual_salary / 12`

` RETURN Salary`

**Date Literals**

Use the TO_DATE function only when the operand is a variable.
*Inefficient:*

` Start_date = TO_DATE ( '12-JAN-1992' )`

*Efficient:*

` Start_date = '12-JAN-1992' (date)`

**Single Expressions**

Use a single expression in straightforward formulas where this does not lead to confusion.
*Inefficient:*

` Temp = Salary / Annualizing_factor`

` Tax = Temp * 3 `

*Efficient:*

` Tax = (Salary / Annualizing_factor) * 3`

**Database Items**

Do not refer to database items until you need them. People sometimes list at the top of a formula all the database items the formula might need, thinking this helps Oracle FastFormula process more quickly. However, this in fact slows processing by causing unnecessary database calls.
*Inefficient:*

` S = Salary`

` A = Age`

` IF S < 20000 THEN`

` IF A < 20 THEN`

` Training_allowance = 30`

` ELSE`

` Training_allowance = 0`

*Efficient:*

` IF Salary < 20000 THEN`

` IF Age < 20 THEN`

` Training_allowance = 30`

` ELSE`

` Training_allowance = 0`

The first example always causes a database fetch for Age whereas the second only fetches Age if Salary is less than 20000.