Skip to Content

# Expand your toolbox – how to calculate weight, area and volume in BRFplus (part 2 of 2)

In my previous blog on BRFplus and DSM I talked about my first “Hello World” type of application, and promised to showcase the formula editor with a few typical geometrical calculations in our industry.

Typically we would do this kind of calculation in variant configuration, either directly in VC syntax, or in ABAP function modules called via variant functions.

We all remember our geometry class, so the formulas are pretty straightforward and easy to grasp.

I wanted to model rectangular (or “cuboid”) and round objects. I wanted to calculate volume and net weight first.
In a second step I tried also to calculate the coated surface area – typically relevant for variant pricing of coated metal sheets.

I created a new application “Quant conversion” which contains the newly created function “QUANTITY_CONVERSION”.

I have included all necessary characteristics in the function’s signature; in real life you would transfer those in a table structure. For my example, I preferred to show input and result explicitly.

The result data object of the function is “Net weight in KG”. Within the function I created a new rule set. To do the calculations I used a number of “help variables” like e.g. volume and density. Those are only visible in the rule set and its assigned rules. I also have created a boolean variable “shape is cuboid”. I will use this later to decide whether I have a cylinder type formula or a cube-like formula.
Both the boolean variable “shape is cuboid” and the density are preset via expressions which initialize the variables when the rule set is called. Let’s first have a look how the boolean variable is  preset. I used again a simple decision table to achieve this. In ABAP I would have coded a few IFs or CASE statements. The decision table is easier to maintain if you add more shapes later. Equally simple is the setting of the density variable – again with a decision table. Need a new material? Just add a line to the table. No coding or customizing needed. Now let’s do some real rules. First rule calculates my volume for a cube. If it is a cube, change the volume (considering the input variables from the signature) based on a formula. Let’s tale a closer look at the formula (which is not very impressive) and the formula editor (which is quite impressive and powerful). The formula editor alone makes me a friend of BRFplus. Any engineer can use this without training – even I could. Nicely embedded help function. Human readable.

If you want to write a formula, you start with the result data object, here volume in MM3. This is what you actually calculate in the formula.

On the left column below you have the context (all the “local” help variables defined in the rules set, plus the signature – everything you transferred through the function’s external interface.

In the middle section below you see all the classical pocket calculator operators, and on the right a powerful set of formula function.This is nice blend of string, date, statistical and other functions  – all out of the box. In my very basic example , I multiply length, width and thickness to get a cuboids volume. Not so impressive, but correct geometry. Similarly I created two more formulas for (round) bar – which are called if the shape is equal to “bar”, … …and (hollow) tube if the shape is equal to “tube”.. In the last step I calculate the net weight from the volume using the correct density, and (just to. show off) round the net weight. I will not dive too deep into this, but you may call e.g. an ABAP function module, or use the predefined rounding operator to adjust the quantity to your needs. The only really tricky bit for me was getting the decimals right with the density (as my density is in KG/M3 and my volume is in MM3). That’s the 10 to the power of 9 term. To finalize this, I played around with rules for single and double coated metal sheets, and the related formulas.  No surprises – this was equally straight forward. ## Conclusions

• Formulas and decision tables are easy to understand & maintain – you do not need to be a programmer.
• Geometrical calculations, as we often have in our type of industries, and more complex formulas can be created (and tested!) easily in BRFplus.
• If you need to model your full set of rules (which can be easily tens of thousands in the metal industry), you should get someone more experienced who knows how to structure a model properly.

Whether you look at use cases closely related to variant configuration, or at any other type of rule-based process. I would love to hear from your experiences. What worked well? Where did you struggle? What are your lessons learned for the community?

Be the first to leave a comment
You must be Logged on to comment or reply to a post.