Previous blog posts explained that the ABAP code triggers the Business Rule Framework functionality by calling the BRF+ function. You supply the input parameters to expect a returned result. The function has at least one ruleset with an optional precondition and additional variables supporting the decision making. The ruleset comes with a rule with the IF-THEN-ELSE condition.
The previous post introduced the expressions for the formula, table operation and case.
|Expression: Table operation|
You have a BRF+ function DAY_IS_WORKING_DAY checking whether a date is a working day. You can use that to call in another function NEXT_WORKINGDAY to determine the next working day.
First, you verify if the current date is a working day. If not, then check if the next day is a working day. You keep on repeating this until you find a working day. You can achieve this by using the function call and loop expressions.
|Expression: Function call|
Modular design expects that you can re-use objects. That also accounts for functions. You can call a function within a function. Make sure the calling function can pass all the required input parameters and store the result.
The function DAY_IS_WORKING_DAY requires CALENDARS, PLANT and DATE as input. At least make sure that the NEXT_WORKING_DAY also have that input either via the function signature or ruleset. Use the returned result WORKING_DAY to verify whether it is a working day. If not, the most logical approach to increase the DATE with one extra day and check if this is a working day. You use a formula to add a day to the date via the formula function DT_ADD_DAYS.
Use a loop to keep on adding days to the date until you found a working day.
ICON FOR LOOP
Various types of loops are possible:
- Loop x times, or
- Loop for every row in a table, or
- DO something UNTIL you pass a condition, or
- DO something WHILE you have a specific status is valid.
The simulation of this expression is essential to avoid an indefinite loop.
The rule within the function NEXT_WORKING_DAY checks if the supplied date is a working day. If so, then we found our WORKING_DATE, else we loop to find the next working day. This loop uses a formula to get the next date and a function call to check if this is a working day.