SAP Knowledge Base Article - Public

2688637 - How to add filter for the results while consuming a CDS view through OData service - SAP S/4HANA Cloud Public Edition

Symptom

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

Environment

SAP S/4HANA Cloud Public Edition

Resolution

  1. Get the metadata first, <URL>/YY1_<ODATA-SERVICE>/$metadata
  2. In the metadata locate the 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. Under the Parameters EntityType find the following:
                <NavigationProperty Name="<RESULTSNAME>" .../>
    </EntityType>
  5. Run the URL as follow https://<URL>/sap/opu/odata/sap/YY1_<ODATA-SERVICE>/EntitySet(P_1='<WHATEVER-VALUE>',P_2='<WHATEVER-VALUE>')/<RESULTSNAME>
  6. Note: If the result is very large, it's possilbe to add $top=<n> (i.e. $top=1) for testing purposes like that:

    https://<URL>/sap/opu/odata/sap/YY1_<ODATA-SERVICE>/YY1_<NAME>(P_1='<WHATEVER-VALUE>',P_2='<WHATEVER-VALUE>')/<RESULTSNAME>?$top=<n>
  7. It's possible 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, Invalid key predicate, parameters, resource not found for the segment, resource, not found, segment, service, OData Call, CDS View, URL , KBA , BC-SRV-APS-GKE , Generic CDS Key User Editor , OPU-GW-COR , Framework , How To

Product

SAP S/4HANA Cloud Public Edition all versions