Skip to Content
Personal Insights
Author's profile photo Sreenu Reddy Yarramachu

Wildcard Character Search in OData

Wildcard Character Search:

Wildcard character in a Select query is used to locate a specific item when you can’t remember exactly what to search.

To perform a wild card search, use the characters + and *.

+ will match any single character, and * will match any string of characters.

However, * can only be used as a wildcard at the beginning or end of a string.

Step1:

Create a new project in the SEGW T-Code.

Step2:

Add the properties by importing a structure/table.

Select the required fields/properties and mandatory to select at least one key filed from the list.

Generate Runtime objects.

Step3:

Now, redefine the AIRLINESET_GET_ENTITYSET method.

 

  METHOD airlineset_get_entityset.
*** --- Get the Selected string
    DATA(lv_str) = io_tech_request_context->get_search_string( ).
**** --- Replace
    REPLACE ALL OCCURRENCES OF '*' IN lv_str WITH '%'.
*** --- Get Airline Details
    SELECT carrid carrname currcode url FROM
          scarr INTO CORRESPONDING FIELDS OF TABLE et_entityset
          WHERE carrid LIKE lv_str.
    IF et_entityset IS NOT INITIAL.
** -- Inline Count
      es_response_context-inlinecount = lines( et_entityset ).
** -- Paging
      CALL METHOD /iwbep/cl_mgw_data_util=>paging
        EXPORTING
          is_paging = is_paging
        CHANGING
          ct_data   = et_entityset.
    ENDIF.
  ENDMETHOD.

Register the service.

Step4:

URI: /sap/opu/odata/SAP/ZWILD_CHARS_SRV/AirlineSet?search=A*&$format=json

 

Thanks for reading this blog.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.