Monday, February 15, 2016

Fast Formula – First Formula

In our previous blog, we went over the basics of the Fast Formula engine and its components. We also explained the Fast Formula types, Context, Input Values and Return Variables/Values. 

In this blog, we want to take a simple example so that the fast formula can be understood clearly. If you have already created a formula, this section is not for you. This is for those people who have not yet created any fast formula. Advance users; please feel free to skip. ☺
The Fast Formula is created in Payroll Administration Area (You may navigate from other products too). This is a two part entry. In the first screen, you enter the basic details (Header) like Name, Type, Description, Legislative Data Group (LDG) and Effective Date of Fast Formula. And in the second part, you can code the Formula.

Name:  Name is a unique and a required column.
We can create a fast formula with or without the Legislative Data Group (LDG). We will discuss the importance of LDG later in a different section.
If you provide a LDG, then the uniqueness is validated within the LDG while saving the formula.
If you have not provided a LDG, it will be considered as a global Fast Formula and the name has to be unique within the LDG and global Fast Formulas.
Type: Type is a required column. Once the name is entered, you can select the Formula Type. In our example, we use the Benefit Eligibility type, “Participation and Rate Eligibility.
For example, in one case, the user has created a Fast Formula in Compensation Work Bench’s Formula type, ‘Compensation Default and Override Rule’ and wanted to attach the formula in Total Compensation Items and found that the formula is not available. The user should know the type and where it is used. 
Description:  It is an optional column.
Legislative Data Group: You do not need to select a LDG. It is an optional column but some formula types need the LDG. This mandatory attribute is defined in Formula Type of the Fast Formula.  If the formula type defines the LDG attribute as required, then you will not be able to save the Formula without selecting LDG. For example, Formula Type, “Absence” does not allow to save without LDG.  In our example, we are creating Global Formula and therefore we are not selecting the LDG for Fast Formula. 
Effective Start date: This decides the availability of the Fast Formula for the products to select in their setups.  One suggestion is to specify a date as early as possible. 
For example, in one case,  a formula in Total Compensation Item was created on current date (1-1-2016) and attached to the setup and the setup was processed for the period of 2015 (Jan  1 to Dec 31, 2015). The processed resulted in an error as the Formula is not compiled. The process was looking for a compiled formula and it was not available but the user is trying to compile the Formula again and again, still it is not working. Therefore, you need to understand the importance of Effective Start Date.
In the second part of the Fast Formula, you can code the logic for the fast formula.
ELIGIBLE = ‘Y’
Return ELIGIBLE
In our example, we have provided a simple Fast Formula to explain the steps.  
Save & Submit
Once the code is written for the fast formula, you can save the formula and submit the formula. The difference between saving and submitting is that the saved formula can be edited immediately but submitted formula cannot be edited immediately. 
Compile
Once you submit the formula, you will need to compile the formula. Once you press the compile button, you will see a popup to confirm the compilation (Sometimes the popup does not appear, you may need to click the compile button again) Compilation will initiate an ESS process internally. Once the compilation has started the “Compile Status” icon will change from “X” to a Clock icon.  To see the status of the compilation, you need to press the refresh button. Once the compilation is complete, the “Compile Status” icon will show the result.

In case of an error, the error message will be displayed below the Formula editor window. In some releases, you can see the log from the ESS monitor page. (You can use any monitor page. For example, Compensation Work Bench monitor page, Compensation -> Run Batch Process -> Monitor Process)
Search and Edit the Fast Formula: 
To Edit or Delete the Formula you need to search the formula first. If the Formula is created for a LDG, then you must provide the LDG when searching the formula though it is not a required column. If the Formula is Global (i.e. no LDG was specified while creating the formula), you must not provide the LDG information.
The edit feature provides four options (Correct, Update, Delete and End date) to edit (Since we are not discussing the date tracking, I do not want to get into details about these four options). You can use the “Correct” to edit the Fast formula. Once you change a Formula, the Compiled Status automatically changes to invalid. You need to Save/Commit and compile the formula again.
  

In our previous blog, we mentioned that the Benefit Eligibility formula expects the return variable “ELIGIBLE”. You can change the variable to something else. For example 
RETURNVAL = ‘Y’
RETURN RETURNVAL
Still the formula compiles fine because the Formula engine does not impose this rule and the rule is validated by the Benefit, Eligibility. But the benefit eligibility will not work as expected.
This concludes the description of how to create, edit and compile a Fast Formula.
Hope this gives you some basic information about the Fast Formula entry steps. 
If you have any comments or suggestions, please feel free to provide your comments below.



/*************************************************
Name: TCS_PERSON_SELECTION
type: Compensation Person Selection
Date: today 
Dev:  Tilak
Requirement: Select the Person who are 
             Female, age is 50 or more 
             and having 1 or more year experience in the org

*************************************************/
/* Declare DBI */
DEFAULT FOR PER_PER_SEX is 'X'
DEFAULT FOR PER_PER_PERSON_AGE is -1
DEFAULT FOR PER_PERSON_ENTERPRISE_HIRE_DATE is '1900/01/01' (date)
/* Input Value */ 
INPUTS ARE CMP_IV_PERIOD_START_DATE (date), CMP_IV_PERIOD_END_DATE (date), CMP_IV_STMT_ID, CMP_IV_PERIOD_ID

l_temp = ESS_LOG_WRITE('Entering  TCS_PERSON_SELECTION ' )
RETAVL = 'N'

l_person = get_Context(PERSON_ID, -1)
l_date   = get_context(EFFECTIVE_DATE,  '1900/01/01' (date) )


l_temp = ESS_LOG_WRITE('l_person ' || to_char(l_person) )
l_temp = ESS_LOG_WRITE('l_date ' || to_char(l_date) )

l_gender = PER_PER_SEX
l_age    = PER_PER_PERSON_AGE
l_hire_date =  PER_PERSON_ENTERPRISE_HIRE_DATE
l_exp_months = MONTHS_BETWEEN(l_date , l_hire_date)

l_temp = ESS_LOG_WRITE('l_gender ' || l_gender )
l_temp = ESS_LOG_WRITE('l_age ' || to_char(l_age) )
l_temp = ESS_LOG_WRITE('l_hire_date ' || to_char(l_hire_date) )
l_temp = ESS_LOG_WRITE('l_exp_months ' || to_char(l_exp_months) )

/* Condition */
if l_gender = 'F' then (
   if l_age >= 30 then (
      if l_exp_months >= 12  then(
         RETAVL = 'Y'
      )
   )
)
l_temp = ESS_LOG_WRITE('Returning  TCS_PERSON_SELECTION ' || RETAVL)
Return RETAVL




/*************************************************

Name: TCS_PERSON_SELECTION

type: Compensation Person Selection

Date: today 

Dev:  Tilak

Requirement: Select the Person who are 

             Female, age is 50 or more 

             and having 1 or more year experience in the org


*************************************************/

/* Declare DBI */

DEFAULT FOR PER_PER_SEX is 'X'

DEFAULT FOR PER_PER_PERSON_AGE is -1

DEFAULT FOR PER_PERSON_ENTERPRISE_HIRE_DATE is '1900/01/01' (date)

/* Input Value */ 


DEFAULT FOR CMP_IV_PERIOD_START_DATE is '1900/01/01' (date)

INPUTS ARE CMP_IV_PERIOD_START_DATE (date), CMP_IV_PERIOD_END_DATE (date), CMP_IV_STMT_ID, CMP_IV_PERIOD_ID


l_temp = ESS_LOG_WRITE('Entering  TCS_PERSON_SELECTION ' )

RETAVL = 'N'


l_person = get_Context(PERSON_ID, -1)

l_date   = get_context(EFFECTIVE_DATE,  '1900/01/01' (date) )

l_start_date = CMP_IV_PERIOD_START_DATE 






l_temp = ESS_LOG_WRITE('l_person ' || to_char(l_person) )

l_temp = ESS_LOG_WRITE('l_date ' || to_char(l_date) )

l_temp = ESS_LOG_WRITE('l_start_date ' || to_char(l_start_date) )




l_gender = PER_PER_SEX

l_age    = PER_PER_PERSON_AGE

l_hire_date =  PER_PERSON_ENTERPRISE_HIRE_DATE

l_exp_months = MONTHS_BETWEEN(l_date , l_hire_date)


l_temp = ESS_LOG_WRITE('l_gender ' || l_gender )

l_temp = ESS_LOG_WRITE('l_age ' || to_char(l_age) )

l_temp = ESS_LOG_WRITE('l_hire_date ' || to_char(l_hire_date) )

l_temp = ESS_LOG_WRITE('l_exp_months ' || to_char(l_exp_months) )


IF CONTEXT_IS_SET(EFFECTIVE_DATE) THEN (

    l_temp = ESS_LOG_WRITE(' Eff Date context Set ')

    IF CMP_IV_PERIOD_START_DATE WAS NOT DEFAULTED Then (

       l_temp = ESS_LOG_WRITE(' CMP_IV_PERIOD_START_DATE not defaulted  ')

       if l_start_date != l_date Then (

          change_contexts(EFFECTIVE_DATE = l_start_date)(

              l_age = PER_PER_PERSON_AGE    

              l_temp = ESS_LOG_WRITE('l_age CC' || to_char(l_age) )

          )


        )else (

          l_temp = ESS_LOG_WRITE(' start date not same as effective date  ')

        )


    )



)



/* Condition */

if l_gender = 'F' AND l_age >= 30 AND l_exp_months >= 12  then(

         RETAVL = 'Y'

)

l_temp = ESS_LOG_WRITE('Returning  TCS_PERSON_SELECTION ' || RETAVL)

Return RETAVL







YouTube Tutorial: TOTAL Compensation Item Fast Formula 1:



/*

Name: TCS_ITEM_FF

Type: Total Compensation Item

Logic: Return annual Salary as of EO Period


*/


DEFAULT FOR  CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT IS 0 

DEFAULT FOR  PER_ASG_LEGAL_ENTITY_ID IS 0 

DEFAULT FOR  CMP_ASSIGNMENT_SALARY_CURRENCY_CODE IS 'XXX'


INPUTS ARE CMP_IV_PERIOD_START_DATE (DATE) ,CMP_IV_PERIOD_END_DATE (DATE)


l_data = SET_LOG('Entering TCS_ITEM_FF' )


L_START_DATE      = CMP_IV_PERIOD_START_DATE

L_END_DATE        = CMP_IV_PERIOD_END_DATE

l_hr_assign_id = get_context(HR_ASSIGNMENT_ID, -1)



L_DATA = SET_LOG( 'Start Date   :' + TO_CHAR( L_START_DATE,'YYYY/MM/DD')) 

L_DATA = SET_LOG( 'END Date   :' + TO_CHAR( L_END_DATE,'YYYY/MM/DD')) 

L_DATA = SET_LOG( 'Asg ID     :' + TO_CHAR(l_hr_assign_id)) 


COMPENSATION_DATES   =  TO_CHAR( L_END_DATE,'YYYY/MM/DD')

VALUES               =  ' ' 

UNIT                 =  CMP_ASSIGNMENT_SALARY_CURRENCY_CODE

LEGALEMPLOYERS       =  TO_CHAR(PER_ASG_LEGAL_ENTITY_ID )

ASSIGNMENTS          =   TO_CHAR(l_hr_assign_id)



CHANGE_CONTEXTS(EFFECTIVE_DATE = L_START_DATE)

  (

   L_DATA = SET_LOG( 'ANN SALARY   :' + TO_CHAR( CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT)) 

   VALUES =  TO_CHAR( CMP_ASSIGNMENT_SALARY_ANNUAL_AMOUNT)

)


l_data = SET_LOG('Leaving TCS_ITEM_FF' )

RETURN  COMPENSATION_DATES ,VALUES, LEGALEMPLOYERS, ASSIGNMENTS, UNIT 










 






14 comments:

  1. Good One!!.Specially the return value part.

    ReplyDelete
  2. unbale to view the image in this page

    ReplyDelete
  3. Wonderful site to learn fast formula. Bookmark the site.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. which example are you talking about. please elaborate? Do not expect me to go through entire blog again :)

      Delete
    2. Yes, I'm actually trying to print a simple value from fast formula using extract.

      I've created a similar fast formula you showed in this blog -

      https://tilak-lakshmi.blogspot.com/2016/02/fast-formula-first-formula_15.html


      fast formula type- extract rule


      fast formula code -

      ELIGIBLE 'Y'
      RETURN ELIGIBLE


      I'm expecting to see the result 'Y' in my extract result.

      But I'm not getting the expected output.




      Delete
    3. why are you using eligibility profile in extract?
      Please understand the extract types, their usages and where it should be used.

      Delete
  6. Hi Tilak I am using the participation and Eligibility formula, but i couldn't able to see the logs. can you suggest me the process name in Monitor process.

    ReplyDelete
    Replies
    1. where are u using your eligibility profile.?
      You must know the process u r running, check parent or child process logs in ESS

      Delete
  7. can u check this blog: https://tilak-lakshmi.blogspot.com/2017/03/how-to-debug-fast-formula.html

    ReplyDelete