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.). You can also enter comments into a formula to help others better understand the purpose of a particular calculation step.
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.
You can extend the functional scope of the formula expression type by defining additional functions according to the individual requirements of your use case. You can accomplish this by defining methods in the exit class assigned to the application and registering these methods as formula functions. For an in-depth documentation of customer-defined formula functions, see the How to Create Formula Functions paper on SDN (http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10e9c96f-0c8b-2b10-6885-f00adbeb314b).
In addition to the standard consistency checks that are available for all types of BRFplus objects, the system performs some specific checks for formula expressions containing calculations with data objects of type quantity that have a quantity dimension assigned. The challenge here is that each unit of measure belongs to a particular quantity dimension (time, length, speed, and so on), but there is only a limited number of combinations of operands and result data objects with different dimensions that make sense. Here are some examples:
Formula |
Result Data Object |
Valid |
|---|---|---|
Length / Time |
Speed |
yes |
Length / Mass |
Number |
no |
Note
In the first example given in the above table, do not confuse the Time operand with the BRFplus data object type Timepoint. The Time operand is in fact a data object of type Quantity with dimension Time. This is used for expressing time durations, whereas the Timepoint object type is used to refer to a particular point in time.
The system performs quantity dimension checks only for formula expressions with data objects of type quantity where the Dimension property has been maintained. If there is no dimension information available, this part of the check is omitted. In case of an undetected dimension mismatch, an error occurs at runtime.
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 ) )