我们希望在我们的Java应用程序中使用CloudSDK(版本1.9.2)实现库存预订流程。我们正在调用S4 OnPremise System(1709)。
1。)我们使用服务DefaultPhysicalInventoryDocumentService()和方法.createPhysInventoryDocHeader()调用create进程。
=>结果:已创建实际库存凭证。
2.)必须计算创建的实际库存凭证的物理库存对象。为此,我们使用方法.getPhysInventoryDocItem()获取相应的项,设置新值并使用方法updatePhysInventoryDocItem()调用更新过程。
=>结果:错误:"数据服务请求必须是有条件的。尝试使用\" If-Match \"报头"
我们使用SAP的Gateway Client尝试了一次此过程。在这里,我们必须访问一个带有GET过程的实例来获得一个" eTag"退出响应,并能够将其指定为" If-Match"补丁方法中的参数。此过程适用于Gateway Client。
尽管如此,我们在Java应用程序中尝试了相同的过程。不幸的是,我们没有获得获取请求的eTag。根据后端的跟踪,在网关客户端中寻址相同的OData服务。
我们的实现是通过PostMan调用的(用于测试目的)。
补丁 - 方法:
public void doPatch(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ErpConfigContext config = new ErpConfigContext("ErpQueryEndpointHTTP");
ErpEndpoint endpoint = new ErpEndpoint(config);
String physDoc = request.getParameter("physicalInventoryDocument");
String responseUpdate = null;
PhysInventoryDocItem InvItem;
BigDecimal quantity = new BigDecimal("25.000");
try {
DefaultPhysicalInventoryDocumentService invs = new DefaultPhysicalInventoryDocumentService();
InvItem = invs
.getPhysInventoryDocItemByKey("2018", physDoc , "1")
.execute(endpoint);
logger.info(InvItem.toString());
InvItem.setQuantityInUnitOfEntry(quantity);
InvItem.setUnitOfEntry("ST");
InvItem.setFiscalYear("2018");
InvItem.setPhysicalInventoryItemIsCounted(true);
ODataUpdateResult patchResult = invs.updatePhysInventoryDocItem(InvItem).execute(endpoint);
logger.info(patchResult.toString());
responseUpdate = new Gson().toJson(patchResult);
response.setStatus(HttpServletResponse.SC_CREATED);
} catch (Exception e) {
responseUpdate = e.getMessage();
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
logger.error(e.getMessage(), e);
}
response.setContentType("application/json");
response.getOutputStream().print(responseUpdate);
logger.error(response.toString());
}
答案 0 :(得分:6)
最新版本的SAP S / 4HANA Cloud SDK(1.10.0)透明地将ETag作为更新实体的版本标识符处理。
升级您的项目以使用S / 4HANA Cloud SDK的1.10.0版,然后重试更新远程实体。
答案 1 :(得分:1)
正如Emdee所述,自SAP S / 4HANA Cloud SDK的版本1.10.0以来,在更新请求期间透明地支持ETag处理。
SAP S / 4HANA Cloud SDK的版本2.0.0允许在所有OData请求上设置自定义标头。 您可以使用它来向函数导入提供所需的ETag标头,如下所示:
new DefaultPhysicalInventoryDocumentService()
.postDifferences(...)
.withHttpHeader("If-Match", document.getVersionIdentifier())
.execute()
只有OData函数导入才需要手动设置这样的标题,而不是更新,如上所述透明地处理它。