SAP Knowledge Base Article - Public

2688637 - How to add filter for the results while consuming a CDS view through OData service

Symptom

 How to add filter for the results while consuming a CDS view through OData service

Environment

SAP S/4HANA Cloud

Resolution

  1. Get the metadata first, <URL>/YY1_<ODATA-SERVICE>/$metadata
  2. In the metadata locate your EntitySets and check its Entity type, it will be something like this: 
     <EntitySet Name="YY1_<NAME>" EntityType="YY1_<ODATASERVICE>.YY1_<NAME>Parameters" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:content-version="1"/>
  3. Then locate the the <EntityType Name="YY1_<NAME>Parameters" as shown below
    <EntityType Name="YY1_<NAME>Parameters" sap:semantics="parameters" sap:content-version="1">
                    <Key>
                        <PropertyRef Name="P_1"/>
                        <PropertyRef Name="P_2"/>
                    </Key>
  4. Run the URL as follow https://<URL>/sap/opu/odata/sap/YY1_<ODATA-SERVICE>/EntitySet(P_1='<WHATEVER-VALUE>',P_2='<WHATEVER-VALUE>')/<RESULTNAME>
  5. If you want to use the other property instead of key to filter, the format is:https://<URL>/sap/opu/odata/sap/YY1_<ODATA-SERVICE>/EntitySet?$filter=PropertyRefName eq 'Value'

See Also

2600276 - Exposing a CDS view with parameters as OData error code LCX_MISSING_PARAMETER

Keywords

Custom CDS View, Filter, OData , KBA , BC-SRV-APS-GKE , Generic CDS Key User Editor , Problem

Product

SAP S/4HANA Cloud 1808