Warm tip: This article is reproduced from stackoverflow.com, please click
sap-cloud-sdk

VDM's update not updating data on S/4

发布于 2020-04-20 10:59:53

We are using com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultOutboundDeliveryV2Service for updating an item on S/4. Please find the code snippet below:

DefaultOutboundDeliveryV2Service service = new DefaultOutboundDeliveryV2Service();

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

This code gets executed successfully, but no update takes place on S/4. While examining the logs, I found following:

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

What is the cause of this problem? I've clearly made changes to actualDeliveryQuantity field. Why is the update not working?

Questioner
cleancoder
Viewed
32
Alexander Dümont 2020-02-05 21:29

"No fields have changed" because you edited an offline entity instance, that you've just built yourself.

To get your example working little adjustments have to made:

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

If the service is complaining about missing ETag provided, either follow the example described further below using the get-by-key appraoch. Or you explicitly tell the request to ignore the version identifer:

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

That's it!


Alternatively, in order to implement the complete OData update workflow, you need to first get the entity by using the get-by-key method as described below.

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

This way, the ETag will be set internally. The entity version identifier is a requirement for most S/4 OData services to enable update/delete operations.

Note: You are not limited to get-by-key. You can also use the get-all method with filters to resolve multiple entities, in preparation for further update changes.