Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
carsten_ziegler
Active Contributor

Customer feedback shows that BRFplus formula expressions are heavily used. Next to decision tables they are probably the most popular concept.
Often customers do not make use of texts to simplify the user experience. In case of formulas, texts could be used to show the particular calculation step. For example take a look at the following screenshot. What do you find more clear, the explanatory text “Apply Promotion” or the formula text “Shelf Price / (1 + Customer Discount)”?

BRFplus Formula with good text

As you can see in the screenshot below, the text shown next to the formula icon is taken from the expression's Text attribute. However, in this example the Text attribute simply repeats the formula itself, rather than describing the formula's purpose on a higher level of abstraction. Note that good use of texts can make a big difference in the acceptance of the solution by business-side experts.

Formula in BRFplus Ruleset

From the various projects in which I have been involved, I took home mainly the following three requirements with respect to the formula expression:

  • Text editor instead of point and click interface
  • Improved formula parser for better error messages
  • More formula functions (e.g. for string and timepoint operations)

Text Editor for Formulas

The first requirement is part of our backlog for 2012. We plan to offer much improved UIs for trees, rules, and also for formulas. If things work out as planned, customers will be able to install a support package on NW 7.0 Enhancement Package 3 (NW703) or NW 7.31 (NW731). With the support package, they will get the option to activate a new kind of user interfaces. The following lab screenshot shows how the formula could look like. We expect a lot of improvement especially from the in-place menus and the ability to write the formula in a powerful text editor without the need to point and click as known from today's UI. 

Rich Text Editor of BRFplus Formula

Formula Parser

With SP 3 of NW 7.0 Enhancement Package 3 (NW703) or NW 7.31 (NW731), BRFplus returns better and much more detailed messages in case of formula errors. A new formula parser has been written to better analyze the formula strings and return precise information about the nature and position of an error. Take a look at the next screenshot for an example.

Formula with errors

Formula Functions

The second requirement is much easier to address. Via SAP notes, we have recently added many more formula functions and we will continue to do so. Whenever you miss one of the formula functions listed below, you may search in OSS notes and install them on your systems. However, we did not only add new formula functions but also improved the existing ones, for example by making them more flexible with respect to input data.

Date and Time Functions

Formula FunctionDescription
DT_ADD_DAYSAdd days to a Timepoint
DT_ADD_HOURSAdd hours to a Timepoint
DT_ADD_MINUTESAdd minutes to a Timepoint
DT_ADD_MONTHSAdd months to a Timepoint
DT_ADD_QUARTERSAdd quarters to a Timepoint
DT_ADD_SECONDSAdd seconds to a Timepoint
DT_ADD_WEEKSAdd weeks to a Timepoint
DT_ADD_YEARSAdd years to a Timepoint
DT_CONVERT_TIMEPOINT_TYPEConvert a Timepoint into another type
DT_DURATION_DIFFCalculate difference in seconds, then convert to unit (decimals)
DT_DURATION_DIFF_DAYSCalculate difference in seconds, then convert to days (decimals)
DT_DURATION_DIFF_HOURSCalculate difference in seconds, then convert to hours (decimals)
DT_DURATION_DIFF_INTReturns the time difference in the specified unit (integer)
DT_DURATION_DIFF_INT_DAYSCalculate difference in seconds, then convert to days (integer)
DT_DURATION_DIFF_INT_HOURSCalculate difference in seconds, then convert to hours (integer)
DT_DURATION_DIFF_INT_MINUTESCalculate difference in seconds, then conv to minutes (integer)
DT_DURATION_DIFF_INT_MONTHSCalculate difference in months (integer)
DT_DURATION_DIFF_INT_QUARTERSCalculate difference in months, then conv to quarters (integer)
DT_DURATION_DIFF_INT_SECONDSCalculate difference in seconds
DT_DURATION_DIFF_INT_WEEKSCalculate difference in seconds, then convert to weeks (integer)
DT_DURATION_DIFF_INT_YEARSCalculate difference in month, then convert to years (integer)
DT_DURATION_DIFF_MINUTESCalculate difference in seconds, then conv to minutes (decimals)
DT_DURATION_DIFF_MONTHSCalculate difference in seconds, then convert to months (decimals)
DT_DURATION_DIFF_QUARTERSCalculate difference in seconds, then convert to quarters (decimals)
DT_DURATION_DIFF_SECONDSCalculate difference in seconds
DT_DURATION_DIFF_WEEKSCalculate difference in seconds, then convert to weeks (decimals)
DT_DURATION_DIFF_YEARSCalculate difference in seconds, then convert to years (decimals)
DT_GET_CURRENT_DATEReturns the current local system date
DT_GET_CURRENT_DTReturns the current local system date & time
DT_GET_CURRENT_DT_OFFSET_UTCReturns the current loc. system date & time w. offset to UTC
DT_GET_CURRENT_TIMEReturns the current local system time
DT_GET_CURRENT_UTCReturns the current global UTC timestamp
DT_GET_DAY_OF_WEEKReturns day of week for a given TP as number: MO=1... SU=7
DT_GET_DAY_OF_YEARReturns day of year for a given TP as number
DT_GET_FIRST_DAY_OF_WEEKReturns the calendar setting 'First Day of the Week'
DT_GET_SYSTEM_DATEReturns local date in system time zone
DT_GET_SYSTEM_DTReturns local datetime in system time zone
DT_GET_SYSTEM_DT_OFFSET_UTCReturns local datetime w. offset to UTC in system time zone
DT_GET_SYSTEM_TIMEReturns local time in system time zone
DT_GET_SYSTEM_TIMEZONEGet time zone of system (from DB-table TTZCU)
DT_GET_SYSTEM_TIMEZONE_TEXTGet text of system time zone
DT_GET_TIMEZONE_DATEReturns the local date for a time zone
DT_GET_TIMEZONE_DTReturns the local datetime for a time zone
DT_GET_TIMEZONE_DT_OFFSET_UTCReturns the local datetime w. offset to UTC for a time zone
DT_GET_TIMEZONE_TEXTGet text of time zone
DT_GET_TIMEZONE_TIMEReturns local time for a time zone
DT_GET_USER_DATEReturns local date in users time zone
DT_GET_USER_DTReturns local datetime in users time zone
DT_GET_USER_DT_OFFSET_UTCReturns local datetime w. offset to UTC in user time zone
DT_GET_USER_TIMEReturns local time in user time zone
DT_GET_USER_TIMEZONEGet time zone (sy-zonlo) of user (sy-uname)
DT_GET_USER_TIMEZONE_TEXTGet text of users time zone
DT_GET_UTC_TIMESTAMPReturns the current UTC timestamp
DT_HAS_53_WEEKSReturns TRUE if a year has 53 weeks
DT_IS_ACTIVE Checks whether the Timepoint is active w.r.t the calendar
DT_IS_LEAP_YEARReturns TRUE if year is a leap year
DT_IS_NULLReturns TRUE if a Timepoint is NULL (date part is 00010101)
DT_IS_VALIDChecks the validity of a Timepoint
DT_MAXFinds the later Timepoint of the given two Timepoints
DT_MINFinds the earlier Timepoint of the given two Timepoints
DT_NEXT_ACTIVEReturns the next active TP if the given TP is not active
DT_PART_DATEReturns the date part from a Timepoint
DT_PART_DAYSReturns the day part from a Timepoint
DT_PART_HOURSReturns the hour part from a Timepoint
DT_PART_MINUTESReturns the minute part from a Timepoint
DT_PART_MONTHSReturns the month part from a Timepoint
DT_PART_QUARTERReturns the quarter (i.e. 1, 2, 3 or 4) from a Timepoint
DT_PART_SECONDSReturns the second part from a Timepoint
DT_PART_TIMEReturns the time part from a Timepoint
DT_PART_WEEKSReturns the week of the year from a Timepoint
DT_PART_YEARSReturns the year part from a Timepoint
DT_PREVIOUS_ACTIVEReturns the previous active TP if the given TP is not active
DT_ROUND_TO_FIRSTRounds the Timepoint to first w.r.t the given time unit
DT_ROUND_TO_LASTRounds the Timepoint to last w.r.t the given time unit
DT_ROUND_TO_MIDDLERounds the Timepoint to middle w.r.t the given time unit
DT_SET_CALENDAR_WEEKSet the calendar week for a Timepoint
DT_SET_DAY_OF_THE_YEARSet the day of the year for a Timepoint
DT_SET_PART_DAYSSet the days part of a Timepoint
DT_SET_PART_HOURSSet the hours part of a Timepoint
DT_SET_PART_MINUTESSet the minutes part of a Timepoint
DT_SET_PART_MONTHSSet the months part of a Timepoint
DT_SET_PART_SECONDSSet the seconds part of a Timepoint
DT_SET_PART_YEARSSet the years part of a Timepoint
DT_SET_QUARTER_OF_THE_YEARSet the quarter of the year for a Timepoint
DT_SUBTRACT_DAYSSubtract days from a Timepoint
DT_SUBTRACT_HOURSSubtract hours from a Timepoint
DT_SUBTRACT_MINUTESSubtract minutes from a Timepoint
DT_SUBTRACT_MONTHSSubtract months from a Timepoint
DT_SUBTRACT_QUARTERSSubtract quarters from a Timepoint
DT_SUBTRACT_SECONDSSubtract seconds from a Timepoint
DT_SUBTRACT_WEEKSSubtract weeks from a Timepoint
DT_SUBTRACT_YEARSSubtract years from a Timepoint

Functions for Character Strings

Formula FunctionDescription
CONCATENATE Concatenate two strings
CONDENSETrims off leading and trailing white space
COUNT_SUBSTRINGCounts a given substring in a string
EDIT_DISTANCEComputes the number of operation required for transforming two strings
FIND_SUBSTRINGFinds a substring in a string
FIND_SUBSTRING_POSITIONFinds the position of substring in a string
INSERT_STRINGInserts a string at given position in a string
REPLACE_STRINGReplaces the position of the string with another string
REPLACE_SUBSTRINGReplaces all occurences of a substring with another string
REVERSE_ Reverts a string
SHIFT_LEFT_PLACESShifts a string to left by n places
SHIFT_LEFT_SUBSTRINGRemoves all leading occurrences of a substring from a string
SHIFT_RIGHT_PLACESShifts a string to right by n places
SHIFT_RIGHT_SUBSTRINGRemoves all trailing occurrences of substring from a string
STRING_LENGTHReturns the length of a string
STRING_SIMILARITYMeasures the similarity of two strings
SUBSTRINGReturns the specified part of a string
SUBSTRING_FROM_IDXReturns the end of a string from the given offset
SUBSTRING_FROM_STRReturns a string before the substring
SUBSTRING_TO_IDXReturns the beginning of a string up to the given offset
SUBSTRING_TO_STRReturns a string after the substring
TOUPPERConverts a character string into upper case  

Mathematical Functions

Formula FunctionDescription
ABSAbsolute Value
ARCCOSArccosine
ARCSINArcsine
ARCTANArctangent
COSCosine
COSHHyperbolic cosine
DIVCalculates the whole number ratio of the two numbers
EXPExponential function to the base e
FRACReturns the decimal value of a fraction
LOGNatural logarithm to the base e
LOG10Logarithm to the base 10
MODCalculates the integer remainder from dividing two numbers
POWERRaise to a power
SIGNSign
SINSine
SINHHyperbolic Sine
SQRTCalculates the Square Root of a Number
TANTangent
TANHHyperbolic Tangent
TONUMBERConverts Text/Number/Boolean/Amount/Quantity/Timepoint to number
TRUNCReturns the integer part of a decimal fraction

Miscellaneous Functions

Formula FunctionDescription
ANDBoolean operator AND
CONVERT_AMOUNTConverts an amount to the specified currency
CONVERT_QUANTITYConverts a quantity to the specified unit
GET_CURRENCYReturns the currency as text from an amount
GET_UNITReturns the unit as text from a quantity
IFTest
IS_INITIALReturns TRUE, if the transferred value is 'blank'
MAXReturns the larger of two values
MINReturns the smaller of two values
NOTBoolean operator NOT
ORBoolean operator OR
ROUNDRounds the value to a specified number of decimal places
TO_AMOUNTCombines a number and currency into a BRF+ amount
TO_QUANTITYCombines a number and unit into a BRF+ quantity

System Functions

Formula FunctionDescription
SYS_INFO_CALENDER_DAYReturns the factory calendar day
SYS_INFO_CLIENT_IDReturns the client ID
SYS_INFO_CURRENT_DATEReturns the current date
SYS_INFO_DAYLIGHT_SAVINGChecks the daylight saving time selection
SYS_INFO_DB_SYSTEMReturns the name of the database system
SYS_INFO_HOSTReturns the application server ID
SYS_INFO_LANGUAGEReturns the language key
SYS_INFO_LOCAL_DATEReturns the local date for the current user
SYS_INFO_LOCAL_TIMEReturns the local time
SYS_INFO_OPERATING_SYSReturns the operating system
SYS_INFO_SAP_RELEASEReturns the SAP system release
SYS_INFO_SYSTEM_IDReturns the name of the system ID
SYS_INFO_TIME_ZONEReturns the time zone
SYS_INFO_TIME_ZONE_DIFFReturns the time zone difference
SYS_INFO_USER_NAMEReturns the user name

Table Functions

Formula FunctionDescription
TABLE_AVG_AMOUNTReturns the average of the amounts in a table column
TABLE_AVG_NUMBERReturns the average of the numbers in a table column
TABLE_AVG_QUANTITYReturns the average of the quantities in a table column
TABLE_MAX_AMOUNTReturns the maximum amount from a table column
TABLE_MAX_NUMBERReturns the maximum number from a table column
TABLE_MAX_QUANTITYReturns the maximum quantity from a table column
TABLE_MAX_TIMEPOINTReturns the maximum timepoint from a table column
TABLE_MIN_AMOUNTReturns the minimum amount from a table column
TABLE_MIN_NUMBERReturns the minimum number from a table column
TABLE_MIN_QUANTITYReturns the minimum quantity from a table column
TABLE_MIN_TIMEPOINTReturns the minimum timepoint from a table column
TABLE_ROW_COUNTCount the number of rows in a table
TABLE_SUM_AMOUNTReturns the sum of the amounts in a table column
TABLE_SUM_NUMBERReturns the sum of the numbers in a table column
TABLE_SUM_QUANTITYReturns the sum of the quantities in a table
20 Comments