In the context of Transformations you can choose for rule type Formula. SAP delivered a Formula Builder with many ready-to-use Formulas. It is even possible to extend the Formula Builder with your own custom Formulas by implementing Business Add-in (BAdI) RSAR_CONNECTOR.

My requirement was not only to deliver such a custom Formula. I also had to add a message to the Monitor Log in case a certain condition was met. In this blog I would like to share with you how to handle such a requirement and to discuss some implementation aspects.

# BAdI Implementation

Custom Formulas can be made available by implementing classic BAdI RSAR_CONNECTOR. Next to the on-line BAdI documentation you can refer to the following documents for detailed implementation instructions:

- How to Integrate Custom Formulas into the Formula Builder;
- Custom Formulas in SAP BW Transformations;
- SAP Help – Transformation Library and Formula Builder.

Result of my implementation is a new custom group with custom Formulas.

**Figure 1**: Example custom group with custom Formulas

The last custom Formula is used in the example Transformation rule.

**Figure 2**: Example Transformation rule with a custom Formula

# Monitor Log Messages

Implementing the BAdI was actually the easy part. It was not so easy to implement Monitor Log messages in the custom Formula.

For reference purposes I used standard Formula LOG_MESSAGE. I copied the relevant source code from the standard Formula and appended it to my own implementation. Please refer to line 12 to 17 in the next screenshot.

**Figure 3**: Source code in BAdI implementation

Unfortunately, my custom Formula did not send any messages to the Monitor Log. After some investigation I found that also standard Formula LOG_MESSAGE did not send the messages to the Monitor Log.

I raised an SAP Support ticket and it turned out to be a program error. After implementing SAP Note 2285154 – 730SP15:Standard formula function LOG_MESSAGE doesn’t send the issue was solved for the standard Formula. However, the custom Formula still did not send any messages.

Diving a bit deeper I found an interesting explanation. The generated Transformation program is based on template programs such as RSTRAN_RULE_TMPL_ROUTINE. In the source code you can see how the Formula routine is composed. Pay attention to line 173 in the next screenshot.

**Figure 4**: Template program for Transformation rule

The source code of line 174 to 180 is only applied if the Formula contains string LOG_MESSAGE.

So the “hidden feature” is that you have to include string LOG_MESSAGE in the technical name of the custom Formula. Only then the crucial source code is appended to the Transformation rule routine in the generated program.

**Figure 5**: Generated Transformation program

# Conclusion

In this blog I demonstrated how to send a message to the Monitor Log in the context of a custom Formula. You have to append similar source code to the BAdI implementation as found in standard Formula LOG_MESSAGE. A small “hidden feature” is that you also have to include string LOG_MESSAGE in the technical name of the custom Formula. Only then crucial source code is appended to the Transformation rule routine in the generated program. Now the messages are correctly sent to the Monitor log.

Philipp SchornbergNice article and thanks for the “investigation” with the monitor message!

It would be interesting to know, why the requirement for “LOG_MESSAGE” in the name of the function was made.

Philipp SchornbergI just thought about a bit off topic question:

Since AFAIK all the built-in formulas are HANA optimized, they’re probably going to be used a lot more in the future.

Is it possible to create HANA optimized custom formulas by yourself? Would BW even check such a thing?

Sander van WilligenPost authorHi Philipp,

First of all, thanks for your positive feedback.

At the moment I do not have experience with creating HANA optimized custom formulas. As far as I understood there is a limited set of standard HANA optimized formulas which are taken care of by SAP (i.e. converted to HANA SQL script / stored procedures, etc). I do not expect that there is any standard SAP functionality to dynamically convert the logic of custom formulas. It might be that implementing an ABAP Managed Database Procedure is a work-around in realizing a HANA optimized custom formula.

I suggest to create a new Discussion in SAP BW Powered by SAP HANA to get a second opinion.

Best regards,

Sander

Andreas SchindlerDo you have found a solution for HANA optimized formulas?

Philipp SchornbergSince it’s possible from BW 7.5 SP4 to also create field based HANA SQL Script routines (not only expert routines for the whole transformation), I don’t think any workaround (if it exists) with formulas is necessary there any more. So that would be the solution in my opinion.

Andreas Schindler…ok, thanks. Then I have to wait for BW 7.5 ðŸ˜‰