I built an RAP application with Header and Item using Custom Entities as I need to call external API for fetching the data.
The Select Query is called twice, once with Offset 0 and second with Offset 34. Upon Execution for the first time I have all the data fetched and I am setting the Number of Records Fetched and data. However, since the query is called twice, with offset greater than number of records, the select query is failing and throwing an error message.
Please help on how to prevent the error message
Below is my code
METHOD if_rap_query_provider~select.
** Check if data is requested.
DATA(lv_requested) = io_request->is_data_requested( ).
IF lv_requested IS NOT INITIAL.
DATA(lv_entity_id) = io_request->get_entity_id( ).
CASE lv_entity_id.
** get the bank balance
WHEN 'YYYYYYY'.
get_YYYYYYY(
EXPORTING
io_request = io_request
io_response = io_response
).
** Get the Bank statement
WHEN 'XXXXXXX'.
get_XXXXXXX(
EXPORTING
io_request = io_request
io_response = io_response
).
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDMETHOD.
********** Entity Method logic
METHOD get_YYYYYY.
**paging
DATA(lv_offset) = io_request->get_paging( )->get_offset( ).
DATA(lv_page_size) = io_request->get_paging( )->get_page_size( ).
DATA(lv_max_rows) = COND #( WHEN lv_page_size = if_rap_query_paging=>page_size_unlimited
THEN 0 ELSE lv_page_size ).
** Get the search criteria
DATA(lv_sql_filter) = io_request->get_filter( )->get_as_sql_string( ).
**search string
DATA(lv_search_string) = io_request->get_search_expression( ).
SELECT ******<Logic>
INTO TABLE _Itab
UP TO _max_rows ROWS OFFSET _offset ##TOO_MANY_ITAB_FIELDS.
IF sy-subrc NE 0.
ls_message-msgid = gc_msgid.
ls_message-msgno = '042'.
* No Data found for the given criteria
ENDIF.
IF ls_message IS NOT INITIAL.
RAISE EXCEPTION TYPE zcx_exception
EXPORTING
textid = ls_message.
ENDIF.
IF io_request->is_total_numb_of_rec_requested( ).
io_response->set_total_number_of_records( lines( lt_itab ) ).
ENDIF.
io_response->set_data( lt_itab ).
ENDMETHOD.Service Definition
Request clarification before answering.
please use with this way without offset
SELECT COUNT( * ) FROM (lv_table)
WHERE (lv_sql_filter)
INTO @DATA(lv_count).
io_response->set_total_number_of_records( iv_total_number_of_records = lv_count ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can refer to this demo from SAP. https://help.sap.com/docs/ABAP_PLATFORM_NEW/fc4c71aa50014fd1b43721701471913d/254f68c7d5374e94a88241b...
The number of records should contain the total number of records and should not be based on the max rows and offset value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.