基于gateway实现odata(4)–查询选项3-top, skip

上一节学习了$fliter的使用,这一节学习$top, $skip, and $inlinecount的使用。

更详细学习请参看:SAP Press – OData and SAP NetWeaver Gateway

ODATA学习(SAP Press – OData and SAP NetWeaver Gateway)第6.5.3章节,第276页

The Hop and $skip query options are called client-side paging. It means
that the client (consumer) defines how many entries to receive (Hop)
and how many entries to skip ($skip) by the SAP NetWeaver Gateway
server. This enables the consumer to implement a paging functionality.
This allows you to implement quite efficient data accesses to the underlying
database, because you only need to read the records that are relevant
for the requested page. When you’re fetching your data via any
standard function module (as in this example), you can’t really benefit
from it because most of the function modules don’t support input
parameters for top and skip. What you typically find is a MAX_ROI1S input
parameter that at least limits the number of records returned. But you
can only make use of this if no sorting has to be applied on the returned
list.
MAX_ROWS = $skip + $top

——————————————————————-

$top:          返回的记录数量;
$skip:       跳过记录数,与$top一起使用,比如:$top=10&$skip=5表示:跳过5条, 然后返回最多10条数据;
$inlinecount: 返回所有的记录的数量,如果表达式中有$filter  ,那么返回的就是符合条件的记录数量;

测试使用如下:

最后使用http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H?$inlinecount=allpages&$top=1&$skip=2,得到了从第三开始的一行数据。
同时返回了所有表中的数据行项目数。如下

<feed xmlns=”http://www.w3.org/2005/Atom” xmlns:m=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata” xmlns:d=”http://schemas.microsoft.com/ado/2007/08/dataservices” xml:base=”http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/”>
<id>
http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H
</id>
<title type=”text”>ZTSALE_H</title>
<updated>2016-11-16T23:10:10Z</updated>
<author>
<name/>
</author>
<link href=”ZTSALE_H” rel=”self” title=”ZTSALE_H”/>
<m:count>4</m:count>
<entry>
<id>
http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1003′)
</id>
<title type=”text”>ZTSALE_H(Gjahr=’2016′,Zsaleid=’1003′)</title>
<updated>2016-11-16T23:10:10Z</updated>
<category term=”ZSALE_SRV.ZTSALE_H” scheme=”http://schemas.microsoft.com/ado/2007/08/dataservices/scheme”/>
<link href=”ZTSALE_H(Gjahr=’2016′,Zsaleid=’1003′)” rel=”self” title=”ZTSALE_H”/>
<content type=”application/xml”>
<m:properties xmlns:m=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata” xmlns:d=”http://schemas.microsoft.com/ado/2007/08/dataservices”>
<d:Gjahr>2016</d:Gjahr>
<d:Zsaleid>1003</d:Zsaleid>
<d:Zsaty>SO</d:Zsaty>
<d:Bukrs>1000</d:Bukrs>
<d:Werks>1000</d:Werks>
<d基于gateway实现odata(4)--查询选项3-top, skip - 第1张  | 优通SAPgort>1000</d基于gateway实现odata(4)--查询选项3-top, skip - 第2张  | 优通SAPgort>…

更多的查询选项请参看$select ,  $filter , $top ,  $skip , $inlinecount , and$orderby。

留下一个回复

你的email不会被公开。

19 − sixteen =