Formula Expression 
A formula expression allows you to perform a wide range of calculations. The formula expression offers the basic mathematical operations (addition, subtraction, multiplication, division), more advanced operations (such as exponentiation or binary AND), comparisons (greater than, less than, etc.), and a wide variety of formula functions for different purposes and data types (date and time calculation, string handling and manipulation, conversion functions, system functions, etc.).
The system offers two different editing modes for maintaining a formula expression, Normal Mode and Expert Mode:
Normal Mode
In Normal Mode, the system tries to preserve the formula integrity by preventing the user from directly editing the formula text. Rather, a user would make use of the various predefined options offered in the BRFplus workbench by clicking the respective function buttons or choosing an option from a list. This is true even for constant values you might want to enter as a formula operand. To accomplish this, you have to use the buttons provided for entering a Number or a String value. Expressions and data objects that are used as formula operands are displayed with their technical name.
Expert Mode
In Expert Mode, the system allows the user to manually edit the formula text. This can speed up formula maintenance significantly, but the user is completely responsible for the syntactical correctness of the formula text. Expressions and data objects that are used as formula operands are displayed with their ID.
In a formula expression, you can use elementary data objects and expressions as operands. In addition, structure or table data objects may also be used in a formula if the formula contains a function that expects a data object of these complex types as a parameter (for example, all table functions expect a table data object as a parameter).
In the BRFplus workbench, the system presents a list of data objects that can be used as formula operands. The data objects in the list are inherited from the context of the function to which the formula expression is assigned. In other words, a stand-alone formula expression that has not yet been assigned to a function cannot offer any context data objects.
Note
If a formula expression is assigned to more than one function, the list of context data objects available as formula operands represents the intersection of the context data objects of all involved functions. This is necessary to ensure that the formula can be calculated properly, regardless by which function it is called.
In a formula expression, you can choose from a large number of formula functions that help you retrieve, transform, and analyze data. For a better overview, the functions are grouped into categories as follows:
Function Category |
Examples |
|---|---|
Date and Time |
Calculation of difference between two points in time, in different units of measures; determination of leap years; extraction of different parts from a given point in time; etc. |
String Functions |
Concatenation and extraction of strings; string length; string similarity; etc. |
Mathematical Functions |
Logarithms; exponentiation; trigonometric functions; etc.
Parameters passed to the trigonometric functions must be given in radians (one full circle = 2 Pi). End of the note. |
System Functions |
Retrieval of system-specific information like factory calendar, operating system, logon language, etc. |
Table Functions |
Retrieval of information about, or stored in, a BRFplus table data object like maximum or minimum value, sum, average, row count, etc. |
Miscellaneous Functions |
Conversion of quantities and amounts; number rounding; check for initial values; etc. |
In addition to the function grouping, the system offers another way of finding a function: In the Filter by Text field, you can enter the name of a function (or a part of it) and let the system display all function names that match the search string. This is helpful if you know the function name already. Combined with the Show All Functions function category, this gives you the fastest access to the desired function.
For the details of each function, there is online documentation available. There you find all the information about parameters, types, calling conventions, examples, and more for each function. To display the function documentation, navigate to the respective function in the list and click the Show link in the Documentation column.
The following formula demonstrates how the trigonometric functions can be used to calculate the air-line distance between two locations on Earth. To keep things simple, we assume that the shape of the Earth is a perfect sphere.
The context of the function to which the formula belongs consists of quite a number of data objects that are partially filled by the user (Departing Town, Destination Town), partially by a decision table (Longitude, Latitude), and partially calculated by the formula (Distance).
Name |
Description |
|---|---|
Coordinates |
Structure (Longitude, Latitude). Values are determined with the help of a decision table, depending on the chosen departure and destination location. |
Departure Town, Destination Town |
Text data objects filled in by the user interactively. |
Distance |
Number data object that serves as the formula's result data object. |
Longitude Start, Longitude End, Latitude Start, Latitude End |
Helper variables used for the calculation. |
Pi |
Constant value |
6378.137 * ARCCOS ( SIN ( Latitude Start * Pi / 180 ) * SIN ( Latitude End * Pi / 180 ) + COS ( Latitude Start * Pi / 180 ) * COS ( Latitude End * Pi / 180 ) * COS ( ( Longitude End - Longitude Start ) * Pi / 180 ) )