0

I've been hardstuck on making service to expose data through API/OData. The url I use:
http://server.serversap.com/sap/opu/odata/sap/ZGW_YTI_POS_SRV/EtDataSet?$format=json&sap-client=100&

$orderby=CREATED_AT desc&
$filter=CREATED_AT ge datetime'2022-06-01T00:00:00' and CREATED_AT le datetime'2022-06-30T23:59:59'&
$top=10 

but the result is ignore the $filter and I am confused since ChatGPT said that I need to set the IV_DATE_FROM and IV_DATE_TO. I tried that but it comes out with error. And the machine once again ignore $filter. I can share the suggestion from the AI.

Sandra Rossi
14k6 gold badges29 silver badges58 bronze badges
asked Dec 12, 2025 at 3:43
1
  • Your URL is a custom service, it doesn't help. AI generates answers based on the "best" probabilities; there's no intelligence in it, no need to share what AI generates. Only provide an example that people can reproduce, what you get, what you expect, what you have tried, etc. Commented Dec 13, 2025 at 15:22

2 Answers 2

1

I assume that you using abap query to get items. You need to manually add filter to your abap query like below:

 data: LR_OBJECT type range of TDOBJECT,
 LR_ID type range of TDID,
 LR_SPRAS type range of TDSPRAS.
 loop at IT_FILTER_SELECT_OPTIONS assigning field-symbol(<FS_FILTER>).
 case <FS_FILTER>-PROPERTY.
 when 'OBJECT'.
 LR_OBJECT = value #( for WA in <FS_FILTER>-SELECT_OPTIONS (
 SIGN = WA-SIGN
 OPTION = WA-OPTION
 LOW = WA-LOW
 HIGH = WA-HIGH ) ).
 when 'ID'.
 LR_ID = value #( for WA in <FS_FILTER>-SELECT_OPTIONS (
 SIGN = WA-SIGN
 OPTION = WA-OPTION
 LOW = WA-LOW
 HIGH = WA-HIGH ) ).
 when 'SPRAS'.
 LR_SPRAS = value #( for WA in <FS_FILTER>-SELECT_OPTIONS (
 SIGN = WA-SIGN
 OPTION = WA-OPTION
 LOW = WA-LOW
 HIGH = WA-HIGH ) ).
 endcase.
 endloop.
 select *
 from MYTABLE
 into corresponding fields of table @LT_ITAB
 up to @IS_PAGING-TOP rows
 where TDOBJECT in @LR_OBJECT
 and TDID in @LR_ID
 and TDSPRAS in @LR_SPRAS.
answered Dec 12, 2025 at 12:57
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for the response you made. it surely the best practice to do so. and in my case, i dump all the error and debug it one by one until i get the bug. and thankfully its done. thank you all
0

I finally solved this issue. The root cause was a combination of how the OData filter string is parsed and how the Function Module (RFC) parameters were defined.

Here is the complete working solution to handle Date Range filters from OData ($filter=DateProperty ge datetime'...') passed into a Backend Function Module.

1. The Function Module (Backend)

Avoid using the TABLES parameter for output, as it's considered obsolete and sometimes causes issues with modern RFC calls. Use EXPORTING for the data and IMPORTING for the filter range.

Signature:


Import: IT_DATE_RANGE Type RANGE_DATE_TT (Optional, Pass Value)
Export: ET_DATA Type ZTT_MY_DATA_TABLE (Pass Value)
METHOD myentityset_get_entityset.
 
 DATA: lt_range_date TYPE zttrange_date,
 ls_range_date LIKE LINE OF lt_range_date,
 lv_temp_date TYPE string.
 
 DATA: et_data_fm TYPE ztt_sales_data,
 ls_data_fm TYPE LINE OF ztt_sales_data,
 ls_gw_data LIKE LINE OF et_entityset.
 " 1. Retrieve Standard OData Filters
 DATA(lt_filter_select_options) = io_tech_request_context->get_filter( )->get_filter_select_options( ).
 DATA(ls_filter) LIKE LINE OF lt_filter_select_options.
 DATA(ls_option) LIKE LINE OF ls_filter-select_options.
 LOOP AT lt_filter_select_options INTO ls_filter.
 LOOP AT ls_filter-select_options INTO ls_option.
 CLEAR ls_range_date.
 ls_range_date-sign = ls_option-sign.
 ls_range_date-option = ls_option-option.
 " 2. Clean the Low Date (Format: 2022年10月26日T00:00:00 -> 20221026)
 lv_temp_date = ls_option-low.
 REPLACE ALL OCCURRENCES OF '-' IN lv_temp_date WITH ''.
 REPLACE ALL OCCURRENCES OF 'T' IN lv_temp_date WITH ''.
 REPLACE ALL OCCURRENCES OF ':' IN lv_temp_date WITH ''.
 CONDENSE lv_temp_date NO-GAPS.
 ls_range_date-low = lv_temp_date(8). 
 " 3. Clean the High Date
 lv_temp_date = ls_option-high.
 REPLACE ALL OCCURRENCES OF '-' IN lv_temp_date WITH ''.
 REPLACE ALL OCCURRENCES OF 'T' IN lv_temp_date WITH ''.
 REPLACE ALL OCCURRENCES OF ':' IN lv_temp_date WITH ''.
 CONDENSE lv_temp_date NO-GAPS.
 IF strlen( lv_temp_date ) >= 8.
 ls_range_date-high = lv_temp_date(8).
 ENDIF.
 APPEND ls_range_date TO lt_range_date.
 ENDLOOP.
 ENDLOOP.
 " 4. Call Function Module (Note: IMPORTING here catches the EXPORTING from FM)
 TRY.
 CALL FUNCTION 'Z_API_GET_DATA'
 EXPORTING
 IT_DATE_RANGE = lt_range_date
 IMPORTING
 ET_DATA = et_data_fm
 EXCEPTIONS
 OTHERS = 1.
 CATCH cx_root.
 ENDTRY.
 " 5. Map Data to EntitySet
 LOOP AT et_data_fm INTO ls_data_fm.
 CLEAR ls_gw_data.
 MOVE-CORRESPONDING ls_data_fm TO ls_gw_data.
 APPEND ls_gw_data TO et_entityset.
 ENDLOOP.
 ENDMETHOD.
Crucial Check: Ensure the property name in $filter matches the OData Property Name (defined in SEGW), NOT necessarily the Database field name. It is Case Sensitive.

If your metadata says Type="Edm.DateTime", use the datetime prefix.

Correct URL Example: .../MyEntitySet?$filter=OrderDate ge datetime'2022-10-26T00:00:00' and OrderDate le datetime'2022-10-26T23:59:59'

This approach fixed the issue where the backend was receiving an empty range table.

answered Dec 15, 2025 at 9:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.