Defining Advanced Execution Times with Period Functions 
SAP CPS features rich calendaring possibilities; time windows offer great flexibility while remaining easy to define. However, sometimes complex calculations are required to determine if certain conditions are met for a time window to be open, Easter for example. For this matter it is possible to create period functions. Period functions are boolean functions used in time windows that calculate when a time window is supposed to be open or closed. Period functions are complex functions written in RedwoodScript, stored in the Repository, that are used in time windows to calculate the dates and times that a time interval is open.
When you import SAP Calendars (like the Factory and Holiday calendars), these become available as period functions.
The following period functions are built-in:
Period Function |
Description |
SAP_FactoryCalendar |
Use the SAP calendar from an SAP instance to schedule jobs; the calendaring data needs to be imported from the instance |
SAP_HolidayCalendar |
Use the SAP calendar from an SAP instance to schedule jobs; the calendaring data needs to be imported from the instance |
System_Easter |
Calculates Easter or Easter-based holidays |
System_FiscalPeriods |
Calculates open days based on periods in a fiscal year. |
You can create your own period functions, however, since they are very complex, you should contact SAP for more information.
Note
You need the scripting module, which requires the Module.Scripting license key, to be able to create period functions.
Period functions support the following actions:
Action |
Description |
Export |
Export the period function into a CAR file |
Edit |
Edit the period function |
Edit Security |
Edit the security of the period function |
Delete |
Delete the period function |
Duplicate |
Make a copy of the period function to create a similar one |
Expand All |
Expand all period functions in the current filter |
New |
Create a new period function |
Filter > New Filter |
Create a new period function filter |
Filter > Edit Filter |
Edit current period function filter |
Filter > Delete |
Delete current period function filter |
The easter period function accepts one dayNumber parameter, which is the offset to easter Sunday.
No parameter or daynumber=0 means easter Sunday.
AP calendars are imported and converted to period functions to be used in time windows. Period functions of SAP calendars take arguments, as the factory calendar, for example, can include several different calendars, which all must have a unique calendar id.
SAP Calendar period functions accept the following arguments:
calendar=<SAP Instance> <Calendar ID>
Parameter |
Description |
<SAP Instance> |
The SAP Instance Name |
<Calendar ID> |
The Calendar Id, usually two characters, can be found in the output file of the SAP_ImportCalendar job. |
You should only specify instances for which you have imported the calendar with the SAP_ImportCalendar job definition and the specific calendar ID must exist in that SAP instance. Use the Opens at tab of the time window edit screen to make sure you are using the correct values.
The fiscal period function is used to calculate open days based on the fiscal year, both US and ISO-8601 fiscal years are supported. Fiscal years divide quarters in 1 five- and 2 four-week periods.
US style fiscal years start on January 1st. ISO-8601 fiscal years always start on Monday. The 4-5-4 fiscal period starts on the 2nd workday to the 6thworkday of each period.
Parameter |
Description |
Values |
Default |
week{1|2|3} |
Specifies the number of weeks for the first, second and third period of the quarter |
4 (period is 4 weeks long) 5 (period is 5 weeks long) |
week1=4 week2=4 week3=5 |
weekday{From|To} |
Specifies the day of the week. |
1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday), 8 (Workday), 9 (Weekends), 10 (Workweek), 0 (Anyday) |
weekdayFrom=8 (Workday) weekdayTo=1 (Sunday) |
weekOrDay{From|To} |
Specifies the number of the weekday in the period; if the number is larger than the number of days in the period, it specifies the last weekday. |
1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday), 8 (Workday), 9 (Weekends), 10 (Workweek), 0 (Anyday) |
weekOrDayFrom=1 (Sunday) weekOrDayTo=1 (Sunday) |
isISOPeriod |
Specifies the start of the year. |
true (Monday) false (January 1st) |
false (Year starts on Monday). |
Note
The period function parameters are case-sensitive.
You can search for period functions using filters and the Search Period Functions box on the Period Functions tab. This box is known as the intelliSearch box and located under your username on the top right-hand side of the user interface. Filters allow you to specify a list of objects with static criteria. IntelliSearch allows you to specify complex queries in a simple way using prefixes. Prefixes are used to specify which property you are searching in and have short and long syntaxes. For example, if you want to display all period functions with the term import in the comment, you would use the search criteria as follows:
c:import
You can search more than one property, as follows:
c:import n:Bi
Note
No spaces should be entered before or after the colon (:).
See the Advanced Object Search for more information.
The following table illustrates the available prefixes for period functions:
Prefixes |
Description |
n, name |
searches the name property |
c, com, comment |
searches the comment property |
d, desc, description |
searches the description property |
a, app, application |
searches the application property |
You can only delete period functions when no other objects relate to them. For example, if there are time windows that use the period function, the period function cannot be deleted until all time windows that use it have been edited to not use it anymore. You can see all objects that relate to the period function in Related Objects in the lower detail pane and on the show page.
The table in related objects contains three columns:
Type - the type of objec with a link to itt
Related Object - the name of the object with a link to it
Used As - objects can sometimes be used in different roles
Privilege |
Description |
PeriodFunction.Create |
Create period functions |
PeriodFunction.Delete |
Delete period functions |
PeriodFunction.Edit |
Edit period functions |
PeriodFunction.View |
Access period functions |
You can grant privileges on two levels, Access and Admin; a privilege granted on Admin level allows the grantee to grant the privilege to other users. These privileges can be granted system-wide, per partition or isolation group.
If you have the security module, which requires the Module.Security license key, you have an additional Security tab on the period function. It allows you to specify which users can access, edit, and delete the period function.
In the following examples, tables illustrate the fields of the time window element that need to be filled, all other fields are left with their default values.
In this example, you want to have the time open on the fourth workday of the SAP Factory Calendar of every month. You need 3 time windows in this case. One that is always closed, one that uses the SAP Factory Calendar and one for the day shift.
Note
We need the TW_AlwaysClosed and TW_GermanFactoryCalendar time windows below because we want to force SAP CPS to use the SAP Calendar for determining and counting workdays, this way it takes public holidays into account.
You need to create a time window that is always closed. Only the following fields need to be specified:
Field |
Value |
Name |
TW_AlwaysClosed |
Is Calendar |
true (checked) |
You also need a time window to use the SAP Factory Calendar:
Field |
Value |
Name |
TW_GermanFactoryCalendar |
Is Calendar |
true (checked) |
The German factory calendar of the PR1 instance is used in a time window element as follows:
Field |
Value |
Period Function |
SAP_FactoryCalendar |
with parameters |
calendar=PR1 de |
The time window with the day shift is the one you will use in SAP CPS:
Field |
Value |
Name |
SAP_4th_Workday |
Is Calendar |
true (checked) |
If an open day is closed during |
TW_AlwaysClosed |
the shift this day |
Forward |
to the |
4 |
open day in |
TW_GermanFactoryCalendar |
The following time window element defines Good Friday (Friday preceding easter).
Field |
Value |
Period Function |
System_Easter |
with parameters |
daynumber=-2 |
Field |
Value |
Period Function |
System_FiscalPeriods |
with parameters |
week1=4 week2=5 week3=4 weekOrDayFrom=2 weekdayFrom=8 weekOrDayTo=6 weekdayTo=8 isISOPeriod=true |