Skip to Content

How to use paging in Odata?

paging in oData abap..

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Feb 28 at 11:43 AM

    Hi Parul,

    You first need to implement the method: GET_ENTITY_SET in odata.

    Code:

    METHOD maraset_get_entityset.
    DATA : it_tab TYPE STANDARD TABLE OF zmara_130495.DATA : wa_tab TYPE zmara_130495,
    ls_entityset TYPE zcl_zmara_130495_pagin_mpc=>ts_mara,
    lt_entityset TYPE zcl_zmara_130495_pagin_mpc=>tt_mara,"FOR FILTER
    wa_filter TYPE /iwbep/s_mgw_select_option,
    wa_id LIKE LINE OF wa_filter-select_options,id TYPE zmara_130495-matnr.READ TABLE it_filter_select_options INTO wa_filter WITH KEY property = 'Matnr'.IF sy-subrc = 0.READ TABLE wa_filter-select_options INTO wa_id INDEX 1 .
    IF sy-subrc = 0.id = wa_id-low.ENDIF.ENDIF.
    IF id IS NOT INITIAL.SELECT * FROM zmara_130495 INTO TABLE it_tab WHERE matnr = id ."END OF FILTER CODE
    ELSE.SELECT * FROM zmara_130495 INTO TABLE it_tab .ENDIF.IF it_tab IS NOT INITIAL.LOOP AT it_tab INTO wa_tab.MOVE-CORRESPONDING wa_tab TO ls_entityset.APPEND ls_entityset TO lt_entityset.ENDLOOP.ENDIF.
    DATA: lv_top TYPE i,
    lv_skip TYPE i,
    lv_table_size TYPE i.

    lv_top = io_tech_request_context->get_top( ).
    lv_skip = io_tech_request_context->get_skip( ).
    * >> Client Paging (top/skip)IF lv_top IS NOT INITIAL OR
    lv_skip IS NOT INITIAL.LOOP AT lt_entityset INTO ls_entityset.IF sy-tabix > lv_skip.APPEND ls_entityset TO et_entityset.
    lv_table_size = lines( et_entityset ).IF lv_top IS NOT INITIAL AND
    lv_table_size >= lv_top.EXIT.ENDIF.ENDIF.ENDLOOP.ELSE.* >> No Paging
    et_entityset = lt_entityset.ENDIF.


    ENDMETHOD.

    Go to gateway: Run the URL

    /sap/opu/odata/sap/ZMARA_130495_PAGING_SRV/MARASet?$top=2&$skip=2

    note: ZMARA_130495 here is custom table created in se11.

    maraset_get_entityset is the name of GET_ENTITY_SET method.

    Regards,

    Mrinalini

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 28 at 11:37 AM

    Hi,

    Paging (pagination) is a functionality that can be achieved with the $top and $skip commands. there has to be implemented by the data provider.

    The topic is covered in the GW100 standard training too, but you can find many resources on the SAP help:
    https://help.sap.com/viewer/68bf513362174d54b58cddec28794093/latest/en-US/30116c10d4ff42908d4a4ad023b77634.html

    and on the community too:
    https://blogs.sap.com/2011/11/04/odata-channel-api-implementing-paging-of-entity-sets/
    https://blogs.sap.com/2014/12/03/gateway-service-optimizing-performance-with-sql-paging/
    https://blogs.sap.com/2015/07/10/pagination-decrypted/
    https://blogs.sap.com/2015/08/09/pagination-decryptedpart-2-serverside-paging/

    Regards,
    Janos

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 28 at 11:46 AM

    Hi Mrinalini,

    Thanks for the great help.

    Regards,

    Parul

    Add comment
    10|10000 characters needed characters exceeded