Odata実行命令
Posted yjyongil
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Odata実行命令相关的知识,希望对你有一定的参考价值。
$skiptoken 編
http://<server>:<port>/sap/opu/odata/sap/<service_name>/ProductsSet?$skiptoken=10
使い方法
- サーバーでページサイズ、つまりDPC_EXTクラスのGET_ENTITYSETメソッドを定義する必要があります。
- エンティティセットのエントリがページサイズより大きい場合は、エントリをページサイズで割ります。
- skiptoken値と、次のエントリセットへの次のリンクに基づいて、要求されたエントリセットをアプリケーションに送信します。 詳細は下の画像をご覧ください。
Step.1
Step.2
PRODUCTSSET_GET_ENTITYSET ソースコードは以下のようです。
DATA: ls_order TYPE /iwbep/s_mgw_sorting_order, lt_products TYPE STANDARD TABLE OF bapi_epm_product_header, ls_products TYPE bapi_epm_product_header, ls_entityset TYPE zcl_zdemo_gw_srv_mpc=>ts_products, lt_entityset TYPE zcl_zdemo_gw_srv_mpc=>tt_products, lv_max_rows TYPE bapi_epm_max_rows, ls_filter TYPE /iwbep/s_mgw_select_option, lr_product_id TYPE TABLE OF bapi_epm_product_id_range, ls_product_id TYPE bapi_epm_product_id_range, ls_select_options TYPE /iwbep/s_cod_select_option. * >> Check if $filter option is available * Get the filter option for product ID READ TABLE it_filter_select_options INTO ls_filter WITH KEY property = ‘ProductId‘. IF sy-subrc = 0. LOOP AT ls_filter-select_options INTO ls_select_options. MOVE-CORRESPONDING ls_select_options TO ls_product_id. APPEND ls_product_id TO lr_product_id. ENDLOOP. ENDIF. * Call the BAPI by providing the filter options * if no filter, BAPI will get the entire list of products CALL FUNCTION ‘BAPI_EPM_PRODUCT_GET_LIST‘ TABLES headerdata = lt_products selparamproductid = lr_product_id. IF lt_products IS NOT INITIAL. LOOP AT lt_products INTO ls_products. MOVE-CORRESPONDING ls_products TO ls_entityset. APPEND ls_entityset TO et_entityset. ENDLOOP. ENDIF.
上記のソースだとすべてデータを取得しますので、
$skiptoken オプションでページサイズを設定します。
Step.3
PRODUCTSSET_GET_ENTITYSETに以下のようにページサイズを設定します。
DATA: ls_order TYPE /iwbep/s_mgw_sorting_order, lt_products TYPE STANDARD TABLE OF bapi_epm_product_header, ls_products TYPE bapi_epm_product_header, ls_entityset TYPE zcl_zdemo_gw_srv_mpc=>ts_products, lt_entityset TYPE zcl_zdemo_gw_srv_mpc=>tt_products, lv_max_rows TYPE bapi_epm_max_rows, ls_filter TYPE /iwbep/s_mgw_select_option, lr_product_id TYPE TABLE OF bapi_epm_product_id_range, ls_product_id TYPE bapi_epm_product_id_range, ls_select_options TYPE /iwbep/s_cod_select_option. * >> Check if $filter option is available * Get the filter option for roduct ID READ TABLE it_filter_select_options INTO ls_filter WITH KEY property = ‘ProductId‘. IF sy-subrc = 0. LOOP AT ls_filter-select_options INTO ls_select_options. MOVE-CORRESPONDING ls_select_options TO ls_product_id. APPEND ls_product_id TO lr_product_id. ENDLOOP. ENDIF. * Call the BAPI by providing the filter options * if no filter, BAPI will get the entire list of products CALL FUNCTION ‘BAPI_EPM_PRODUCT_GET_LIST‘ TABLES headerdata = lt_products selparamproductid = lr_product_id. IF lt_products IS NOT INITIAL. LOOP AT lt_products INTO ls_products. MOVE-CORRESPONDING ls_products TO ls_entityset. APPEND ls_entityset TO lt_entityset. ENDLOOP. ENDIF. DATA: lv_page_size TYPE i VALUE 50, " Define the Page Size/ lv_index_start TYPE i, lv_skiptoken TYPE string, lv_index_end TYPE i, lv_table_size TYPE i. * Obtain the $skiptoken value if it exists in the URL lv_skiptoken = io_tech_request_context->get_skiptoken( ). * Clear the skiptoken, if the result is empty DESCRIBE TABLE lt_entityset LINES lv_table_size. IF lv_table_size IS INITIAL. CLEAR es_response_context-skiptoken. EXIT. ENDIF. * If the table size is less than the predefined page size, * send all the data IF lv_table_size < lv_page_size. et_entityset = lt_entityset. * If the table size is beyond the predefined page size, * cut the whole table into pieces with the page size ELSE. lv_index_start = lv_skiptoken. lv_index_end = lv_skiptoken + lv_page_size. ENDIF. LOOP AT lt_entityset INTO ls_entityset. IF sy-tabix > lv_index_start AND sy-tabix <= lv_index_end. APPEND ls_entityset TO et_entityset. ENDIF. ENDLOOP. * Next Link es_response_context-skiptoken = lv_index_end + 1. CONDENSE es_response_context-skiptoken.
Step.4
以上是关于Odata実行命令的主要内容,如果未能解决你的问题,请参考以下文章
仅公开路由的 .NET OData API 子集(排除 API 返回 404)
如何使用命令(API)和查询(odata)控制器将位置标头传递给响应