Wednesday, September 7, 2016

Fast Formula – Without DBI

Fast Formula & Value Set

In EBS days, Fast Formula allows us to write SQL through their Formula Functions. This feature allows accessing any table and columns through the Fast Formula. In Fusion, Fast Formula functions are limited to customers who have onsite implementation. 
In Fusion, the only way to access the data is using DBI or Input Values. In a real life scenario, many times, it is hard to find the DBI we want. Sometimes the DBIs are not available, sometimes the Context are not available, even sometime, the DBI are available in an array format that may lead to performance issues. 
For a long time, we were looking for a way where we can access the data without using DBI.  Finally we found the Holy Grail. 
Holy Grail of Fast Formula: 
We know that we cannot access the database and therefore writing our own SQL or a Function is out of the question. So, we are looking for an option where SQL can be defined through a setup and that can be executed from Formula Function.
After some search , we found out exactly what we were looking for. 
Value Set:  Value Set is a setup where customer can define a table, id and value columns with Where, Condition and Order By clause. This setup allows us to define a simple Select statement from a table with condition. 
This option, Value Set can be navigated as follows. 
Select Setup and Maintenance 
From the Setup and Maintenance Overview, search for Manage Payroll Value Sets as shown in the following screen. 

From the search Result, click ‘Go to Task’ to navigate to the page where Value Set can be created as follows.
In the above example, the Value Set is defined as 
select the lookup code and meaning from HR_LOOKUP for lookup type ‘CMP_TCS_COLS_BNFTS’
The Value Set needs to have at a minimum, Table, ID and Value columns for using Fast Formula Function (ID is not a required column in the Value Set UI).
Formula Function: GET_VALUE_SET
This Formula Function, Get_Value_Set is delivered by Oracle Payroll. This function is defined with 4 parameters and returns a character value. 
The parameters are: 
  1. P_VALUESET: This is a required parameter and is used for passing the Value Set name.
  2. P_BINDS: this is an optional parameter. If you have defined your Value Set with bind variable in where clause, you can pass a value to the bind variable with this parameter. The Formula Function uses a predefined format for passing the value.
Predefined Format : The first character defines the delimiter and the second character defines the  assignment character. From third character onwards, you can pass the bind variable name and value to the bind variable. We will go through the format in detail in our examples.
  1. P_FILTER: This is an optional parameter. With this parameter, we can pass additional filter condition. The Filter value is validated against the Value column Name of the Value Set. The function uses like condition to validate the value.
  2. P_ENABLE_CACHE: I don’t think this parameter is used anywhere in Fast Formula, so we can ignore this parameter. 
Now, we will go through a few examples to understand how we can use this Function and Value Set in our Fast Formulas. For our example, we use the same set of data so that we can understand the different options with ease.
Data: We use the following lookup data for the type, CMP_TCS_COLS_BNFTS for our example.
Example 1
Value Set:  The first Value Set is a very simple value set.
The Value Set needs to have at a minimum - Table, ID and Value columns. The Formula Function, Get_Value_Set returns ID column value to the Fast Formula. The following Value Set is defined for returning Lookup Code for the lookup type, CMP_TCS_COLS_BNFTS. 
Fast Formula:  The following Formula is defined for TCS item. The Formula calls the function, Get_Value_Set with our Value Set. And we log the return value in the ESS log.

The Fast Formula attached to the TCS Item as follows.
We are not going into the details of the TCS setup here. Assume the item is added to a Category and the Category is added to a Statement and the Statement is processed in ESS. 
The following is the result of the ESS process and the result of the Get_Value_Set. Since there is no “order by” clause defined in the Value Set, we expect any one value from the Lookup type.
The result shows the first value of the column ‘Code’, DESC from our select statement.  
Example 2  
We changed the first example to bind the lookup type instead of hard coding to ‘CMP_TCS_COLS_BNFTS’.
Value Set:  Bind variable are defined with the following format 
:{PARAMETER.<BIND_NAME>}
Fast formula:   As we explained earlier, the bind variable is passed to the function in a specific format.
In our example, the bind value is passed as ‘|=TYPE_CODE=’CMP_TCS_COLS_BNFTS’ ‘
  1. The first character, | defines the delimiter. 
  2. The second character, = defines the assignment character. 
  3. TYPE_CODE is the bind variable name from the Set Value and = is the assignment character. 
  4. Finally we pass the value of the bind variables, ‘CMP_TCS_COLS_BNFTS’. 
In theory, you can use any delimiter and assignment character but with our experience, we would recommend using the same delimiter (|) and assignment character (=).
We expect the same result as in the previous example.
 

Example 3
In this example, we try to bind more variables to explain how more than one value is passed.
Value Set:  With two bind variables, one is equi joint and other one is a like condition. Please note that the like condition is already defined within quotes.
Fast Formula:  The value of both bindings is passed in a different way.  The first binding is not defined with quotes and so we need to pass the value with a quote. The second binding is defined within quotes and so the value is passed without any quote. 
As per our value set, we are expecting one of the contribution values, EEC_CNTRB or ERC_CNTRB.


Example 4 :  In this example, we use the Value Set from Example 3. We pass the Value to the third variable, P_FILTER.
This parameter value is validated against the Value Column Name of the Value Set in ‘like’ condition.
In our example, ‘Meaning’ of the lookup is the value column Name.  We pass the value ‘Company’ to filter the row.

As per our Value Set and bind values, we expect company contribution Lookup Code, ERC_CNTRB.


Hope the above examples helped you understand how a Formula and Value Set can be used to execute any SQL in Fast Formula.

YouTube Video 19 Formula:

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

Name: CMP_PERSON_SELECTION

Type: Compensation Person Selection

Programer: Tilak

purpose: Do not process the people who where already process by 

         checking the period processed flag and row in person statement


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

INPUTS ARE CMP_IV_STMT_ID, CMP_IV_PERIOD_ID 


ltem = ess_log_write('Entering  CMP_PERSON_SELECTION' ) 

l_value = 'Y' 

stmtprocessed = GET_VALUE_SET('TCS_STMT_PROCESSED')

ltem = ess_log_write('TCS_STMT_PROCESSED ' +  stmtprocessed) 

IF stmtprocessed = 'Y' then (

  l_value = 'N' 

)


ltem = ess_log_write('Leaving  CMP_PERSON_SELECTION '  + l_value ) 

RETURN l_value









YouTube Video 20 Formula:



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

Name: CMP_PERSON_SELECTION

Type: Compensation Person Selection

Programer: Tilak

purpose: Do not process the people who where already process by 

         checking the period processed flag and row in person statement


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

Name: CMP_PERSON_SELECTION

Type: Compensation Person Selection

Programer: Tilak

purpose: Do not process the people who where already process by 

         checking the period processed flag and row in person statement


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

INPUTS ARE CMP_IV_STMT_ID, CMP_IV_PERIOD_ID 

ltemp = ess_log_write(' Entering CMP_PERSON_SELECTION') 

l_value = 'Y'

/* Calling valueSet */


/* 

stmtprocessed = GET_VALUE_SET('TCS_PERSON_SELECTION')

*/ 

stmtperd = TO_CHAR(CMP_IV_PERIOD_ID) 

ltemp = ess_log_write(' CMP_IV_STMT_PERD_ID: ' + stmtperd ) 


param = '|=STMTPERDID='|| stmtperd

ltemp = ess_log_write(' param ' + param) 

stmtprocessed = GET_VALUE_SET('TCS_STMT_PROCESSED', param)

ltemp = ess_log_write(' TCS_PERSON_SELECTION: ' + stmtprocessed) 


/* Validating result of value set */


If stmtprocessed = 'Y' Then (

   l_value = 'N'  

)

ltemp = ess_log_write(' Leaving CMP_PERSON_SELECTION: ' + l_value ) 

RETURN l_value



Youtube Video 21 Formula



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

Name: CMP_PERSON_SELECTION

Type: Compensation Person Selection

Programer: Tilak

purpose: Do not process the people who where already process by 

         checking the period processed flag and row in person statement


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

INPUTS ARE CMP_IV_STMT_ID, CMP_IV_PERIOD_ID 


ltem = ess_log_write('Entering  CMP_PERSON_SELECTION' ) 

l_value = 'Y'

 

personid = get_context(PERSON_ID, -1)

perid = TO_CHAR(CMP_IV_PERIOD_ID)

ltem = ess_log_write('stmt id  ' +  to_char(CMP_IV_STMT_ID) ) 

ltem = ess_log_write('CMP_IV_PERIOD_ID ' +  perid) 

ltem = ess_log_write('person id  ' +  to_char(personid) ) 


param = '|=STMTPERDID='||perid 

ltem = ess_log_write('param ' +  param) 


/* calling value set */

stmtprocessed = GET_VALUE_SET('TCS_PERSON_SELECTION',param )


ltem = ess_log_write('TCS_PERSON_SELECTION ' +  stmtprocessed) 

IF stmtprocessed = 'Y' then (

   param = '|=STMTPERDID='||perid ||' |STMTID='|| TO_CHAR(CMP_IV_STMT_ID)||' |PERSON_ID='|| to_char(personid)

   ltem = ess_log_write('param ' +  param) 

   perperdid =  GET_VALUE_SET('TCS_STMT_PROCESSED',param )

   ltem = ess_log_write('perperdid ' +  perperdid ) 

   if perperdid != ' ' then (

      l_value = 'N'

   )  

)


ltem = ess_log_write('Leaving  CMP_PERSON_SELECTION '  + l_value ) 

RETURN l_value



19 comments:

  1. Hello,

    With reference to this post I created an Table Value Set as GET_LEMP_CODE having

    From clause - HR_ALL_ORGANIZATION_UNITS_F
    Value Column Name - ORGANIZATION_CODE
    Where - LEGAL_ENTITY_ID = :{PARAMETER.LEGAL_ENTITY_ID}

    In the FF I'm unable to get any value. please suggest what Im missing

    Tried using the below

    l_param = '|=LEGAL_ENTITY_ID=PER_ASG_LEGAL_ENTITY_ID'
    l_le_code = GET_VALUE_SET('GET_LEMP_CODE', l_param)

    ====================================

    l_param = '|=LEGAL_ENTITY_ID=300000034840956'
    l_le_code = GET_VALUE_SET('GET_LEMP_CODE', l_param)

    How to pass the LE ID from DBI. Even for hard coded value I'm unable to get any value.

    Thanks,
    Sankara K

    ReplyDelete
    Replies
    1. Hello Sankara,
      The Get_Value_Set always return the ID Column value which seems missing while defining value set in application.

      Delete
  2. what is the ID column. please read my blog entirely :)

    ReplyDelete
  3. Hi Tilak and Lakshmi,

    I struck with an issue. I am unable to pass the inputs and get the value.Please find my below code and log messages for the same. Please guide me, if anything wrong with code...

    ln_person_id = GET_CONTEXT (PERSON_ID, 0 )
    ld_effective_date = GET_CONTEXT(EFFECTIVE_DATE,'4712/12/31 00:00:00' (DATE))

    ln_cuurent_year=to_number(to_char(Get_context(EFFECTIVE_DATE, '1999/01/01 12:00:00' (date)),'YYYY')) - 1
    ld_effective_date= to_date(to_char(ln_cuurent_year)+'/12/31')

    L_LOG_DATA = ESS_LOG_WRITE('ln_person_id : '||to_char(ln_person_id))
    L_LOG_DATA = ESS_LOG_WRITE('ld_effective_date : '||to_char(ld_effective_date))

    l_param = '|=PERSON_ID=ln_person_id|EFF_DATE=ld_effective_date'

    L_LOG_DATA = ESS_LOG_WRITE('Parameter Passed : '||l_param )

    ln_sick_pln_id = GET_VALUE_SET('GET_SICK_PLAN_ID',l_param )

    L_LOG_DATA = ESS_LOG_WRITE('value return : '||ln_sick_pln_id)

    LOG MESSAGES:-
    ln_assignment_id : 300000009180682
    ln_person_id : 300000009180666
    ld_effective_date : 2018-12-31T00:00:00.000Z
    Parameter Passed : |=PERSON_ID=ln_person_id|EFF_DATE=ld_effective_date
    value return :

    The parameters are not passing any values... It's not working as a variables.

    ReplyDelete
  4. Very good blog.
    Lakshmi hats off to your knowledge.

    ReplyDelete
  5. Pleas can you help me ??
    I need to use a lookup in the fast formula . How??

    ReplyDelete
  6. I need to get count on a column in Fast formula and i don't have any DBIs to get the count through while loop. How can we acheive this? Any idea?

    ReplyDelete
    Replies
    1. I have not used any function yet, but I do not see any issue, why cant you use count(column_name) in ID and test your FF.
      Please let us know the result.

      Delete
  7. Hi,Can we do a MIN in value column within a value set?

    Thanks in advance!

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  8. the images attached are not visible .

    ReplyDelete
    Replies
    1. sorry about that and thanks for letting me know. let me see how to fix it.

      Delete
    2. thanks ...please fix it ASAP...

      Delete
    3. taken care. Let me know if you have any issues.

      Delete
  9. I Have requirement to fetch lookup value based on start date and end date of the lookup.I tried adding parameter for them in where clause but it is not working

    ReplyDelete
  10. Hi
    I have a requirement to pull the Requisition Approved Date by using hcm extract.But Requisition Approved date is not in DBI(Database Item group).so,i have called value set and fast formulae to pull the value set value.but i am unable to get the value for Req Approved date.the given below is fast formulae will i have write
    Fast Formulae :
    DEFAULT FOR DATA_ELEMENTS IS EMPTY_TEXT_TEXT
    INPUTS ARE DATA_ELEMENT_CODE (TEXT), DATA_ELEMENTS (TEXT_TEXT) , l (TEXT_TEXT)
    RULE_VALUE = ' '

    l_num = add_rlog(100, 45,'entry the approved date')
    if (DATA_ELEMENTS.EXISTS('Extracts_Requisition_Id')) then
    (
    l_REQUISITION_ID = DATA_ELEMENTS['Extracts_Requisition_Id']
    RULE_VALUE = GET_VALUE_SET_VALUE('SM_GET_APPROVED_DATE','|=P_REQUISITION_ID='''||l_REQUISITION_ID||'''')
    )

    l_num = add_rlog(101, 45 ,'failed approved date ')

    RETURN RULE_VALUE
    please help on to this..

    ReplyDelete
    Replies
    1. send a msg in ur mail, pls reply

      Delete
    2. Sorry there was mistaken in my mail id venkatrambabu2016@gmail.com

      Delete