Show TOC

OData Query OptionsLocate this document in the navigation structure

The OData query options supported by SAP Gateway belong to either of these categories:
  • They are automatically available in the framework, no further actions needed by development.
  • They are available, but they require implementation efforts from development.
Table 1:
OData Query Options Additional Implementation Needed
$select no
$count no
$expand no
$format no
Read $links no
$value no
$orderby yes
$top yes
$skip yes
$filter yes
$inlinecount yes
$skiptoken yes
Query Options: No Additional Implementation Needed
The following framework query options are available automatically.
  • $select
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$select=Category,Name
  • $count
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$count
  • $expand
    Request example:
    https://<server>:<port>/.../<service_name>/Suppliers?$expand=Products
  • $format
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$format=json
  • Read $links
    Request example:
    https://<server>:<port>/.../<service_name>/Products('1000')/$links/Category
  • $value
    Request example:
    https://<server>:<port>/.../<service_name>/Products('1000')/Name/$value
Query Options Requiring Implementation
The following query options can be used, but they require implementation efforts by development.
  • $orderby
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$orderby=Category desc
  • $top
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$top=5
  • $skip
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$skip=10&$top=5
  • $filter
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$filter=Category eq 'Notebooks'
  • $inlinecount
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$inlinecount=allpages
  • $skiptoken
    Request example:
    https://<server>:<port>/.../<service_name>/Products?$skiptoken=20
Example

Implementation example:

METHOD products_get_entityset.


    DATA: lt_return            TYPE TABLE OF bapiret2,
          lt_filter            TYPE /iwbep/t_mgw_select_option,
          ls_filter            TYPE /iwbep/s_mgw_select_option,
          lt_category_filter   TYPE STANDARD TABLE OF bapi_epm_product_categ_range,
          ls_category_filter   TYPE bapi_epm_product_categ_range,
          ls_sel_option        TYPE /iwbep/s_cod_select_option,
          lv_top               TYPE int4,
          lv_skip              TYPE int4,
          lv_skiptoken         TYPE int4,
          lt_entityset         TYPE zcl_zag_product_mpc=>tt_product,
          ls_entity            TYPE zcl_zag_product_mpc=>ts_product,
          lt_orderby           TYPE /iwbep/t_mgw_tech_order,
          ls_orderby           TYPE /iwbep/s_mgw_tech_order,
          lv_count             TYPE i.

*   Filter
    lt_filter = io_tech_request_context->get_filter( )->get_filter_select_options( ).

    LOOP AT lt_filter INTO ls_filter WHERE property EQ 'CATEGORY'.
      LOOP AT ls_filter-select_options INTO ls_sel_option.
        CLEAR ls_category_filter.
        MOVE-CORRESPONDING ls_sel_option TO ls_category_filter.
        APPEND ls_category_filter TO lt_category_filter.
      ENDLOOP.
    ENDLOOP.

    CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_LIST'
      TABLES
        headerdata         = lt_entityset
        selparamcategories = lt_category_filter
        return             = lt_return.

*   Order By
    lt_orderby = io_tech_request_context->get_orderby( ).
    READ TABLE lt_orderby INTO ls_orderby INDEX 1.
    IF sy-subrc EQ 0.
      IF ls_orderby-order EQ 'desc'.
        CASE ls_orderby-property.
          WHEN 'PRODUCT_ID'.
            SORT lt_entityset BY product_id DESCENDING.
          WHEN 'NAME'.
            SORT lt_entityset BY name DESCENDING.
          WHEN 'CATEGORY'.
            SORT lt_entityset BY category DESCENDING.
        ENDCASE.
      ELSEIF ls_orderby-order EQ 'asc'.
        CASE ls_orderby-property.
          WHEN 'PRODUCT_ID'.
            SORT lt_entityset BY product_id ASCENDING.
          WHEN 'NAME'.
            SORT lt_entityset BY name ASCENDING.
          WHEN 'CATEGORY'.
            SORT lt_entityset BY category ASCENDING.
        ENDCASE.
      ENDIF.
    ENDIF.

*    paging
    lv_top = io_tech_request_context->get_top( ).
    lv_skip = io_tech_request_context->get_skip( ) + 1.

    "Client Paging (top/skip)
    IF lv_top IS NOT INITIAL OR
    lv_skip NE 1.
      LOOP AT lt_entityset INTO ls_entity FROM lv_skip.
        APPEND ls_entity TO et_entityset.
        ADD 1 TO lv_count.
        IF lv_count = lv_top.
          EXIT.
        ENDIF.
      ENDLOOP.
    ELSE.
      "No Paging
      et_entityset = lt_entityset.
    ENDIF.

    "Server Paging (skiptoken)
    lv_skiptoken = io_tech_request_context->get_skiptoken( ).
*   for server paging functionality (not implemented in this example)
*   you need to return a fixed size of entries (e.g. 100) and fill export parameter
*   es_response_context-skiptoken

*   Inlinecount
    IF io_tech_request_context->has_inlinecount( ) = abap_true.
      DESCRIBE TABLE et_entityset LINES es_response_context-inlinecount.
    ELSE.
      CLEAR es_response_context-inlinecount.
    ENDIF.

  ENDMETHOD.