Skip to Content
Technical Articles
Author's profile photo Volker Ruof

EC Time and Attendance – Tipps and hints Nr. 11: How to simplify your business rules using variables

Hello,

it has been a while… but here we go again with some cool thing I want to share with you.

You know the business rules concept in EC. Business rules are a very important and powerful tool set and is heavily used especially in Time Off. You can use them to:

  • to calculate regular leave accruals
  • do proration of accruals when an employee is hired/terminated during the year or needs to be recalculated based on unpaid leaves
  • do input validation checks when an absence is recorded based on the duration of the absence, working days, calendar days
  • do cross validations with the duration of other absences in the year
  • and many more

As mentioned, business rules are powerful – but this comes a bit at the cost of complexity. Depending on your requirements business rules can be very complex and not easy to build. When you have lots of if-else clauses where you need calculated values you are for example in the need of repeating this calculation in each if-else clause. And this makes the rule not only slow – cause each time something needs to be calculated – but also complicated to create and complicated to understand for people who where not involved from the beginning in creating the rule. And it happens quite often that you must adapt or analyze a rule that someone else has created.

So, what would you say if we provide something that makes your life easier it this respect?

What would you say when our rules framework team would have developed something that allows to calculate a value, store it and have it available in each if/else clause without the need of calculating it anew?

I would say: big thank you to the rules framework team for this excellent feature.

Lets look how it works:

In the business rule configuration you can calculate a value right at the top of the rule using the normal business rule functions and -this is now the new thing –ย  you can store this value in a variable. This variable can then be used in each if/else clause.

Benefit is twofold:

a) it increases the performance of your business rule to a large extend cause you donยดt have to calculate in each if-clause the value you need, you are just referring to the once calcualted and now stored value in your variable and this fastens the processing of your rule

b) the complexity of the rules in general can be simplified. This eases the creation and the understanding of the rule for others

So, how does this look like in real practice? Lets take an example where a interim time account update rule needs to check the actual balance of a time account.

When the balance is less than 5 days nothing is done. The balance stays as it is.

When the balance is between 5 and 10 then the balance shall be reduced by 50% of the delta from 5 – 10. So when there is a balance of 9 the delta to 5 is 4. And this is reduced by 50% so that in the end the balance is reduced to 7.

And when the balance is bigger than 10ย  all days shall be lost.

The purpose of the rule is to have employees encouraged to take their leaves at a given point in time, otherwise they might loose days. The higher the remaining balance, the more they loose.

You can see in this rule that first a variable is calculated “var_balance” using the “calculate balance” rule function. This function calculates the actual balance of the employee and with the new feature stores this value in the variable var_balance.

And this is only an example of an easy value calculation. There are often much more complex calculations. And instead of doing this calculations in each If / elseif section you just query this variable before your “then” part.

 

This is it. Quite simple, but very efficient in terms of performance and your rule gets more clearly arranged and understandable.

 

Hope this helps.

Regards

Volker

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sandip Biswas
      Sandip Biswas

      This will provide a new dimension in the Time-Off implementation. From my experience I have seen this type of variable functionality is really very important & required.

      Author's profile photo Volker Ruof
      Volker Ruof
      Blog Post Author

      Thanks for the feedback

      Author's profile photo Jwala Malyadri Garimella
      Jwala Malyadri Garimella

      gud .this is more useful for us

      Author's profile photo Volker Ruof
      Volker Ruof
      Blog Post Author

      Thanks for the feedback

      Author's profile photo Partha Chinta
      Partha Chinta

      Good to have these kind of feature and hoping to get more flexible features will be added to Business Rules.

      Mostly expecting an operation like HRS in SAP Time Management. ๐Ÿ™‚

      Author's profile photo Volker Ruof
      Volker Ruof
      Blog Post Author

      HRS ๐Ÿ™‚ Yes, that one would be good. And an OUTTP as well ๐Ÿ˜‰

      Thanks for the feedback

      Author's profile photo Radoslav Asparuhov
      Radoslav Asparuhov

      Well, this is just kind of great. I sometimes need to use those values in the "then" parts of my rules. What happens then? I am waiting for improvement here.

      Author's profile photo Volker Ruof
      Volker Ruof
      Blog Post Author

      Thanks for the feedback

      Author's profile photo Sylvia Strangfeld
      Sylvia Strangfeld

      I would be very interested in the use cases you have in mind if you request the variable values available in the THEN part. Could you describe in more detail? Please contact me directly: sylvia.strangfeld@sap.com. Thx!

      Author's profile photo Yong Qing LIU
      Yong Qing LIU

      Hi Volker,

      We're trying to enable sick time account for employees, we tried set up a permanent time account and assign a Interim Account Update Rule, In the interim rule, we use variables to get the balance of existing employees, it's base on the sickness absence records the EE taken in past 2years, for example, if an employee have taken 10days sick leave in the past 2 years, then the balance is 180-10=170days.

      And we want to set up posting type to "Accrual", and we have test it works. But according to the SAP guide "Interim Time Account Updates | SAP Help Portal, it says the only permitted posting types are Interim Update and Period-End Processing.

      We don't need recalculation when termination.

      Can we use Accrual posting type?

      Regards,

      Kathy L

      Author's profile photo Luis Barrera
      Luis Barrera

      Hi Kathy.

      To satisfy my curiosity, what did make you design the time account as permanent rather than recurring?

      Regards,

      Author's profile photo Yong Qing LIU
      Yong Qing LIU

      Hi Luis,

      The requirement is monthly accrual. The employee have 180days for rolling 2 years. monthly accrual equal to the absence taken the same month 2years ago.

      Regards.