Querying Range of Records (Select-option functionality)
Operation: GetEntitySet (Right click à go to abap workbench), open the class in
editable mode and
Redefine the method ‘PRODUCTSET_GET_ENTITYSET’
method PRODUCTSET_GET_ENTITYSET.
data t_product_header type table of bapi_epm_product_header.
data : wa_entityset like line of et_entityset,
wa_product_header like line of t_product_header.
* Read the select option property
data wa_filter_select_options type /iwbep/s_mgw_select_option.
read table it_filter_select_options
into wa_filter_select_options
with key property = 'ProductID'
transporting select_options.
if sy-subrc eq 0.
* Read select option values
data wa_select_option type /iwbep/s_cod_select_option.
read table wa_filter_select_options-select_options
into wa_select_option
index 1.
if sy-subrc eq 0.
* prepare select-option parameter for product ids
data : t_productid_range type table of bapi_epm_product_id_range,
wa_productid_range like line of t_productid_range.
clear wa_productid_range.
wa_productid_range-sign = wa_select_option-sign.
wa_productid_range-option = wa_select_option-option.
wa_productid_range-low = wa_select_option-low.
wa_productid_range-high = wa_select_option-high.
append wa_productid_range to t_productid_range.
endif.
* Get the List of products based on product id range
call function 'BAPI_EPM_PRODUCT_GET_LIST'
tables
headerdata = t_product_header
selparamproductid = t_productid_range.
* Map the retrieved product details to the corresponding return intern
al table
loop at t_product_header into wa_product_header.
clear wa_entityset.
wa_entityset-productid = wa_product_header-product_id.
wa_entityset-typecode = wa_product_header-type_code.
wa_entityset-category = wa_product_header-category.
wa_entityset-name = wa_product_header-name.
wa_entityset-description = wa_product_header-description.
append wa_entityset to et_entityset.
endloop.
else.
* Get the List of all products
call function 'BAPI_EPM_PRODUCT_GET_LIST'
tables
headerdata = t_product_header.
* Map the retrieved product details to the corresponding return intern
al table
loop at t_product_header into wa_product_header.
clear wa_entityset.
wa_entityset-productid = wa_product_header-product_id.
wa_entityset-typecode = wa_product_header-type_code.
wa_entityset-category = wa_product_header-category.
wa_entityset-name = wa_product_header-name.
wa_entityset-description = wa_product_header-description.
append wa_entityset to et_entityset.
endloop.
endif.
endmethod.
Maintain the service for querying range of records:
Case 1: Returns list of products for the given range
/sap/opu/odata/sap/ZEPM_PROJ_SRV/ProductSet?$filter=ProductID ge ‘HT-1000’
and ProductID le ‘HT-1030’
Case 2: Returns count of products for the given range
/sap/opu/odata/sap/ZEPM_PROJ_SRV/ProductSet/$count/?$filter=ProductID ge
'HT-1000' and ProductID le 'HT-1030'