Fast Formula – WSA
In this session, we will explain how to talk to another Fast Formula that is executed in the same session.
In many processes, we define more than one Fast Formula and sometimes these Fast Formulas execute the same routine again and again. This can be avoided if we could talk to each other or if we can pass a value between Fast Formulas.
We will explain this concept with a hypothetical use case.
Assume Total Compensation Statement needs to calculate the Annual FTE (Full Time Equivalent) Salary and Bonus for every person. The Bonus is 20% of the Annual FTE Salary.
In the above example, the Annual FTE needs to be calculated in the Salary Fast Formula and the Bonus Fast Formula. Instead of doing the calculation in every Fast Formula, we want to calculate the Annual FTE salary in the Fast Formula that is executed first and pass the value to the Fast Formula that is executed later.
As per the setup, we assume, the Annual FTE Salary Fast Formula is executed first and the Bonus Fast Formula is executed later. To find out which process is executed first, you can run the process for a person and the Fast Formula ESS Logs can help you.
How we achieved this requirement:
- Steps for FTE Salary Fast Formula:
- We get the Annual salary from the Annual Salary DBI.
- Get the FTE value from the FTE DBI.
- If the DBI is not null or 1, then divide the Annual salary with FTE
- If the Salary is defined for Hourly, then multiply the salary with FTE.
- Set the value in Working Storage Area using the function WSA_SET(<item>, <value>).
- Check the salary WSA Item exists by using WSA_EXISTS(<item>).
- If the WSA exists, get the value from WSA by using WSA_GET(<item>, <default-value>).
- Otherwise, calculate the value from the DBI.
- If the WSA exists, delete the WSA by using WSA_DELETE(<item>) so that we make sure the WSA value is not used for the next person.
What is WSA:
As per the Fast Formula documentation,
“The working storage area is a mechanism for storing global values across
formulas. The values are accessed by name. The names are case-independent”.
There are four working storage area methods:
WSA_EXISTS
WSA_DELETE
WSA_SET
WSA_GET
FTE Salary Fast Formula:
/*
Author : Ti(lak)shmi
Type : Total Compensation Item
NAME : TCS_FTE_SAL_TEST_FF
Remarks: This formula is for demonstrating the communication between Fast Formulas.
This formula calculates the Full time FTE salary and assigns it to a WSA Variable.
*/
DEFAULT FOR CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT IS -1
DEFAULT FOR PER_ASG_FTE_VALUE IS 1
INPUTS ARE CMP_IV_PERIOD_START_DATE (DATE) ,CMP_IV_PERIOD_END_DATE (DATE)
L_DATA = ESS_LOG_WRITE( 'BEGIN CS_FTE_SAL_TEST_FF' )
COMPENSATION_DATES = TO_CHAR(CMP_IV_PERIOD_END_DATE, 'YYYY/MM/DD')
VALUES = 0
IF (CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT WAS NOT DEFAULTED ) THEN
(
VALUES = CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT
IF (PER_ASG_FTE_VALUE WAS NOT DEFAULTED) THEN
(
VALUES = VALUES * PER_ASG_FTE_VALUE
)
L_DATA = ESS_LOG_WRITE( 'Salary Amount is ' + TO_CHAR(VALUES) )
WSA_SET('TCS_WSA_TEST_FTE_SALARY', VALUES)
) ELSE (
L_DATA = ESS_LOG_WRITE( 'Salary Amount is 0 to test WSA ' )
WSA_SET('TCS_WSA_TEST_FTE_SALARY', VALUES)
)
L_DATA = ESS_LOG_WRITE( 'END CS_FTE_SAL_TEST_FF' )
RETURN COMPENSATION_DATES ,VALUE
Bonus Fast Formula:
/*
Author : Ti(lak)shmi
Type : Total Compensation Item
NAME : TCS_BONUS_TEST_FF
Remarks: This formula is for demonstrating the communication between Fast Formulas.
This formula gets the salary value that is calculated at TCS_FTE_SAL_TEST_FF by using WSA.
*/
INPUTS ARE CMP_IV_PERIOD_START_DATE (DATE) ,CMP_IV_PERIOD_END_DATE (DATE)
L_DATA = ESS_LOG_WRITE( 'BEGIN TCS_BONUS_TEST_FF' )
COMPENSATION_DATES = CMP_IV_PERIOD_END_DATE
VALUES = 0
IF WSA_EXISTS('TCS_WSA_TEST_FTE_SALARY' ) THEN
(
L_DATA = ESS_LOG_WRITE( 'WSA FOUND' )
VALUES = WSA_GET('TCS_WSA_TEST_FTE_SALARY', 0 )
L_DATA = ESS_LOG_WRITE( 'WSA VALUE ' + TO_CHAR(VALUES))
IF (VALUES != 0 ) THEN
(
VALUES = VALUES * .20
L_DATA = ESS_LOG_WRITE( 'Bonus Amount ' + TO_CHAR(VALUES))
)
WSA_DELETE('TCS_WSA_TEST_FTE_SALARY' )
)
L_DATA = ESS_LOG_WRITE( 'END TCS_BONUS_TEST_FF' )
RETURN COMPENSATION_DATES ,VALUE
TCS Setups:
Item:
Category Setup
Statement Setup
Sample Log for the Formula Execution
BEGIN CS_FTE_SAL_TEST_FF
Salary Amount is 54963
END CS_FTE_SAL_TEST_FF
BEGIN TCS_BONUS_TEST_FF
WSA FOUND
WSA VALUE 54963
Bonus Amount 10992.6
END TCS_BONUS_TEST_FF
As per the log, Salary Fast Formula calculated the Salary and assigned the Salary value to a WSA Variable and the Bonus Fast Formula was able to get the value from the WSA Variable.
Hope this has helped you with an understanding of WSA and how communicating between Fast Formulas is possible. As always, if you have any questions or suggestions, please feel free to comment.
/*
Author : Tilak
Type : Compensation Person Selection
NAME : CMP_PERSON_SELECTION
Remarks: Eligible if the person annual salary is < 200000
and set the salary to WSA with person id
*/
DEFAULT FOR CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT IS -1
DEFAULT FOR PER_ASG_FTE_VALUE IS 1
INPUTS ARE CMP_IV_PERIOD_START_DATE (DATE) ,CMP_IV_PERIOD_END_DATE (DATE)
L_DATA = ESS_LOG_WRITE( 'Entering CMP_PERSON_SELECTION' )
VALUES = 0
retValue = 'Y'
personid = get_context(PERSON_ID, -1)
L_DATA = ESS_LOG_WRITE( 'person id ' + to_char( personid ) )
IF (CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT WAS NOT DEFAULTED ) THEN
(
VALUES = CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT
IF (PER_ASG_FTE_VALUE WAS NOT DEFAULTED) THEN
(
VALUES = VALUES * PER_ASG_FTE_VALUE
)
)
L_DATA = ESS_LOG_WRITE( 'Salary Amount is ' + TO_CHAR(VALUES) )
WSA_SET('TCS_WSA_TEST_FTE_SALARY', VALUES)
WSA_SET('TCS_WSA_TEST_PERSON', personid)
if VALUES > 200000 OR VALUES <= 0 then (
retValue = 'N'
)
L_DATA = ESS_LOG_WRITE( 'Leaving CMP_PERSON_SELECTION ' + retValue )
RETURN retValue
//*
Author : Tilak
Type : Participation and Rate Eligibility
NAME : CMP_ELiGiBLE
Remarks: Eligible if the person annual salary is > 100000
get the salary from WSA and delete the WSA
*/
L_DATA = ESS_LOG_WRITE( 'Entering CMP_ELiGiBLE ' )
VALUES = 0
ELIGIBLE = 'Y'
personid = get_context(PERSON_ID, -1)
L_DATA = ESS_LOG_WRITE( 'person ' + TO_CHAR(personid) )
if WSA_EXISTS('TCS_WSA_TEST_FTE_SALARY') then (
L_DATA = ESS_LOG_WRITE( ' WSA Exists' )
lperson = WSA_GET('TCS_WSA_TEST_PERSON', -1)
L_DATA = ESS_LOG_WRITE( 'WSA person ' + TO_CHAR(lperson) )
if lperson = personid then (
VALUES = WSA_GET('TCS_WSA_TEST_FTE_SALARY', -1)
L_DATA = ESS_LOG_WRITE( 'WSA salary ' + TO_CHAR(VALUES) )
if VALUES > 100000 then (
ELIGIBLE = 'N'
)
WSA_DELETE('TCS_WSA_TEST_FTE_SALARY')
WSA_DELETE('TCS_WSA_TEST_PERSON')
)
)
ELSE (
L_DATA = ESS_LOG_WRITE( 'WSA NOT EXIST CMP_ELiGiBLE ' )
ELIGIBLE = 'N'
)
L_DATA = ESS_LOG_WRITE( 'Leaving CMP_ELiGiBLE ' + ELIGIBLE )
RETURN ELIGIBLE
Hi Tilak,
ReplyDeleteCan we write a fast formula(no LDG) and have that call another FF(specific to US LDG) if legislation is US?
Thanks,
-Manikandan
yes you can. It is explained in my parent child formula blog:Please read my blog on parent child: http://tilak-lakshmi.blogspot.com/2016/03/parent-and-child-formula.html
DeleteHi,
ReplyDeletewhen we create Standard earning elements a formula is created where we find WSA mechanism used, so if don't need to use any such global variable can we remove that part from the formula?
Thanks,
Have you tried global variable of array type using WSA mechanism.... its becomes more complicated to understand.
ReplyDeleteHi,
DeleteI understand the Formula supports array in WAS but I have not seen any document on it. if you let me know what you did and what are you trying to achieve, I can help you further.
Update the blog with a sample that can handle array in WSA
DeleteHi Lakshmi,
ReplyDeleteCould you please explain where this total compensation item formula can be added in application and how to run for one employee and check the status.
Thanks
Shiva G
I fixed the screenshots.
DeleteExplaining the setup of TCS can not be done in this reply. You need to go through the documents.
will there be any issues with respect to performance when we use wsa?
ReplyDeleteplz write some basic payroll formulas
ReplyDeleteHi Lakshmi,
ReplyDeleteIam encountering an issue regarding updating variable in my fast formula .
L_Eligible_Duration=0
IF (ANC_ABS_RSN_NAME = 'Maternity Leave - 3rd Child ') THEN
(
L_Eligible_Duration= 12
)
By defualt L_Eligible_Durationis taking 0 ,it is not getting updated even though condition matches.Could you please help me how to update L_Eligible_Duration when condition matches.
Thanks
print and check what is the value of ANC_ABS_RSN_NAME.
ReplyDeleteI think the if condition is failing
Yeah I have already checked it is getting printed correctly but L_Eligible_Duration is not getting updated
ReplyDeleteI Printed this through Error Message .ANC_ABS_RSN_NAME is getting updated but L_Eligible_Duration is not getting updated
ReplyDeleteANC-L_Total_Duration=13.286L_Eligible_Duration=0 L_Prev_Duration=0 ANC_ABS_RSN_NAME=Maternity Leave - 3rd Child (ANC--1)
the name is not matching , 'Maternity Leave - 3rd Child (ANC--1)' can not be same as 'Maternity Leave - 3rd Child'
DeleteNeed some help with understanding this. Salary and person id are set to WSA as below
ReplyDeleteWSA_SET('TCS_WSA_TEST_FTE_SALARY', VALUES)
WSA_SET('TCS_WSA_TEST_PERSON', personid)
When
lperson = WSA_GET('TCS_WSA_TEST_PERSON', -1)
is encountered in CMP_ELiGiBLE ff how does fusion know which of the two set values to provide?
Hi sorry ... I realized two different variables, thought there was only one :) ... Tilak delete my questions/posts if you need to
DeleteI am not sure i understood your question. why cant you check the current person id with WSA person id, if there are not the same, you can set the WSA values.
ReplyDeleteHi ... my question was wrt the code in the tutorial. I am new to fusion. Two variables are SET to WSA say var1, var2. With code WSA_GET('FF', -1) what should you expect to be returned, var1 or var2?
DeleteHi sorry ... I realized two different variables, thought there was only one :) ... Tilak delete my questions/posts if you need to
Deleteit is ok. in WSA_GET, The first parameter is the variable name, second one is default value. if there is no value in WAS then it returns the second value.
DeleteYes got it, thank you !!!!
Delete