You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SAP S/4Hana OData使用$filter过滤LastChangeDate报400错误求助

问题描述

在SAP Business Accelerator Hub的「Try Out」模块中,尝试通过LastChangeDate属性过滤accountingdocuments时请求失败,但使用AccountingDocument等文本属性过滤可正常返回结果。

正常请求示例

https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=AccountingDocument%20eq%20'100000032'&$inlinecount=allpages

该请求返回的响应中,LastChangeDate值为/Date(1502841600000)/。

错误请求示例

基于响应中的日期值构造的过滤请求:

https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=LastChangeDate%20eq%20'%2FDate(1502841600000)%2F'&$inlinecount=allpages

返回400错误,响应内容:

{
  "error": {
    "code": "005056A509B11EE1BB8AF4A65EC3CA20",
    "message": {
      "lang": "en",
      "value": "Invalid parametertype used at function 'eq' (Position: 16)"
    },
    "innererror": {
      "transactionid": "25669476CF9401C0E00665F8B4DE9B04",
      "timestamp": "20240605163836.8291520",
      "Error_Resolution": {
        "SAP_Transaction": "For backend administrators: use ADT feed reader \"SAP Gateway Error Log\" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details",
        "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"
      }
    }
  }
}

疑问:是否可以实现通过LastChangeDate过滤accountingdocuments的需求?


解决方案

可以实现通过LastChangeDate过滤的需求,错误原因是你使用了JSON格式的日期字符串作为过滤条件,不符合OData的日期参数规范。

OData中针对日期类型的属性,过滤时需要使用datetime前缀加上标准ISO日期格式(yyyy-MM-dd或yyyy-MM-ddTHH:mm:ss),而非响应中返回的/Date(timestamp)/格式。

具体操作如下:

  1. 将响应中的时间戳1502841600000转换为对应的ISO日期:该时间戳对应UTC时间2017-08-16 00:00:00,即日期为2017-08-16。
  2. 构造正确的过滤条件:LastChangeDate eq datetime'2017-08-16'
  3. 对过滤条件进行URL编码后,整合到请求中。

修正后的请求示例:

https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=LastChangeDate%20eq%20datetime%272017-08-16%27&$inlinecount=allpages

如果需要更精确的时间匹配,可以带上时分秒:

https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=LastChangeDate%20eq%20datetime%272017-08-16T00%3A00%3A00%27&$inlinecount=allpages

内容的提问来源于stack exchange,提问作者AFlow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 23:33:18