使用“API_PHYSICAL_INVENTORY_DOC_SRV”修补库存项目时出错(eTag - CloudSDK)

问题描述 投票:1回答:2

我们希望使用CloudSDK(版本1.9.2)在我们的Java应用程序中实现库存预订流程。我们正在调用S4 OnPremise System(1709)。

1.)我们使用服务DefaultPhysicalInventoryDocumentService()和方法.createPhysInventoryDocHeader()调用创建过程。

=>结果:创建实际库存凭证。

2.)必须计算创建的实际库存凭证的物理库存对象。为此,我们使用方法.getPhysInventoryDocItem()获取相应的项,设置新值并使用方法updatePhysInventoryDocItem()调用更新过程。

=>结果:错误:“数据服务请求必须是有条件的。尝试使用\”If-Match \“标题。”

我们使用SAP的Gateway Client尝试了一次此过程。在这里,我们必须访问具有GET过程的实例,以从响应中获取“eTag”,并能够在补丁方法中将其指定为“If-Match”参数。此过程适用于Gateway Client。

不过,我们在Java应用程序中尝试了相同的过程。不幸的是,我们没有获得获取请求的eTag。根据后端的跟踪,在网关客户端中寻址相同的OData服务。

我们的实现是通过PostMan调用的(用于测试目的)。

请求(标题/正文):Request - Header Request - Body

回应:Response

补丁 - 方法:

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());

    }
sap etag s4sdk
2个回答
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函数导入,而不是更新,如上所述透明处理它。


6
投票

最新版本的SAP S / 4HANA Cloud SDK(1.10.0)透明地将ETag作为更新实体的版本标识符处理。

升级您的项目以使用S / 4HANA Cloud SDK的1.10.0版,然后重试更新远程实体。

© www.soinside.com 2019 - 2024. All rights reserved.