温馨提示:本文翻译自stackoverflow.com,查看原文请点击:sap cloud sdk - VDM's update not updating data on S/4
sap-cloud-sdk

sap cloud sdk - VDM更新不更新S / 4上的数据

发布于 2020-04-20 16:15:33

我们正在使用com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultOutboundDeliveryV2Service更新S / 4上的项目。请在下面找到代码片段:

DefaultOutboundDeliveryV2Service service = new DefaultOutboundDeliveryV2Service();

service.updateOutbDeliveryItem(
     OutbDeliveryItem.builder()
        .deliveryDocument("some key")
        .deliveryDocumentItem("some key")
        .actualDeliveryQuantity(BigDecimal.TEN)
        .build()
).execute(someDestination);

该代码已成功执行,但是在S / 4上未进行任何更新。在检查日志时,我发现以下内容:

Update strategy is to modify with PATCH, but no fields have changed. The request may be bound to fail in the target system.

这个问题是什么原因造成的?我显然已经对actualDeliveryQuantity领域进行了更改为什么更新不起作用?

查看更多

提问者
cleancoder
被浏览
29
Alexander Dümont 2020-02-05 21:29

“没有字段已更改”,因为您已编辑了自己构建的离线实体实例。

为了使您的示例正常工作,无需进行任何调整:

OutbDeliveryItem item =  OutbDeliveryItem.builder()
  .deliveryDocument("some key")
  .deliveryDocumentItem("some key")
  .build();

// The following method registers a change of the entity.
item.setActualDeliveryQuantity(BigDecimal.TEN);

// Then execute the actual update operation, which only uses the actually changed fields.
service
  .updateOutbDeliveryItem(item)
  .execute(someDestination);

如果服务抱怨缺少提供的ETag,请使用“ 按键获取”方法遵循下面进一步描述的示例或者,您明确告诉请求忽略版本标识符:

service
  .updateOutbDeliveryItem(item)
  .ignoreVersionIdentifier()
  .execute(someDestination);

而已!


或者,为了实施完整的OData更新工作流程,您需要首先使用如下所述的“按键获取”方法来获取实体

String deliveryDocument;
String deliveryDocumentItem;
HttpDestinationProperties someDestination;

// First get the item by key.
OutbDeliveryItem item = service
  .getOutbDeliveryItemByKey(deliveryDocument, deliveryDocumentItem)
  .execute(someDestination)

// The following method registers a change of the entity.
itme.actualDeliveryQuantity(BigDecimal.TEN);

// Then execute the actual update operation, which only uses the actually changed fields.
service.updateOutbDeliveryItem(item).execute(someDestination);

这样,将在内部设置ETag。实体版本标识符是大多数S / 4 OData服务启用更新/删除操作所必需的。

注意:您不仅限于密钥获取您还可以将具有筛选器的“ 获取全部”方法用于解析多个实体,以准备进一步的更新更改。