Skip to Content

OData(v2) search option to dynamically search on columns

In native HANA 1.0 (SP12) SQL you have the option when searching on CDS enabled views to limit your search criteria to specific columns only.

For example we have a HANA CDS view with 4 enabled search columns (Description_1 - Description_4)
To restrict the search only to column 1 we can use the following statement in SQL:

SELECT * <viewname> where CONTAINS("Description_1",'waterleakage');

Question is if this is also possible when exposing the CDS view with OData(v2).
So far I haven't been able to find a solution how to do this based on documentation from SAP or OData

http://<system>/services/search.xsodata/Search?search=waterleakage

I understand that the search criteria is send to the CONTAINS predicate, but the question is if you can also add some additional parameters to this on which columns to search on ?
This without creating separate CDS views/services.

In this case we want for example only to search on Description_1

Many thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Feb 12 at 06:50 PM

    Hi Patrick,

    you have first to enable search on view level by using the annotation.

    @Search.searchable : true;

    as described in this blog:

    https://blogs.sap.com/2014/12/04/enabling-search-in-sap-hana-using-cds/

    In a second step you define which columns of your CDS are to be considered in a freestyle search (for example a SELECT…) where no columns are specified.

    Interestingly the same annotations also work for ABAP based CDS views as described in the SAP Online Documentation (section Search annotations). So if you annotate a CDS based OData Service in S/4HANA or Suite on HANA it would work as well.

    https://help.sap.com/doc/saphelp_nw751abap/7.51.0/de-DE/38/baf2fc3a8e4ed887b29de738296fa9/frameset.htm

    That means you don't have to bother with complicated $filter statements nor have your OData Clients to specifiy which columns to search.

    Best Regards,

    Andre

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 12 at 02:12 PM
    -2

    hi Patrick,

    rather than just telling you how to do a like operation in odata v2... here is the url to the documentation for the various operation queries you can perform on Odata: https://www.odata.org/documentation/odata-version-2-0/uri-conventions/

    keep in mind you can use multiple operators on various columns using an & to join several operations

    hope this helps you.

    Add comment
    10|10000 characters needed characters exceeded