Skip to content
Business Rule Framework
  • Home
    • Get informed
    • Practical advice
    • Be prepared
    • Career opportunities
  • Blog
    • Disclaimer
    • Cookie Policy
  • Training courses
  • Contact Me
Training Courses

Visualising BRF+ expressions (part 2)

  • December 12, 2019December 16, 2019
  • by Isard Haasakker

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.

Function icon Function
Function input icon Function input
Function result icon Function result
Ruleset icon Ruleset
Ruleset precondition icon Ruleset precondition
Ruleset input icon Ruleset input
Rule icon Rule input

The previous post introduced the expressions for the formula, table operation and case.

FOrmula icon Expression: Formula
Table operation icon Expression: Table operation
Case icon Expression: Case

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.

Function call icon 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.

Loop icon Expression: Loop

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.

BRF+ Function NEXT_WORKING_DATE
Training Courses

Visualising BRF+ expressions (part 1)

  • December 11, 2019December 16, 2019
  • by Isard Haasakker

Previous blog posts explained the Business Rule Framework visualisation for functions, rulesets and rules. It gives you sufficient detail to make straightforward decisions within BRF+, using the available context.

The context exists of the function signature, function result and the additional variables defined within the ruleset.

Function input icon Function input
Function result icon Function result
Ruleset input icon Ruleset input

For example, a rule returns an error message when the combination of the material type and material group is not allowed.
You see that these types of validations are simple and do not take advantage of the capabilities within the Business Rule Framework tool.
You use expressions to add complexity in the decision making.

Expressions allow you to use the context to enrich the data within the BRF+ function, ruleset or rule. They are the foundation for modular development.

This blog post uses SAP calendars as an example of how to work with expressions.
The BRF+ function DAY_IS_WORKING_DAY exists to check if a specific date is a working day.
The result is the boolean element WORKING_DAY, returning either a true or false value.
Three types of input exist. The table CALENDARS contains all entries of the SAP table TFACS. The structure PLANT includes the configuration data of a specific plant from the SAP table T001W. The element DATE consists of the date to be checked and linked to the domain DATUM in the SAP data dictionary.

You only need one ruleset, named DETERMINE_WORKING_DAY.
Within this ruleset, you only want to check if the date is a working day.

You start with extracting the year, month and day from the DATE. New ruleset variables YEAR, MONTH and DAY are required. The expression for the formula fills the variables with a value.

Formula icon Expression: Formula

You determine a value for a field using specific formula functions allowing you to play with mathematical equations, string manipulations and also date conversions.
You extract the year, month and day from a specific date via the formula functions DT_PART_YEARS, DT_PART_MONTHS and DT_PART_DAYS.

You continue with selecting the specific calendar for the plant, using the table operation expression.

Table operation icon Expression: Table operation

You can select a specific row in the CALENDARS table and store it in the new structure CALENDAR_SELECTED.
The selection criteria are the factory calendar of the plant, available in the field PLANT-FABKL and the YEAR from the date supplied.

You proceed with selecting the month of the selected calendar, utilising the case expression.

Caseicon Expression: Case

The calendar details store the working days month-by-month in a specific field within the structure CALENDAR_SELECTED. The field MON01 represents January and MON12 December.
You use the MONTH from the DATE to select the calendar month in the CALENDAR_SELECTED and store the result in the new element DAYS_IN_MONTH.

The element DAYS_IN_MONTH contains a string of 0 and 1 values, each character representing a day. The first day of the month is the first character, and the last day the last character. The value 1 identifies a working day.

You can now create a new formula to determine the new DAY_IN_MONTH element, using the formula function SUBSTRING and element DAY to locate the working day indicator.

You now have all the information for a simple IF-THEN-ELSE statement.
If the DAY_IN_MONTH has the value 1, then WORKING_DAY is true, else WORKING_DAY is false.

Visualising this BRF+ function has the following result:

BRF+ Function DAY_IS_WORKING_DAY
Training Courses

Visualising BRF+ rules and rulesets

  • December 10, 2019December 11, 2019
  • by Isard Haasakker

The Business Rule Framework uses rules to determine a result based on an IF-THEN-ELSE structure.

The IF statement defines a condition that can be either true or false. When the IF statement is true, you set the actions in the THEN section. Otherwise, you use the ELSE section to list the tasks when the IF statement is false.

You have the ruleset to group the rules within a function by setting a sequence.

A function must have at least one ruleset that consists of at least one rule.

Ruleset icon Ruleset
Function result icon Rule

The ruleset can have a precondition. You want to use this to skip the rules within this ruleset and speed up the function processing time.

The rules will use data to determine the result. The data supplied in the function signature is available for decision making. When additional data is required, then define other variables within the ruleset.

The sequence in which variables added in the ruleset is essential. For example, when you have two additional variables, A and B, for the ruleset. When the value of A is needed to determine B, then define variable A before B.

Ruleset precondition icon Ruleset precondition
Ruleset input icon Ruleset input

The input parameters in the function and ruleset are also called the “context”. The context is an overview of all the data accessible to make a decision.

Imagine you want to select a specific factory calendar influencing a decision in a rule. You can supply all calendars as table CALENDARS via the function input parameters. The ruleset will define a new variable that filters all supplied calendars to only keep those linked to a specific factory calendar into CALENDARS_SELECTED.

The table CALENDARS uses the structure CALENDAR linked to the SAP data dictionary TFACS. 

You cannot use the structure CALENDAR again to define another BRF+ table. Instead, you need to create a new structure CALENDAR_SELECTED, also linked to TFACS, as the basis for identifying the table CALENDARS_SELECTED.

The context contains two tables CALENDARS and CALENDARS_SELECTED and two structures CALENDAR and CALENDAR_SELECTED.

The table CALENDARS can contain all calendar information in the SAP database and passed to the BRF+ function. Then the ruleset can decide how to filter the data. One ruleset might filter on the plant, whereas other rulesets use the customer unloading point or shipping point.

The rule can have unlimited statements to get to a final result. The sequence of the steps within the THEN or ELSE section is important.
When the rule has two steps then they are processed sequentially top-down.

Assigning values to the context is done via expressions, explained in another blog post.

Training Courses

Visualising BRF+ functions

  • December 9, 2019December 11, 2019
  • by Isard Haasakker

Understanding the inner workings of the Business Rule Framework might be daunting for many. Some find a visual representation of the BRF+ components beneficial and increases the likelihood to embrace the tool to become more efficient and productive.

Visualising BRF+ is done via several blog posts, and this will be the first in the series, focusing on the function.

Function icon BRF+ function

The function allows you to communicate between the ABAP program and the complex decision making with the Business Rule Framework.

The function contains a signature, that consists of:

Function input icon Function input
Function result icon Function result

You can offer many types of data objects as input:

Data object: Element Element: A single value.
Data Object: Structure Structure: Collection of single values.
Data Object: Table Table: Rows of data with the same structure.

Often the data object is linked to the SAP Data Dictionary. Then changes made in this dictionary are also applied to the BRF+ data object when they are updated.
For example, a BRF+ structure relates to the SAP Data Dictionary. The structure is updated in the SAP system (via transaction code SE11). This change is also applied within BRF+ when you refresh the structure definition.

Use the following icon to identify that the data element refers to the SAP Data Dictionary:

Data dictionary icon SAP Data Dictionary object

Only one result is returned, which could be:

Data object: Element Element: A single value.
Data Object: Table Table: Rows of data with the same structure.

Returning only one result is very important to realise. Imagine you want to determine a packing material for a specific product. You also know that finding a suitable packing material might not be possible due to data errors in the database. When you want to validate the data and also return the identified packing material, then two BRF+ functions need to be created. At first, you check data quality via the first function and issue messages. When it passes the data validation, then the second function will supply the packing material.

For example, your system makes a distinction in packing materials based on whether it is second-hand. The material type and material group are used to identify second-hand materials. The incorrect combination of a material type and material group can exist for second-hand materials. This bad data can result in inaccurate packing material. Therefore, you only want to return a packing material after it passed the validation of data in your database. You need two separate BRF+ functions because they have two different purposes.

You can activate a function after identifying the signature, with at least one input parameter and the return parameter. The code template becomes available, and the developer can cut and paste this into the ABAP code. However, you get no result when you execute the program because you are missing the complex decision making. Next step is to define rulesets in your function to analyse the input to generate a result.

That is a topic for the next blog post for the visualisation of BRF+ components.

Recent Posts

  • BRF+ at the centre of your excellence
  • IDOC monitoring triggering BRF+ requirements
  • Why your business is not aware of BRF+

Categories

  • Be Prepared
  • Career Opportunities
  • Get Informed
  • Practical Advice
  • Training Courses
  • Uncategorized
Theme by Colorlib Powered by WordPress