cancel
Showing results for 
Search instead for 
Did you mean: 

How to Execute Batch Post in OData?

iamjaredm021
Participant
0 Kudos

Hi All,

Please advise on how to execute batch post (i.e. update multiple entries to database) in OData without using associations / expansion. Right now, I was able to execute batch post through creation of association / expand from principal entity then implementing logic on CREATE_DEEP_ENTITY method. However, we are looking for an alternative way to have it done not with that approach. Is it possible? Please advise how could it be done.

Thanks,

Jay

Accepted Solutions (1)

Accepted Solutions (1)

former_member206574
Active Participant
0 Kudos

Hi JAY

Add one more header in Gateway Client Request with content-type

Please see the Image.

Regards,

Venu

iamjaredm021
Participant
0 Kudos


Hi Venu,

I have added a header in the request as you've suggested but still encountered the same error.

Is the request body I'm using is correct?

--batch

Content-Type: multipart/mixed; boundary=changeset

--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

POST IDPAllEmployeesSet HTTP/1.1

Content-Type: application/atom+xml

Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:content type="application/xml">
    <m:properties
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:ViewID>ZZLTVSR</d:ViewID>
      <d:EmployeeName>No data maintained</d:EmployeeName>
      <d:FirstName />
      <d:LastName>No data maintained</d:LastName>
      <d:PersonnelNo>82001225</d:PersonnelNo>
      <d:OrgID>12003777</d:OrgID>
      <d:StatusID>0</d:StatusID>
      <d:StatusName>Not Started</d:StatusName>
      <d:NotApplicable>false</d:NotApplicable>
      <d:LastChangedBy />
      <d:LastChangedOn>00000000</d:LastChangedOn>
      <d:AvailableOn />
      <d:NextJob />
      <d:ReportsTo>PA-UK-T109, Test-109</d:ReportsTo>
      <d:Manager>false</d:Manager>
      <d:Supervisor>false</d:Supervisor>
      <d:StartDate>20030807</d:StartDate>
      <d:EndDate>99991231</d:EndDate>
    </m:properties>
  </atom:content>
</atom:entry>

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

POST IDPAllEmployeesSet HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:content type="application/xml">
    <m:properties
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:ViewID>ZZLTVSR</d:ViewID>
      <d:EmployeeName>No data maintained</d:EmployeeName>
      <d:FirstName />
      <d:LastName>No data maintained</d:LastName>
      <d:PersonnelNo>00003703</d:PersonnelNo>
      <d:OrgID>12001726</d:OrgID>
      <d:StatusID>0</d:StatusID>
      <d:StatusName>Draft</d:StatusName>
      <d:NotApplicable>false</d:NotApplicable>
      <d:LastChangedBy />
      <d:LastChangedOn>00000000</d:LastChangedOn>
      <d:AvailableOn />
      <d:NextJob />
      <d:ReportsTo>PA-UK-T109, Test-109</d:ReportsTo>
      <d:Manager>false</d:Manager>
      <d:Supervisor>false</d:Supervisor>
      <d:StartDate>20030801</d:StartDate>
      <d:EndDate>99991231</d:EndDate>
    </m:properties>
  </atom:content>
</atom:entry>


--changeset--
--batch--

Also, I only redefined the corresponding CREATE_ENTITYSET of entity IDPAllEmployeesSet. Will that suffice to handle the operation?

Thanks,

Jay

Answers (3)

Answers (3)

former_member206574
Active Participant
0 Kudos

Hi Jay,

Please send your payload what is using for POST operation so that i can check.

Regards,

Venu

iamjaredm021
Participant
0 Kudos

Hi Venu,

Please find below detials.

Request URI:

/sap/opu/odata/SAP/YGLOPD_GPA_IDP_DOCUMENTS_SRV/$batch

HTTP Request Header:

Content-Type: multipart/mixed; boundary=batch

HTTP Request Body:

--batch

Content-Type: multipart/mixed; boundary=changeset

--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

POST IDPAllEmployeesSet HTTP/1.1

Content Type: application/atom+xml

Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:content type="application/xml">
    <m:properties
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:ViewID>ZZLTVSR</d:ViewID>
      <d:EmployeeName>No data maintained</d:EmployeeName>
      <d:FirstName />
      <d:LastName>No data maintained</d:LastName>
      <d:PersonnelNo>82001225</d:PersonnelNo>
      <d:OrgID>12003777</d:OrgID>
      <d:StatusID>0</d:StatusID>
      <d:StatusName>Not Started</d:StatusName>
      <d:NotApplicable>false</d:NotApplicable>
      <d:LastChangedBy />
      <d:LastChangedOn>00000000</d:LastChangedOn>
      <d:AvailableOn />
      <d:NextJob />
      <d:ReportsTo>PA-UK-T109, Test-109</d:ReportsTo>
      <d:Manager>false</d:Manager>
      <d:Supervisor>false</d:Supervisor>
      <d:StartDate>20030807</d:StartDate>
      <d:EndDate>99991231</d:EndDate>
    </m:properties>
  </atom:content>
</atom:entry>

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


POST IDPAllEmployeesSet HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:content type="application/xml">
    <m:properties
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:ViewID>ZZLTVSR</d:ViewID>
      <d:EmployeeName>No data maintained</d:EmployeeName>
      <d:FirstName />
      <d:LastName>No data maintained</d:LastName>
      <d:PersonnelNo>00003703</d:PersonnelNo>
      <d:OrgID>12001726</d:OrgID>
      <d:StatusID>0</d:StatusID>
      <d:StatusName>Draft</d:StatusName>
      <d:NotApplicable>false</d:NotApplicable>
      <d:LastChangedBy />
      <d:LastChangedOn>00000000</d:LastChangedOn>
      <d:AvailableOn />
      <d:NextJob />
      <d:ReportsTo>PA-UK-T109, Test-109</d:ReportsTo>
      <d:Manager>false</d:Manager>
      <d:Supervisor>false</d:Supervisor>
      <d:StartDate>20030801</d:StartDate>
      <d:EndDate>99991231</d:EndDate>
    </m:properties>
  </atom:content>
</atom:entry>


--changeset--
--batch--

Thanks,

Jay

former_member206574
Active Participant
0 Kudos

Hi Jay,

It seems the payload you are sending is wrong.

Along with Create_entity you have to redefine the methods

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGINand/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END

Please check the below link for batch operations.

Regards,

Venu

iamjaredm021
Participant
0 Kudos


Hi Venu,

Those methods have been redefined as well. For the post operation, I have redefined IDPALLEMPLOYEESS_CREATE_ENTITY of the entity and not /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CREATE_ENTITY.

Please help point out what is wrong in the payload as I follow the structure of the request provided in the document in the link above.

Thanks and regards,

Jay

EkanshCapgemini
Active Contributor
0 Kudos
iamjaredm021
Participant
0 Kudos

Hi Ekansh,

I have redefined methods /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_BEGIN and /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_END as instructed. Also, will it suffice redefining *_CREATE method of the entity set to handle the POST operation? Is there anything else I need to do?

I tried to execute batch posting but just got unsupported media type error.

Payload Body Request

--batch

Content-Type: multipart/mixed; boundary=changeset


--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

POST IDPAllEmployeesSet HTTP/1.1

Content-Type: application/atom+xml

Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:content type="application/xml">
    <m:properties
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:ViewID>ZZLTVSR</d:ViewID>
      <d:EmployeeName>No data maintained</d:EmployeeName>
      <d:FirstName />
      <d:LastName>No data maintained</d:LastName>
      <d:PersonnelNo>82001225</d:PersonnelNo>
      <d:OrgID>12003777</d:OrgID>
      <d:StatusID>0</d:StatusID>
      <d:StatusName>Not Started</d:StatusName>
      <d:NotApplicable>false</d:NotApplicable>
      <d:LastChangedBy />
      <d:LastChangedOn>00000000</d:LastChangedOn>
      <d:AvailableOn />
      <d:NextJob />
      <d:ReportsTo>PA-UK-T109, Test-109</d:ReportsTo>
      <d:Manager>false</d:Manager>
      <d:Supervisor>false</d:Supervisor>
      <d:StartDate>20030807</d:StartDate>
      <d:EndDate>99991231</d:EndDate>
    </m:properties>
  </atom:content>
</atom:entry>


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

POST IDPAllEmployeesSet HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 975

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:content type="application/xml">
    <m:properties
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:ViewID>ZZLTVSR</d:ViewID>
      <d:EmployeeName>No data maintained</d:EmployeeName>
      <d:FirstName />
      <d:LastName>No data maintained</d:LastName>
      <d:PersonnelNo>00003703</d:PersonnelNo>
      <d:OrgID>12001726</d:OrgID>
      <d:StatusID>0</d:StatusID>
      <d:StatusName>Draft</d:StatusName>
      <d:NotApplicable>false</d:NotApplicable>
      <d:LastChangedBy />
      <d:LastChangedOn>00000000</d:LastChangedOn>
      <d:AvailableOn />
      <d:NextJob />
      <d:ReportsTo>PA-UK-T109, Test-109</d:ReportsTo>
      <d:Manager>false</d:Manager>
      <d:Supervisor>false</d:Supervisor>
      <d:StartDate>20030801</d:StartDate>
      <d:EndDate>99991231</d:EndDate>
    </m:properties>
  </atom:content>
</atom:entry>


--changeset--
--batch--

Please advise on this.

Thanks,

Jay

iamjaredm021
Participant
0 Kudos

Hi Ekansh,

As per my understanding, the use of $batch is to allow sending of multiple requests. Would that mean, based from my sample body request, that each of POST transaction will be handled seperately for each entry but not as single POST transaction for all? Please help confirm on this.

Thanks,

Jay