-1

I am getting a payload similar to below into CPI

My aim is to replace "PurReqnExternalSystemType" value with value from field "PurchasingDocumentCategory" and remove "PurchasingDocumentCategory" field and its value from the payload

These fields appear under multiple times in the payload

PATCH A_PurchaseRequisitionItem(PurchaseRequisition='0011234',PurchaseRequisitionItem='2') HTTP/1.1

and

PATCH A_PurchaseRequisitionItem(PurchaseRequisition='0011234',PurchaseRequisitionItem='2') HTTP/1.1

How do I achieve this in SAP CPI. Any hints on grrovy script?

--batch
content-type: multipart/mixed; boundary=changeset
--changeset
content-type: application/http
content-transfer-encoding: binary
PATCH A_PurchaseRequisitionHeader(PurchaseRequisition='001234') HTTP/1.1
accept: application/json
content-type: application/json
{"PurchaseRequisition":"","PurchaseRequisitionType":"NB","PurReqnDescription":"CPI payloads","SourceDetermination":false}
--changeset
content-type: application/http
content-transfer-encoding: binary
PATCH A_PurchaseRequisitionItem(PurchaseRequisition='0011234',PurchaseRequisitionItem='1') HTTP/1.1
accept: application/json
content-type: application/json
{"PurchaseRequisition":"","PurReqnExternalReference":"6149","PurReqnItemExternalReference":"1","PurReqnExternalSystemType":"A","ExternalApprovalStatus":"A","AccountAssignmentCategory":"K","MaterialGroup":"A00906","PurchasingDocumentCategory":"B","RequestedQuantity":"1.0000000000"}
--changeset
content-type: application/http
content-transfer-encoding: binary
PATCH A_PurchaseRequisitionItem(PurchaseRequisition='0011234',PurchaseRequisitionItem='2') HTTP/1.1
accept: application/json
content-type: application/json
{"PurchaseRequisition":"","PurReqnExternalReference":"6149","PurReqnItemExternalReference":"2","PurReqnExternalSystemType":"A","ExternalApprovalStatus":"A","AccountAssignmentCategory":"K","MaterialGroup":"A00906","PurchasingDocumentCategory":"C","RequestedQuantity":"1.0000000000"}
--changeset
content-type: application/http
content-transfer-encoding: binary
PATCH A_PurchaseReqnItemText(PurchaseRequisition='0011234',PurchaseRequisitionItem='1',DocumentText='B01',TechnicalObjectType='EBAN',Language='EN') HTTP/1.1
accept: application/json
content-type: application/json
{"NoteDescription":"Test "}
--changeset
content-type: application/http
content-transfer-encoding: binary
PATCH A_PurchaseReqnItemText(PurchaseRequisition='001234',PurchaseRequisitionItem='2',DocumentText='B01',TechnicalObjectType='EBAN',Language='EN') HTTP/1.1
accept: application/json
content-type: application/json
{"NoteDescription":"Test "}
--changeset--
--batch--
user928700
  • 63
  • 1
  • 8
  • Use library to parse. For example apache commons fileupload: https://stackoverflow.com/a/13489843/1276664 – daggett Dec 19 '20 at 15:06
  • I am completely newbee to Groovy, could you please provide me some sample code, if you don't mind? – user928700 Dec 20 '20 at 09:14
  • i just searched the SAP CPI documentation and there is a standard message Decoder that could handle "MIME Multipart" format. probably you don't need to parse message by yourself: https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/LATEST/en-US/c95697a0c3914ef6be9c014761363e86.html – daggett Dec 20 '20 at 16:18
  • Hi, thanks the the link I have already tried this. This decoder does not do much actually. when I used , output of this fucntion is again the same MIME message. I want to just replace the PurchasingDocumentCategory" and remove "PurchasingDocumentCategory" field. I don't want to decode/encode the message. – user928700 Dec 21 '20 at 07:29

1 Answers1

0

I have used java.io.reader approach to read each line of the message. in a loop used replaceAll method to modify the content. in the loop each line is added to a variable of stringbuilder. this stringbuilder is finally returned back.

user928700
  • 63
  • 1
  • 8