0

In our application we are using S4Hana SDK for consuming the services of S4Hana.

For update calls to S4 we are using PATCH request type. While doing so found that we are not able to set null value during update(PATCH).

For Eg:

--batch_A
Content-Type: multipart/mixed; boundary=changeset_176b-5a0d-cdab

--changeset_B
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE RequisitionItems(PurchaseRequisition='',PurchaseRequisitionItem='00000',DraftUUID=guid'00163e4e-c788-1eea-81bd-ddd3e2c48bf2',IsActiveEntity=false) HTTP/1.1
Plant: 0001
Currency: EUR
PurchaseOrg: 0001
CompanyCode: 0001
sap-contextid-accept: header
Accept: application/json
Accept-Language: en-GB
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 106

{"ExtPurgOrgForPurg":"0001","PurchasingGroup":"001",**"ExtPlantForPurg":null,**"ExtCompanyCodeForPurg":"0001"}
--changeset_B--
--batch_A--

Here I am trying to set ExtPlantForPurg to null, but the entity is not getting updated with the same, while debugging found that the update request body doesn't contain this field only(its ignored as it contains null)

Let me know if there is any way to update the null values for the property using PATCH request.

medha
  • 3
  • 2
  • Can you please try the same update call not in a batch context? I'm wondering where the `MERGE` verb is coming from, as there should be only PATCH or PUT in an update call (to my knowledge). Also [this](https://hc.apache.org/httpcomponents-client-4.5.x/logging.html) might be interesting to debug the outgoing requests. – Christoph Schubert Nov 14 '19 at 16:13
  • This is the batch request for our application, internally in our application we are making use of the cloud sdk to make call to s4hana service. We are using modifyingEntity() method on the vdm entity, as per my understanding this using PATCH request type. Hence the update call to s4hana service will be PATCH type – medha Nov 15 '19 at 06:33
  • Yep, that I understood. But now I'm wondering why there is the `MERGE` verb used in your example above. And again, to make this problem easier to debug it would be great, if you could run the same without the batch surroundings (just for debugging, in your application you are free to use the batch feature). – Christoph Schubert Nov 15 '19 at 09:13
  • Then I would ask you to show us the code where you update the entity in your app, instead of the batch request sent to your application. – Emdee Nov 15 '19 at 09:29
  • Please find below the code we use to update the entity in S4 sspprService.updateItemCDSViewForGuidedBuying(item).modifyingEntity().cachingMetadata().execute(getS4Destination()); While debugging I found that the getQueryBuilder method has the ODataJsonMapResolver.NullHandling.FILTER, which is ignoring the input parameters(update body) which has null value for the property. – medha Nov 18 '19 at 04:42
  • @medha: Kindly put the source code you posted as comment in the question above, this improves readability, and format it properly. Furthermore, kindly show us the update request body and the response from SAP S/4HANA. Also, we recommend to try out if the desired update works via Postman. – Emdee Nov 18 '19 at 18:26

1 Answers1

0

You can use the includingFields() functionality to specifically list fields that should be updated regardless whether their content has changed.

MatKuhr
  • 505
  • 4
  • 13