OData: Fetch records based on Search – using Wildcard Character (*)

lightOData Wildcard Character Search.

The post describes how to fetch records using wildcard characters.

Records of Table: SCARR


Goto T Code: SEGW and Create new project with desired name:


Created Project will appear in left panel of SEGW TCode.

Now Right click on Data model → Import → DDIC structure:


Provide the Entity name and Structure name as shown below:4

Select the desired field and click on Next:5

As at least one field should be Key field, selecting CARRID here as Key:3.jpg

You can check the created Entity in sub nodes of Data ModelData Model.jpg

Now Generate Runtime Objects by clicking below button,

you’ll get a popup → Next → Savegenerate-runtime-artifacts

In Runtime Artifacts node you can see the generated Classes and Service name. Here service name is ZMTEST4_WILD_CHARS_SRV


We need to write our logic in GET_ENTITYSET method of Data Provider Extension class (DPC_EXT) 1.jpg

Double click on DPC_EXT class and navigate to GET_ENTITYSET method (In our case it is: SCARRSET_GET_ENTITYSET). We need to redefine this method  using 2 button.

Importing parameter: IO_TECH_REQUEST_CONTEXT of GET_ENTITYSET method captures input search string from front end.

Table parameter: ET_ENTITYSET send output records to frontend.

Code written in GET_ENTITYSET method:

  TYPES BEGIN OF ty_scarr,
                  carrid    TYPE s_carr_id,
                  carrname  TYPE  s_carrname,
                  currcode  TYPE s_currcode,
                  url        TYPE s_carrurl,
               END OF ty_scarr.

  DATA lt_scarr TYPE STANDARD TABLE OF ty_scarr,
                 lv_str   TYPE string,
                lw_eset  TYPE zcl_zmtest4_wild_chars_mpc=>ts_scarr.

  FIELD-SYMBOLS <fs_scarr> TYPE ty_scarr.

* Get the InputValues from frontend
  CLEAR lv_str.
  lv_str io_tech_request_context->get_search_string).

 We need to replace ‘‘ with ‘%’

* Fetch records from table SCARR
  REFRESH lt_scarr[].
  SELECT carrid
    FROM scarr
    INTO TABLE lt_scarr
    WHERE carrid LIKE lv_str.
  IF sysubrc IS INITIAL.
    UNASSIGN <fs_scarr>.
    LOOP AT lt_scarr ASSIGNING <fs_scarr>.
      MOVE-CORRESPONDING <fs_scarr> TO lw_eset.
      APPEND lw_eset TO et_entityset.
      CLEAR lw_eset.
    UNASSIGN <fs_scarr>.

Now we need to Add the service: TCode: /IWFND/MAINT_SERVICE

Provide the System Alias name and service name and Add the service:addservice

After adding the service → Click on SAP Gateway Client button or GoTo TCode: /IWFND/GW_CLIENT2.jpg

Select your EntitySet


After selecting the EntitySet, we can filter the record by search keyword:

URL: /sap/opu/odata/sap/ZMTEST4_WILD_CHARS_SRV/SCARRSet?search=*



URL: /sap/opu/odata/sap/ZMTEST4_WILD_CHARS_SRV/SCARRSet?search=L*





One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s