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 last workday of the week containing the last workday of the month

I have to admit that this one took some time to understand exactly what the requirement was and how to summarize that in a simple statement how this particular Month End run was determined.

The way the dates were calculated manually was as follows –

  • Work days were Monday to Friday plus holidays.
  • The last working day of the month is identified
  • The last working day of that same week is the date needed

What this means is

  • If the last working day of the month is midweek, the month end date is actually in the following month e.g. Month ends on Monday, the month end date could be the 4th of the next month.
  • If the last day of the month falls on a Saturday or Sunday the month end date falls before the end of the same month.
  • If the last working day of the month falls on a Friday the month end date falls on the same day.

To schedule this we break the calculation in two parts, finding the last work day of the month followed by finding the last work day of the same week.

To find the last work day of the month is quite easy, it’s a ONLY LAST(001) DAY(WORKDAY) MONTH as a rule, almost in plain English.  Which looks like this on a panel –

Copy to Clipboard

If we create a run cycle group called MONTHEND that uses this rule it effectively gives us an automatic PERIOD in which each interval starts on the last working day of the Month.

But how do we find the last working day of that same week?  There is no rule that directly can do THAT but you can find a particular day on or following those dates.

So in the applications that need to run on Month end we can apply the rule ONLY(001) DAY(FRIDAY) PERIOD(MONTHEND).  Which looks like this on a panel –

Copy to Clipboard

This works by starting at each last working day of the Month and moving forward until it finds the first Friday.  This means that we have found the end of the normal working week that contains the month end date, but this is not necessarily the last working day of the week.  We handle that by putting a free day rule of 1 (Before) on the run cycle, which means if Friday is a Freeday, it moves to Thursday, equally if Thursday and Friday are freedays it moves to Wednesday – Mission accomplished.

If you also want to run batch at Quarter End using similar criteria you might be tempted to use the same Run Cycle Group in the application and have a negative run cycle to knock out January, February, April, May, July, August, October and November.  But this won’t work, as there is no guarantee that the last working day of the week containing the quarter end will fall within March, June, September, or December.

Instead you must create a new Run Cycle Group using the rule ONLY LAST(001) DAY(WORKDAY) MONTH(MARCH JUNE SEPTEMBER DECEMBER).  Which looks like this on a panel –

Copy to Clipboard

Then any quarter end batch would be defined similarly to the month end but using the Quarter End run cycle group instead of the Month End Run Cycle Group.

The following WAPL batch loader will create the Month End and Quarter End run cycle groups –

Copy to Clipboard

Then to use these run cycle groups you could create applications like these –

Copy to Clipboard

So now you know how to combine a run cycle group with a run cycle as a 2 stage calculation.  Keep this mechanism in mind when you have your next complex criteria to resolve.