Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

OData service use filter for fields not present in entityset

sahu101
Explorer
0 Kudos

I have an OData service created through SEGW which has an entity set imported from DDIC source, I want to use $filter to pass two fields to use in the select statement where clause. I don't need those two fields anywhere else and these two fields are not there in the entity set.

How can I use $filter for fields that are not a part of the entity set?

If I pass these two fields in $filter, it gives me an error "Property not found in entityset".

Is there a way to fix this or any other method on passing parameters to the getEntitySet method?

  • SAP Managed Tags:
1 ACCEPTED SOLUTION

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Hi aashish,

you can add a field manually.

Suppose your enttiy type is called 'SalesOrder'.

Then you can redefine the DEFINE method of the MPC_EXT class of your SEGW project.

The following code will add two fields 'Filter1' and 'Filter2' of Edm type string.

Kind regards,

Andre

    DATA property TYPE REF TO /iwbep/if_mgw_odata_property.
    DATA entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ.


    super->define( ).


    entity_type = model->get_entity_type('SalesOrder').


    property = entity_type->create_property( iv_property_name = 'Filter1' iv_abap_fieldname = 'FILTER1' ). "#EC NOTEXT
    property->set_type_edm_string( ).
    property->bind_data_element( 'CHAR4' ).
    property->set_filterable( abap_true ).


    property = entity_type->create_property( iv_property_name = 'Filter2' iv_abap_fieldname = 'FILTER2' ). "#EC NOTEXT
    property->set_type_edm_string( ).
    property->bind_data_element( 'CHAR4' ).
    property->set_filterable( abap_true ).



ceterum censeo RAP esse utendam
  • SAP Managed Tags:
2 REPLIES 2

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Hi aashish,

you can add a field manually.

Suppose your enttiy type is called 'SalesOrder'.

Then you can redefine the DEFINE method of the MPC_EXT class of your SEGW project.

The following code will add two fields 'Filter1' and 'Filter2' of Edm type string.

Kind regards,

Andre

    DATA property TYPE REF TO /iwbep/if_mgw_odata_property.
    DATA entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ.


    super->define( ).


    entity_type = model->get_entity_type('SalesOrder').


    property = entity_type->create_property( iv_property_name = 'Filter1' iv_abap_fieldname = 'FILTER1' ). "#EC NOTEXT
    property->set_type_edm_string( ).
    property->bind_data_element( 'CHAR4' ).
    property->set_filterable( abap_true ).


    property = entity_type->create_property( iv_property_name = 'Filter2' iv_abap_fieldname = 'FILTER2' ). "#EC NOTEXT
    property->set_type_edm_string( ).
    property->bind_data_element( 'CHAR4' ).
    property->set_filterable( abap_true ).



ceterum censeo RAP esse utendam
  • SAP Managed Tags:

0 Kudos

Hi Andre,

Thanks for this solution! Is there a way to get rid of the added fields from the result? They are only needed as input parameters but shall not appear in the output.

Kind Regards

Frank

  • SAP Managed Tags: