Fast Formulas and Arrays
Fast Formulas and Arrays
Fast Formula uses Arrays, the return values are passed as name and value pair of Arrays.
Arrays can be used in
1. Input Values
2. DBI
3. Variables
4. Return values.
Different types of Arrays.
Arrays are defined with two attributes:
1. Type of Value - indicates the value type (Number, Date or Char) stored in the Array.
2. Type of Index - indicates how the Array is indexed.
The following options are available for defining an Array in Fusion Fast Formula.
Array Type Meaning
DATE_NUMBER Date value and number index Array
DATE_TEXT Date value and text index Array
NUMBER_NUMBE Number value and number index Array
R
NUMBER_TEXT Number value and text index Array
TEXT_NUMBER Text value and number index Array
TEXT_TEXT Text value and text Index Array
Usage of Arrays:
Input Values:
There are many products in Fusion that pass the Input Values as Array.
For example, Total Compensation Statement (TCS) process the data at a person level. Therefore, when the
Fast Formula is executed for a person, it sets the primary Assignment Id as Context, HR_ASSIGNMENT_ID.
In case if the person has more than one assignment, it passes all the assignments as Array to the Fast
Formula so that the formula can use the Assignments to process the data.
The syntax for declaring the Array Input Value is:
INPUTS ARE CMP_IVR_ASSIGNMENT_ID (NUMBER_NUMBER)
You can also default the Array with an empty Array as follows.
DEFAULT for CMP_IVR_PAY_ASSIGNMENT_ID is EMPTY_NUMBER_NUMBER
To find the Array input values, you need to check the documentation of each of the products.
Array DBI/ range DBI
DBI:
The Array DBI is also called range DBI.
Every product in HCM has seeded these Array DBIs.
It looks like the Array DBIs are more popular than the conventional ones in Fusion.
The Array DBIs are declared and defaulted as follows
DEFAULT_DATA_VALUE FOR PER_HIST_ASG_EFFECTIVE_START_DATE IS '1900/01/01 00:00:00' (date)
If the Array DBI is not handled in a proper manner, it may lead to a performance issue.
Since the Array DBI holds a range of data, you will need to implement the proper validation to get the
desired results.
Variables:
The variables are like any other Array, the only difference is how you declare them.
You can declare the variable Array as follows.
DEFAULT FOR COMPENSATION_DATES is EMPTY_TEXT_NUMBER
Return values:
Fast Formula engine allows returning Array variables provided the Formula Type supports it.
The Product that executes the Formula determines whether the Array variables that are returned from Fast
Formula are supported. As far as I know, in Compensation product, TCS supports Arrays for their Formula
Type, “Total Compensation Item” in their latest release. (please check the documentation for the availability).
Fast Formula has provided the following functions to handle the Arrays.
Function Syntax Meaning
Return the count of an Array elements
COUNT <Array> .COUNT
Example: l_count = l_array.count
Delete a element from the Array
<Array>. DELETE( <index
DELETE Example: l_array.delete(2) or l_array.delete(‘TWO’) depending on
value> )
the index type of the Array.
Delete all the elements.
DELETE <Array>. DELETE()
Example: l_array.delete()
<Array>. EXISTS ( <index If a value exists at an index of an Array. It returns a Boolean.
EXISTS
value> ) Example: if l_array.exists(1) then
Returns first index of an Array. If there are no elements, then
<Array>.FIRST( <default value>
FIRST return the default value.
)
Example: l_index = l_array.first(-1)
< Array>.LAST (<default Returns last index of an Array. If there is no elements then returns
LAST value>) the default value.
Example: l_index = l_array.last(-1)
< Array>.NEXT (<index>, Returns the next index of the index parameter. If there is no next
NEXT <default value>) element, returns default value.
Example: : l_index =l_array.next(l_index, -1)
< Array>.PRIOR (<index>, Returns the previous index of the index parameter. If there is no
PRIOR <default value>) previous element, returns default value.
Example: l_index =l_array.prior(l_index, -1)
To get/set a value from/to an Array element.
Array[<index>] Example: L_number = l_array[100]
l_array[100] = L_number
Sample Fast Formula to handle Arrays:
/*
Author : Tilak-Lakshmi
Name : TCS_ITEM_ARRAY_TEST
Type : Total Compensation Item
Purpose : Example of using Array DBI, input values and return variables. This formula returns changed salary
of every assignment.
*/
/*Defaulting DBI */
DEFAULT_DATA_VALUE FOR CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT IS 0
ASSIGNMENTS[l_counter] = TO_CHAR(l_asg)
VALUES[l_counter] = TO_CHAR( CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT[l_sal_indx])
l_counter = l_counter + 1
)
l_sal_indx = CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT.NEXT(l_sal_indx , -1)
)
)
index = CMP_IVR_ASSIGNMENT_ID.NEXT(index ,-1)
)
l_data= ESS_LOG_WRITE( ' LEAVING TCS_ITEM_ARRAY_TEST ' )
RETURN COMPENSATION_DATES, VALUES, ASSIGNMENTS
Explanation of the Formula:
When declaring an Array DBI, please note the syntax. It is a little different than the normal DBI declaration.
DEFAULT_DATA_VALUE FOR CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT IS 0
We use the same syntax to default the Input Values and for declaring/defaulting variables.
DEFAULT FOR CMP_IVR_ASSIGNMENT_ID is EMPTY_NUMBER_NUMBER
DEFAULT FOR COMPENSATION_DATES is EMPTY_TEXT_NUMBER
DEFAULT FOR VALUES is EMPTY_TEXT_NUMBER
DEFAULT FOR ASSIGNMENTS is EMPTY_TEXT_NUMBER
To loop through the Array, whether it is DBI or Input Values; we need to identify the index type.
In our example, all the Arrays are indexed by number.
We can identify the index type from the document or the DBI list from the Fast Formula UI.
Once we know the index type, we need to identify the first index.
Many developers use 1 as starting index but I prefer to get the first index from the Array itself.
In the .FIRST method, we use -1 as default value. In case there is no element in the Array, the method will
return the default value, -1.
index = CMP_IVR_ASSIGNMENT_ID.FIRST(-1)
l_data= ESS_LOG_WRITE( ' first index ' + TO_CHAR(index ) )
l_counter = 1
In the loop, we iterate as long as an element exists.
We use the .EXISTS method to find the existence of the element for an index.
We get the assignment id and set the Context, HR_ASSIGNMENT_ID with the assignment id, so that the DBI for
the Assignment Id can be used.
/*Set the Context to the Assignment Id */
CHANGE_CONTEXTS(HR_ASSIGNMENT_ID= CMP_IVR_ASSIGNMENT_ID[index] )
(
l_asg = CMP_IVR_ASSIGNMENT_ID[index]
l_data= ESS_LOG_WRITE( ' ASG CONTTEXT IS SET ' + TO_CHAR(l_ASG) )
In the following code, we get the salary changes for the assignment and then assign the value in the Array
variables.
l_sal_indx = CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT.FIRST(-1)
WHILE (CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT.EXISTS(l_sal_indx ) )
LOOP (
if ( CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT[l_sal_indx] <> 0 ) THEN
(
COMPENSATION_DATES[l_counter]= TO_CHAR(CMP_IV_PERIOD_START_DATE,'YYYY/MM/DD')
ASSIGNMENTS[l_counter] = TO_CHAR(l_asg)
VALUES[l_counter] = TO_CHAR( CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT[l_sal_indx] )
l_counter = l_counter + 1
)
Get the next index for the DBI and Input values to move to the next element.
l_sal_indx = CMP_ASSIGNMENT_RGE_SALARY_CHANGE_AMOUNT.NEXT(l_sal_indx, -1)
)
index = CMP_IVR_ASSIGNMENT_ID.NEXT(index ,-1)
)
l_data= ESS_LOG_WRITE( ' LEAVING TCS_ITEM_ARRAY_TEST ' )
RETURN COMPENSATION_DATES , VALUES,ASSIGNMENTS