[SAP HCM TM] Enhance logic when generating work schedules
3 min read
1. Understanding business requirements
In Vietnam we have 6 public holiday periods every year, all of them are fixed date:
The above days are non-working days and the employees will have 1 paid day for each public holiday date. Sometimes a public holiday falls on Sunday and the next business day (usually Monday) will become the alternative holiday date. In this case, we use a term called "mondayisation" to imply the transition of public holiday from Sunday to Monday.
However, there are so so many working patterns in Vietnam's labor market, a company uses a working pattern with the day off on Monday sometimes will have to "tuesdayised" its public holidays. Similar requirements will require "wednesdayisation", "thursdayisation",...
So the business requirement here is to create many public holiday calendars for each group of employees that have the same working pattern.
2. Understanding system configuration
The most common solution is to create many separate public holiday calendars for each working pattern. Let me illustrate with the below image.
I don’t feel comfortable with this solution because there are so many holiday calendars to be maintained. Each year the SAP HCM consultant will have to adjust all the floating holidays (the lunar ones) for every calendar.
In this blog post, I will show you how to achieve the mission without cloning the holiday calendar.
First, let’s look at the Tcode PT01 – Create Work Schedule.
This tcode will combine a desired working pattern with a public holiday calendar then resulting in a record of table T552A (Monthly Work Schedule):
If you look closely inside PT01, you will find out an include that calls to a function module named HR_GENERATE_WORK_SCHEDULE. This function module holds the main role in generating monthly work schedule.
Continue to dive into HR_GENERATE_WORK_SCHEDULE, you will encounter 2 function parts that SAP reserved for user custom logic.
This time I choose to create the custom country function, I have to create a new function module named HR_MOD_WORK_SCHEDULE_99 (because my country grouping is 99).
My new function module has 2 parameters, exactly like the ones mention inside HR_GENERATE_WORK_SCHEDULE:
Now let’s talk about the way my function will modify the generated monthly work schedule. Basically, the logic is to loop over all the dates in the month and check if there is any public holiday with zero planned working hours then move it to the next working day.
Because HR_GENERATE_WORK_SCHEDULE is called once a month, so the above logic has a big gap is when the public holidays fall into the last days of the current month then they can't be moved to the next month.
To fill this gap, I will divide my function into three parts:
- Part 1: Move holidays inside the previous month (if any)
- Part 2: Move holidays inside the current month and unmoved holidays of the previous month (if any)
- Part 3: Modify the current month's calendar
Ok, now let’s check the result:
I have several employees are assigned to the public holiday calendar VZ.
The first employee works from Monday to Saturday weekly, so all the public holidays fall on Sunday will generate another alternative holiday:
The second employee works from Monday to Friday weekly, so all the public holidays fall on weekends will generate another alternative holiday:
You can notice that the Liberation Day fall on April 30 has been moved successfully to May 02.
Ok, that is all for today. Thanks for reading 😀
May the best solution be with you