Show TOC

OData Query Options Locate this document in the navigation structure

 

The OData query options supported by SAP NetWeaver 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.

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

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$select=Category,Name
    End of the code.
  • $count

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$count
    End of the code.
  • $expand

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Suppliers?$expand=Products
    End of the code.
  • $format

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$format=json
    End of the code.
  • Read $links

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products('1000')/$links/Category
    End of the code.
  • $value

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products('1000')/Name/$value
    End of the code.
Query Options Requiring Implementation

The following query options can be used, but they require implementation efforts by development:

  • $orderby

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$orderby=Category desc
    End of the code.
  • $top

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$top=5
    End of the code.
  • $skip

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$skip=10&$top=5
    End of the code.
  • $filter

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$filter=Category eq 'Notebooks'
    End of the code.
  • $inlinecount

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$inlinecount=allpages
    End of the code.
  • $skiptoken

    Syntax Syntax

    Request example:

    1. https://<server>:<port>/.../<service_name>/Products?$skiptoken=20
    End of the code.

Example

Syntax Syntax

Implementation example:

  1.   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_product_mpc=>tt_product,
              ls_entity            TYPE zcl_product_mpc=>ts_product,
              lv_table_size        TYPE i,
              lt_orderby           TYPE /iwbep/t_mgw_tech_order,
              ls_orderby           TYPE /iwbep/s_mgw_tech_order.
    
    *   Filter
        lt_filter = io_tech_request_context->get_filter( )->get_filter_select_options( ).
    
        LOOP AT lt_filter INTO ls_filter.
          IF ls_filter-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.
          ENDIF.
        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( ).
    
        "Client Paging (top/skip)
        IF lv_top IS NOT INITIAL OR
           lv_skip IS NOT INITIAL.
          LOOP AT lt_entityset INTO ls_entity.
            IF sy-tabix > lv_skip.
              APPEND ls_entity TO et_entityset.
              DESCRIBE TABLE et_entityset LINES lv_table_size.
              IF lv_top IS NOT INITIAL AND
                 lv_table_size >= lv_top.
                EXIT.
              ENDIF.
            ENDIF.
          ENDLOOP.
          "No Paging
        ELSE.
          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.
End of the code.

More Information

http://www.odata.org