基于gateway实现odata(4)–查询选项2-filter

上一节学习了the single read  ( get_entity ),这一节学习$filter的使用。

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

下面是一个为ODATA实现$filter的ECC例子。

代码激活后,就可以使用如:/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H?$filter= (Gjahr eq ‘2016’ and Zsaleid eq ‘1002’)的方式进行筛选数据了。
但使用中发现,以下几点:

由于定义的Entity type 时使用的是引入的表结构,系统自动把字段名的除第一位外的其它位都修改成了小写,所以在地址中的Gjahr,除第一位外都是小写字母,虽然在GET_ENTITYSET的方法中把传入的字母转换为了大写要处理,但当你地址中使用的是GJAHR而不是Gjahr时,打开时会报错的,调试发现这里都进不了 GET_ENTITYSET的方法中,错误如下:

<Error_Resolution>
  <SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction>
  <SAP_Note>See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)</SAP_Note>
  </Error_Resolution>

(Gjahr eq ‘2016’ and Zsaleid eq ‘1002’)这其中有的 连接多个参数时使用的连接是“and”,还必须是小写,不能是大写字母,其中的eq也必须是小写,也不能修改成”=”

Note that the preparation of the ranges tables has certain limitations.
Similar to defining an ABAP report with se l ect -options fields, you
can’t cover all use cases. For example, a filter such as Fi eldA eq ‘A’ or
FieldB eq ‘B’ can’t be put into ranges tables because of the or operator.
It would work if you use and instead of or , but that’s of course a differ·
ent statement and thus has a different result.
For these cases, the framework provides the import variable I V_F I L TER_
STRING that contains the actual filter string provided via the Hi 1 ter
query option (but not in a ranges tables style).

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

留下一个回复

你的email不会被公开。