2330688 - How to Use Methods And Filters in OData Services

SAP Knowledge Base Article - Public

2330688 - How to Use Methods And Filters in OData Services


Below are few commonly used Filters in OData services



http://<Tenant URL>/sap/c4c/Odata/v1/<Custom/Standard OData Service name>/Entity Type/Query Option/Option 


$batch Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/$batch Perform several OData query operations (create, update or delete) with a single HTTP POST call
$count Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection/$count Returns the total number of the collection (in this case total number of Opportunities)
$format Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$format=json Returns entries (in this case Opportunities) in JSON format with server side paging
$top Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$top=10 Returns top 2 entries. Top 2 is defined by server logic here
$search Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$search='Porter' Returns entries with at least one of the search enabled fields containing the word 'Porter'
$select Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$select=OpportunityID,AccountID Returns entries with only two attributes, in this case OpportunityID and AccountID
$skip Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$skip=10 Skips the first 10 entries and returns the rest
$inlinecount Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$top=10&$inlinecount=allpages Returns the top 10 entries and also returns the total number of entries in the collection
$expand Not Available https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$top=10&$format=json&$expand=AccountMainAddress Expands to the Navigation Property AccountMainAddress
$orderby desc https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$orderby=CloseDate desc&$top=10 Performs orderby CloseDate field in Opportunities and selects the top 10 entries from the ordered list.
The 'desc' means descending order.
$filter eq https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=AccountID eq '1234' Gets all Opportunities that contain AccountID 1234
ge, le

https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=AccountID ge '1234' and AccountID le '1240'

Gets Opportunities with AccountID greater or equal to 1234 and AccountID lesser or equal to 1240
datetimeoffset https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=CreatedOn ge datetimeoffset '2017-01-01T00:00:00Z' Shows records created on or after the given date
endswith https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=endswith(AccountName,'LCC') All Opportunities where AccountName ends with LLC
startswith https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=startswith(CreatedBy, 'P') All Opportunities that were created by a user with the name starting with 'P'
ne https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=CreatedBy ne 'Employee Name' All Opportunities not created by given name
gt, lt https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=AccountID gt '1234' and AccountID lt '1240' Filters Opportunities with AccountID greater than 1234 and lesser than 1240
or https://<myTenantURL>/sap/c4c/odata/v1/c4codata/OpportunityCollection?$filter=CountryCode eq 'US' or CountryCode eq 'UK' Filters Opportunities with Country Code 'US' or Country Code 'UK'



KBA , SRD-CC , Cross Components , How To


SAP Hybris Cloud for Customer all versions