Академический Документы
Профессиональный Документы
Культура Документы
Oracle E-Biz is a huge set of programs, combined together in a way that the data across modules are closely connected to
enforce business logic. It is designed with a lot of sophistication, in order to help businesses achieve their goals. Again the
product was designed to cater to all kind of requirements to all sorts of businesses. Hence it is equally scalable, so that
businesses can change the settings in a way their business rules want them to.
Configurability was at the centre of the focus when they built the product. With that in mind, Oracle has tried to give as many
interfaces/ codes as possible, to the functional consultants, where they can key in codes and tweak the flow of the system and
processes as per their demand. However usage of codes is not possible in each and every process of the application. There was
a need of sub-programs that can be written by the Functional guys, so that it will be referred by the application to decide on
the process. Those are like decision making sub-programs that ultimately return values, with which the application can decide
the flow. Those sub-programs are called Fast Formulae.
Fast formulas / Rules are used whenever the codes are not adequate to meet the business requirement. And the codes are not
adequate, because there is a complex logic involved to reach at a decision. But what are codes? If you remember the flags that
we check on the forms, like, we had in Organization screen; we added classifications, and checked the enabled flag. Let’s
concentrate on the enabled flag now. What does it do? It tells the system, that the selected classification is valid and available.
That’s what we call a decisive code, the code that tells the system to do something.
Picture a case where the decision is not so easy like a yes/ no. Think of this example, that the Classification should be valid only
if (A=B and B=C and C<> D). This is where the code cannot be used, and we need a set of statements / subprograms to arrive
at the decision. Those sub programs are called Fast Formulae.
Fast Formula is a Sub-Program that can be written by the functional Consultants. It is written in a language that resembles
SQL, however a lot simplified. Although the syntax is like SQL, it looks a lot like English. It’s a whole language in itself and is
very easy to learn. Even though a lot of functionalities are absent in comparison to SQL, there is provision to achieve any
requirement using Fast Formulae. The trade off for simplicity of the language is the absence of complex functionalities.
Oracle has provided places to attach formulae, whenever there could be a need of a complex logic that a code cannot suffice.
Each and every Fast Formula has a type with a set of allowed Input and Return Values. Let’s learn it as a Programming
language first. Once we know the different programming constructs and the flow of the language, we will then focus on the
input and return values.
Chapter Overview
Learning Outcomes
Variables
While writing a program, we will need different place holders that can hold values. Let’s take an example of a swapping
program. We want to swap the value between A to B. To do this, what should we do? Get a new place holder called X, which
can hold the values for us, and run the following statements.
X=A
A=B
B=X
Here X is a place holder. This place holder is called a variable, which can store a value at one point of time. And the value can
be changed as per the requirement of the program during the execution of the program in other words, at the runtime.
Constants
A Constant is a Variable that does not change its value throughout the program. Like the mathematical value of Pi is
approximately at 3.141. If we wish to change its value to 2, we cannot do it; because it is a constant.
1. If the constant is of type Numeric, then we should not use comma in the numbers.
2. We should not use Exponential values as Constants.
3. The Text Constants should always be in single quotes.
4. If we are using a date constant, we can follow two different types of date formats:
o ‘DD-MON-YYYY’ like: ’01-AUG-1984’
o ‘YYYY-MON-DD HH24:MI:SS’ like ‘1985-JAN-18 14:05:11’
5. If we have multiple language support in our applications, then we must use the second type of dates.
Data Type
So, any Variable or Constant will have to be one of these three data types.
back to top
Expressions
An Expression is a combination of Variables and Constants with either an Arithmetic operator or a Function. We will park
functions as of now, because we are going to learn it later in this chapter. Let’s take the following example with arithmetic
operators to learn about the expressions.
Here RATE is a Variable of type Number. PREMIUM_VALUE is a Constant of numbers and so is EMPLOYER_CONTRIBUTION. Now
the resultant of the arithmetic subtraction between these two numbers will be stored in the variable “Rate”. This entire
sentence can be called as an Expression.
Database Items
In a formula, we might need the details of various stored information to calculate something. For Example, Age of an employee,
Employees basic Salary YTD (Year to date: Basic Salary earned by an employee till date in this year) etc. In a case we need
these types of values; we can get the data from the database by running a query. However fetching these values are difficult
inside a Fast Formula and it drastically impacts the performance of the formula.
To solve this issue, Oracle has come up with a concept of Database Items. These are hidden queries created and stored by
oracle, with a name. We will just have to refer the name in the formula and oracle runs the related query in the backend and
gets us the results.
Global Values
There are few variables that do not change very frequently. For an example, Company wide Bonus Percentage, Company’s
short name etc. these values do not change very frequently. To store these kinds of values, we can use Lookups, but to use the
value in the Fast Formula, we must have a query to get the data from the lookup. So Oracle has provided something called a
Global Variable. The Global value is stored in a date tracked table, and can be easily used, with the Global Variable name. With
this, we do not have to write a query to fetch the value stored in the Global Variable; we can just mention the name and the
formula will fetch the value at the runtime. The Global Variable can be accessed from any fast formula.
Functions
There are a set of functionalities that we need very frequently in fast formulae. Like calculating the Greatest of three numbers,
Average of two numbers etc. Rather than adding the code every time in the fast formula, oracle gives us the liberty of storing
that code somewhere and just using the code whenever necessary. This design is used keeping the code reusability in mind.
Those codes are called Functions. These are few advantages:
Once written the Function can be used in any Fast formula (If contexts match, we will discuss about the contexts later).
Oracle gives us a wide set of seeded functions that can be used in fast formulae.
Oracle enables us to define our own Functions, and use them across formulae.
he User Defined Functions are capable of calling PL/SQL functions, which makes it easy for the user to define complex
business processes with ease.
Writing a Formula
As we are aware, based on the place where it is attached to, the input and the return variables of a formula vary. That is why,
different formula types are defined based on the purpose and provision. Few Examples are:
Each and every formula type has its own set of Input Values and Return values. There are around 150 formula types in HR, and
their details are huge, so it is not possible for us to discuss all sorts of formulae here, however we will discuss a few types that
are important. In case we need to know the specifics of a Particular formula, there are documents available on Oracle support
that we can download. As we had decided earlier, we will focus primarily on the language.
Defining a Formula
We will start with defining a formula. There is just one screen to deal with. See Figure 5.1 – Write Formula.
Variables are the place holders in which we save values for our calculation. Although all the place holders that are used to store
values are known as the Variables; there are different types of them.
Local variables: These are the most frequently used variables. These variables are defined inside a formula, and they
stay valid only within the scope of the formula. We use local variables to store temporary information, which is used
later in the program. In the example of swapping values from A to B, X was the temporary variable. Usually the
frequently changing information is stored in Local Variable.
Global variables: These variables, as the name suggests, has a global scope in comparison to the Local Variables. The
Global variables can be accessed by all Formulae within the application, and the value of a global variable cannot be
updated with in the Formula. We usually store the slowly changing information in these variables. We use the Global
Value screens to create and update Global Variables.
Database Items: The third category of the variable type will be the DBIs. As we know, DBIs are the values retrieved by
stored queries in the application, which is hidden from the front end.
Data types define the type of data being stored in the variable. There can be three types of data in Oracle Fast Formulae:
1. Text
2. Number
3. Date
While defining a variable, we must define its data type. If the data type is not added along with the variable, the compiler takes
it as a Number.
Using Operators
In the example given above, the portion between IF and THEN can be called as an Expression, which looks like this:
Now, the symbols +,-, =, <>, ‘OR’ are called operators. The Operators instruct the compiler about the arithmetic / logical
action that needs to be taken on the variables to arrive at a result of the expression.
Logical Operators: used in logical calculations. Example: =, <>, <, >, OR, AND etc.
Operator Meaning
+ Adds two values. In case of text, it adds the two strings and makes it one.
- Subtracts two values.
* Multiplies two values
/ Divides the first value with the second.
= There are two usages.
1. Determines if the expressions on both sides match. If they do, it’s a Pass.
2. Assigns the Right side value to the variable on the left side.
<>, !=, >< Determines if the expressions on both sides do not match. If they don’t, it’s a Pass.
> Determines if the value on the left side is bigger than that the one on the right. If it is, It’s a pass.
< Determines if the value on the left side is smaller than that the one on the right. If it is, It’s a pass.
>= It is a pass, if the value / variable on the left side is bigger than or equal to the one on its right.
<= It is a pass, if the value / variable on the left side is smaller than or equal to the one on its right.
Like It is a pass, if the value on the left side is matching with the right. The “Like” Operator is similar to that
of ‘=’, with only two differences.
Like takes the wild card character ‘%’ (any number of characters) and ‘_’ (One character).
NOTE: Oracle fast Formulae are case Sensitive to the Text Values. ‘Joe’ and ‘JOE’ are not same.
Not Like It works similar to the ‘Like’ Operator; however it works like the inversion of the later.
There are few things that we must keep in mind while using Arithmetic operators:
So is the case with subtraction, if the resultant is a negative number. It errors if the resultant is a big negative number.
Flow of an Expression
In an Expression, the compiler executes the statements from left to right taking the brackets as precedence.
X = [ ( ( A + B ) / C ) * ( ( P – Q ) * R ) ]
In this Expression, there are four different arithmetic calculations to be done. The way Oracle Fast Formula decides the flow is:
So, if we implement the rules, we will see, the Fast formula will execute the statement in this flow:
1. A+B
2. ( Result of 1 ) / C
3. P–Q
4. ( Result of 3 ) * R
5. (Result of 2) * (Result of 4)
6. Result of 5 is assigned to X
Usually the Expression uses operands of same data type to arrive at a resultant. However, there are a few exceptions like:
Statements
A statement is a sentence that completes a task in a Program. There can be four types of statements.
Input Statement
Assignment statement
Conditional Statement
Return Statement
=============================================================
4. Else
5. WAGE = 1 * HOURLY_RATE
6. RETURN WAGE
=============================================================
Now, let’s analyze the Formula.
Input Statement
The input statements are used, to pass the Input values from element into our formula. Each and every element has some
input values attached to it, which hold the values. In a formula, if we are using Input Values, we need to write a statement that
tells the formula about the different Input values in use.
Here, the HOURS_WORKED and the HOURLY_RATE are the two Input values from the Elements.
The FF Compiler takes Number as the default data type. If the INPUT_VALUE is mentioned without any data type, the compiler
takes them as a Number. For Text ad Date data types, we must add the variable name along with the Input value. In our
example, both the Input Values are of Numeric type.
Assignment Statement
The assignment statement represents assignment of a variable. With this statement, a variable gets updated with a new value.
Variable = expression
Like:
The Resultant of the expression on the left hand side is calculated and placed on the variable on the left hand side, which must
be a Local Variable, as we know no other types of variable can be updated with in a formula.
Conditional Statement
A Conditional statement has a condition and a resultant attached to it. The resultant is executed if the condition matches.
IF condition THEN
statement1
ELSE
statement2
Here, if the condition matches, then the statement1 is executed; and if the condition does not match, then the statement2 is
executed.
Notes
Oracle Fast Formula does not understand “End If”; unlike other programming languages
The Conditions in an IF statement can be Multiple with logical operators like AND / OR. If the entire condition passes, it’s a
pass. For an example, we can have an IF Statement like this:
……..
1. IF [
2. (
4. ) OR
5. (E=F)
6. ] THEN
Here, based on the logical operator settings, we can be sure that the condition passes, if either 3 or 5 is a pass.
If more than one statement is to be executed inside an IF, we can take help of brackets. In case of absence of brackets,
the compiler takes the first statement as part of the conditional statements and executes the rest unconditionally.
IF A = B THEN
(
X = R
Y= S
)
Here, the brackets ensure both statements get executed when the condition is a pass.
IF A = B THEN
X = R
Y = S
In this case only the statement ‘X = R’ is executed only if the condition matches, and statement ‘Y = S’ is executed
irrespective of the condition given above. So what did we conclude? The application takes just one statement after the IF
statement as part of the condition, if there are no brackets in it. It makes sense, right?
back to top
Return Statement
Each and every formula type expects a set of resultants from the formula to be fed to the application. So if we have attached a
formula at a place in the application, the application expects the resultants in order to decide on the next action. Those
resultants are known as the Return Values.
Every formula must have one, and may have more than one return Values. Those return values are given back to the
application with the use of Return Statements. Oracle Fast Formula stops executing the formula, when it finds the Return
Statement.
In Our Example, the wage was calculated with the arithmetic formulas, and at the end, the calculated wage is returned back to
the application by the return statement which looks like this: “RETURN WAGE”. Did we see the variable Wage is not initialized?
That is because the formula knows its return type, and hence automatically defines the local variable in that data type.
Using Input values
Input values are place holders to store values for a particular element entry. For an example, if we have an element called
“Weekly Wage” and it has an input value as “HOURS_WORKED” then, then we can use the input value to store the number of
hours worked by the employee in employee’s element entries.
Later, we can use the Input value in my formula to calculate the wage multiplying the HOURLY_RATE with the
HOURS_WORKED. Simple, isn’t it? Input values come handy in FFs, because we can directly use the input value name in the
fast formula, and based on the ASSIGNMENT_ID and the Payroll run being evaluated, the Hours Worked will be pulled from the
element entries and can be used directly there, without any extra line of code. In the Write fast Formula screen, we have a
button for Input values, which lists all the valid Element types and the corresponding Input Values from which we can choose
the one we are going to use.
Input values can be used in the FF, only after we define the Inputs with an Input statement. An Input statement looks like this:
Here, the HOURS_WORKED and HOURLY_RATE are the two input values that can be used in the fast formula. Let’s look at few
points related to Input Values and their usages.
As both these input values in the example, are numbers we did not have to add the data type in the statement, however
for any other data type, we must have the data type added in brackets just after the Input value name.
We must make sure the Input values are not null for any assignment. In such cases our calculation might go wrong. To
avoid such issues, we can use the Default keyword. The statement might look like:
Was Defaulted
We just discussed about the default statement. So when will the default value of 35 be applied over the HOURLY_RATE? It will
be defaulted, only when the Input value for the assignment being evaluated for the Payroll run is Null.
We can always check, if the Input value was defaulted or not, by using the “was defaulted” key word in a conditional statement.
………
For an example, in a fast formula, we need the assignment_id of the employee being evaluated. In this case, we might default
the assignment_id as ‘0’. So whenever the syatem will not find a valid (Not Null) assignment_id it will assign it a value ‘0’.
However before using the assignment_id, we might want to check if the data was fetched properly. In this case, we would use
Was Defaulted to check if the value was retrieved or was just defaulted. Based on that fact, we can write the next set of
statements.
Global Variables
As we know, we store the Global information in Global variables. We store the information that does not change frequently.
Let’s see how to configure the Global Values. See Figure 5.2 – Global Values.
back to top
Database Items are the hidden queries used by the application to provide fast information in the Fast Formula. The query
actually uses a set of values as Contexts, which is passed by the Fast Formula to the DBI. Using the context the query pulls the
data from the application tables, using the defined query.
Question, what are the data that are available in DBIs? There are many, mainly the assignment details, Contact details, Input
Values, Balances etc.
For the Input Values we must check the create Database Item flag in Input Value definition screen in elements, in order to
create a DBI for the same.
For DFFs and KFFs, we must run the “Create Descriptive Flex field DB Items” process and “Create Key Flex field DB Items
process” respectively, to have the DBIs created.
For all others the DBI gets created without any added tasks.
There is a button called “Show Items” in the Write Formula Screen. This button opens up a form that lists all the Database
Items that are available to the formula type. Now, how does the system identify if a DBI should be available to the formula type
or not? It is the context.
BUSINESS_GROUP_ID
ASSIGNMENT_ID or PERSON_ID
ELEMENT_TYPE_ID AND ELEMENT_LINK_ID
PAYROLL_ID, RUN_RESULT_ID
Based on the type of formula, the contexts are used. And Most of the DBIs need contexts to provide required results. Because
the query in the DBI, needs some inputs and the inputs are given by the Contexts. So if the context is missing, the DBIs will
not be able to pull the data. For an example, we will not need payroll related contexts, if we are writing a formula for Benefits.
So a Benefits Formula will not have Payroll contexts and eventually will not have the payroll related DBIs. So it is always
advised to check the “Show Items” button while writing the formula, to be sure if the DBI is available in there.
back to top
The static database Items are seeded along with the application. They get created during the time of Implementation. Examples
of Static DBIs are:
The Dynamic Database Items, as the name suggests are created dynamically while we create an Element / absence type / DFF
etc. The Different types are:
Flex Field DBIs
o Created only after the Create Descriptive/ Key Flex field DB Items process is run
o It adds the Segment name to the end of the DBI name for uniqueness.
Element DBIs
o It adds the Element Name and Input Value name as a prefix for uniqueness.
o It adds Grade name and the pay scale name to the DBI’s name for uniqueness
Absence DBIs
To fetch the exact query that is used in a DBI, we can use the following query:
SELECT user_name
, definition_text
, item.data_type
, null_allowed_flag
, text
,'B' || sequence_no context_sequence
, context_name
FROM apps.ff_database_items item,
apps.ff_user_entities ent,
apps.ff_routes route,
ff_contexts fc,
ff_route_context_usages frcu
WHERE item.user_entity_id = ent.user_entity_id
AND route.route_id = ent.route_id
AND user_name = '&DBI_NAME'
AND route.route_id = frcu.route_id
AND fc.context_id = frcu.context_id
ORDER BY 6
NULL_ALLOWED_FLAG Tells if the DBI can return Null; If this is Y, we should use Defaults.
pay_element_entries_f pee,
pay_accrual_plans pap,
pay_element_links_f pel
where pap.accrual_plan_element_type_id = pel.element_type_id
and pel.element_link_id = pee.element_link_id
and pee.element_entry_id = &B1
and pee.effective_end_date
And the Contexts will be:
B1: ELEMENT_ENTRY_ID
B2: DATE_EARNED
SELECT DISTINCT pap.accrual_plan_id
pay_element_entries_f pee,
pay_accrual_plans pap,
pay_element_links_f pel
WHERE pap.accrual_plan_element_type_id = pel.element_type_id
AND pel.element_link_id = pee.element_link_id
AND pee.element_entry_id = &b1
AND &b2 BETWEEN pee.effective_start_date AND pee.effective_end_date
back to top
Using Aliases
The database item names are big and hence are difficult to remember. It is very difficult to remember each and every data
base item, and write the names accordingly, while writing a big fast formula. Here the concept of Alias is very useful. The name
itself is self explanatory.
In this above statement the DBI is aliased as BARG_UNIT. Hence forth in the Formula we can easily refer BARG_UNIT and the
compiler will understand that the BARG_UNIT means the value returned by the Database Item.
Comments are always preferred in coding, and Oracle Fast Formula is no exception. We can add as many comments and white
lines in a formula as you want to increase the readability.
A Comment starts with /* and ends with */. Compiler ignores everything in between these two symbols. Comments never
impact the performance of a Formula; hence as a standard practice, we should always add the Formula Name, Type, Input
Values, Return Types, DBIs if any, flow of the code and also the versions with comments in order to make it more standard and
readable. We should also add comments in between the codes to explain the purpose of the statements, in case the statement
is complex. We should not put Comments in between Comments as the compiler does not understand the nesting and throws
an error.