I often have conversations with customers about the number of PERIODs they have to manually update each year, and how they wished they didn’t have to.
Since the advent of both WAPL and Run Cycle groups you should have very limited needs for periods in your workload, as most things we can now do in an automated manner.
When filling out a period the test is are you simply given a list of dates to fill in, or do you know how to work out each date, but it isn’t simple. For the former you should ask how the person that gives you those dates decides, and for the latter it’s time to look again as to whether you can now automate them.
So this blog is one of a series of blogs looking at some of the unusual, complex and sometimes downright bizarre scheduling criteria I’ve been given to solve over the years. They will look at the methodology and techniques you can apply to solve them and provide real solutions in the product. Along the way teaching you some different ways of thinking about scheduling.
I do warn you that some of the concepts that follow can be a little mind blowing and may alter your perception of time.
If you have your own complex criteria that you can’t figure out how to automate, send them our way and you may find yourselves the subject of a future Complex Criteria blog.
The 4 Degrees of Anna’s Bacon
Before we start, I’m going to Repeat a really useful mnemonic from Anna Dawson to help remember the numbers for freeday rules. It’s something that has stuck with me since I was told it, and I’ve never needed to look up free day rule numbers ever since.
The rules are –
- Before – Move to the nearest work day before
- After – Move to the nearest work day after
- On – Run it on the day even if it is a free day
- Never – Never run it on a free day
Which if you take the first letters it’s BAON, so I use the word BA(C)ON to remember the order of the 4 free day rules and thereby also the number that is used in the panel. Thanks Anna.
Tenth day of the Month or Monday if on a weekend
Now at first this sounds deceptively easy. Create yourself a run cycle with a Freeday rule of 2 and a rule like this –
The Rule ONLY(10) DAY(DAY) MONTH appears to do exactly what is wanted and the free day rule moves it to the following workday – job done!
Except it isn’t, as the requirement says move the date to the following Monday NOT the following Workday, a subtle difference. The manual period always put the Monday date in regardless and any run cycles using the period could choose which free day rule to apply.
So to follow the exact specification and move it to Monday if it lands on the weekend there are 2 ways to do it.
The first method requires the creation of an extra calendar that only has Saturday and Sunday as Freedays. Then you can use the fact that a Run Cycle Group can use a different calendar from the application that uses the run cycle group to create a Run Cycle group, using the same rule as mentioned above but pointing to the special Saturday/Sunday calendar. Then you can use this run cycle group anywhere, with any calendar and apply whatever free day rules you need.
However the risk here is that in the future someone might accidentally add holidays to the special calendar, thinking they are doing a good thing fixing what they perceive to be an oversight, which will then break the run cycle group as it is no longer guaranteed to move weekend dates to Monday. Also some companies don’t like creating multiple calendars in case someone chooses the wrong one.
The second way is a bit more complicated but does not rely on calendars. It relies on approaching the problem from a different direction. Instead of solving the whole problem at once you break the requirement into parts. For this challenge we break the problem into three –
- The tenth day of the month when it falls on Monday to Friday. Here we can use the original rule, with a negative run cycle to stop it running on Saturday and Sunday
- The tenth day of the month when it falls on Saturday. For this we need to think sideways and realise that when the 10th is a Saturday this means we will need to schedule this whenever the 12th is a Monday.
- The tenth day of the month when it falls on Sunday. Here we also need to think sideways and realise that when the 10th is a Sunday this means we will need to schedule this whenever the 11th is a Monday.
We can do this in a run cycle group with a combination of 3 pairs of run cycles, all with a free day rule of 3 (On) –
The first two run cycles are a simple Positive Rule and Negative rule. They are paired together using a subset name, in this example WK as you need to be sure that the negative run cycle TENWKNEG only cancels Saturday and Sunday for TENWKPOS. This pair of run cycles will generate all the dates for when the 10th falls on a week day.
The two rules underneath are –
- TENWKPOS – ONLY(010) DAY(DAY) MONTH
- TENWKNEG – EVERY DAY(SATURDAY SUNDAY) WEEK
The next two run cycle use the Run Cycle Group feature of AND rules. These are positive run cycles that only generate dates that are common to all of the AND rules in that subset. So here we need to combine the 12th day of the month with falling on a Monday.
The two rules underneath are –
- TENSA12 – ONLY(012) DAY(DAY) MONTH
- TENSAMON – EVERY DAY(MONDAY) WEEK
Finally we need to do the same for Sunday combining the 11th day of the month with falling on a Monday.
The two rules underneath are –
- TENSU11 – ONLY(011) DAY(DAY) MONTH
- TENSUMON – EVERY DAY(MONDAY) WEEK
The end result is that between them, the three sets of rules generate all variants of the 10th day of the month, moving Saturday and Sunday to Monday.
You can use the technique of breaking the problem into separate parts for many other challenges. The fact that a run cycle group can be broken into subsets that together will generate a single set of dates allows you to break the problem apart, put it back together and then consume the combined result as a single run cycle group, exactly like you would have with a PERIOD.
The following WAPL batch loader will create a run cycle group called TENTH to solve the challenge –