
Using macros in a workbook offers a great option to improve the user experience and to expose functionality in an easy consumable manner. As long as the macros only require information that is available in Analysis already (e.g. filter values), the implementation is straightforward.
For situations, where additional information from the BW back-end is required, Analysis offers the possibility to retrieve information from the BW system, and use it in the Analysis API. In the BW system, the information that can be retrieved, is provided by a Business Add-In (BAdI).
The request to the BW system for retrieving the information, is sent once when a connection is established to the BW system. If a workbook is connected to several BW systems, each system can be asked for back-end information. The transfer format is string. This means whatever information should be transferred, it requires an encoding to string format in the BW system and a decoding from string in Analysis.
The functional area is a BAdI filter of type FUNCTIONAL_AREA.
The functional area is added with API method SAPExecuteCommand and the command SetFunctionalArea.
It must be set before Analysis is connected to the BW system. Therefore it is typically called in callback Workbook_SAP_Initialize.
You can add one functional area per BW system to a workbook.
The information is transferred to Analysis upon connecting to the BW system. The information can be accessed with the Analysis function SAPListOf and parameter CUSTOMAPPLCONTEXT. The formula returns a list with three columns (SystemID, RowCount and Content).
The following example shows the coding in Analysis.
Public Sub Workbook_SAP_Initialize()
Dim result
result = Application.Run("SAPExecuteCommand", "SetFunctionalArea", "FA_Ribbon")
End Sub
The functional area FA_Ribbon is added to the workbook.
The information is encoded to string format to be transferred.
Dim result As String
result = application.run("SAPListOf","CUSTOMAPPLCONTEXT")(3)
'The formula returns in column 3 as result the content: "hideRibbon=X"
Dim hideRibbon As Boolean
Dim parameters() As String
parameters() = Split(result, "=")
If parameters(0) = "hideRibbon" and parameters(1) = "X" Then
hideRibbon = True
Else
hideRibbon = False
End If
If hideRibbon = True
Application.run("SAPExecuteCommand","Hide","Ribbon")
End If
The result "hideRibbon=X" is the encoded string provided by the BW system.
The BAdI information is decoded from string and used to hide the Analysis ribbon with API method SAPExecuteCommand.