Most of the times your SAP BW Queries are designed to take in some input parameters before the actual query is executed. For Example If I want to calculate Actual Costs incurred at each Cost Center level for a certain Controlling Area, I can pass Controlling Area as one of the input parameters for the execution of the query. The query result is now restricted to only those list of Cost Centers that belong to the given Controlling Area.
First let us interpret the metadata of the generated OData Analytics Service and then see how to execute such services.
Metadata
You could see in the metadata document three major changes.
- A new Entity Type annotated with semantics sap:semantics="parameters" is added to the service. This entity type describes the list of parameters that are required for executing the Query operation on Result Entity Type (annotated as sap:semantics="aggregate"). I will refer to it as Parameter Entity Type.
- The Result Entity Set Type is marked as sap:addressable=false.
- There is a navigation property named "Results" created for parameter Entity Type. Well this ensures that you could navigate from parameter Entity Type to Results Entity Type.
These major changes tells that we cannot execute/address the Result Entity Type directly (Try accessing them :wink: ). It can only be addressed via the Parameter Entity type. Refer to the sample attached metadata document which shows the three main changes to the metadata document.
Now that we know how to interpret the metadata lets see how to execute such OData Analytics services. I will be taking examples based on the sample service that you see in above image.
For the sake of simplicity I have listed down the key elements in the metadata document that shall be used in below examples.
Element | Type | Annotation |
---|
ZGK_CCA_D21_Q0001Parameters | Entity Type (Parameter) | sap:semantics="parameters" |
ZGK_CCA_D21_Q0001 | Entity Set | -- |
ZGK_CCA_D21_Q0001Result | Entity Type (Result) | sap:semantics="aggregate" |
Results | Navigation Property | |
Runtime
Case 1 - How to Fetch Non Aggregated Measure Values for a given Input Parameter
Let us take a simple case where I would like to fetch non aggregated values for a given Input Parameter.
OData Request
ZGK_CCA_D21_Q0001(ZP_ZCO_AREA='US01',ZI_ZCOSTCENT='',ZI_ZCOSTCENTTo='')/Results
In the above OData Request note down three main points
- We are navigating from Parameter Entity Type to Result Entity Type
- The Parameter Entity Type takes value for the its Key Properties. The Key properties of Parameter Entity Type is taken as Input Parameter for MDX queries. Refer the attached screen shot. In the screenshot you could see the properties for Parameter Entity Type. They are nothing but Key properties.
- The Parameter Entity Type should take value for its Key Properties that annotated as sap:parameter="mandatory". If the Key property is annotates as sap:parameter="optional", then it can take empty values. In the above example ZI_COSTCENT is an optional parameter and hence it can be passed with empty values.
Case 2 - How to know the values for the Input parameter
Before executing Case 1, you need to know what valid set of values Input Parameters take. To get the list of valid values for the Input parameter execute the following OData request
OData Request
ZGK_CCA_D21_Q0001?$select=ZP_ZCO_AREA
The above request gives the list of valid values for the parameter Controlling Area. Now you could use the values for constructing the OData request mentioned in Case 1.
Note - You cannot select more than one paramter in one call. Which mean I cannot execute the query ZGK_CCA_D21_Q0001?$select=ZP_ZCO_AREA,ZI_ZCOSTCENT