cancel
Showing results for 
Search instead for 
Did you mean: 

IF_RAP_QUERY_PROVIDER~SELECT called two times causing issues

10-17-2025 10:01 PM
prasanth_kasturi Active Contributor
2913 views 13 comments
0 Likes
SAP Managed Tags
Labels
"Custom Entities""SAP ABAP RAP"
Subscribe

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

prasanth_kasturi_0-1760730971087.png

 

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

Erol_CAGLAR
Participant

 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 ).

  

rammel_sapdev
Participant

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.

rammel_sapdev_0-1760731613738.png

 

prasanth_kasturi
Active Contributor
0 Likes

Thank you for your response. I have only one record maintained in the table and it is fetched the first time and the value is set for the max number of records.

One more observation is that this is happening only if I test from Firoi App, but from preview it is good

rammel_sapdev
Participant
Before clicking the GO button, can you click F12 and show us how the both odata request look like after u click GO?
prasanth_kasturi
Active Contributor
0 Likes

I see two request in the Request Payload, Network and Console screenshot as below. Can you please help 

prasanth_kasturi_0-1760929763137.png

 

rammel_sapdev
Participant
0 Likes
When you created the fiori app in SAP BAS, did you change any setting? Is your UI service based on odata v2/v4? But yeah, it is odd and I wonder where those top/skip numbers are coming from.Usually there are even numbers (20, 30) and the is only one GET request at a time.
prasanth_kasturi
Active Contributor
0 Likes
@rammel_sapdev it is Odata V4. I did follow the pattern given in developers website for creating the fiori app, I did set some setting as suggested . Any specific settings you suggest to look at? Please let me know
rammel_sapdev
Participant
0 Likes
Do you have the link of the tutorial you followed and the settings you have changed?
prasanth_kasturi
Active Contributor