Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
harikrishna_malladi
Active Participant
Business Scenario:

There may be certain scenarios wherein instances may logically bind together and requires to be handled or processed in conjunction with the same logical unit of work.

Example:

Take for instance of sales order, wherein update of two or more related entities may be required and must be processed together in a single request.SAP Net Weaver Gateway can be used to process such scenarios with its capability to execute multiple operations in a single request.

Gateway provides an OData API into a SAP system. This uniform interface supports a given set of operations like Create, Read, Update and Delete. However, based on the business requirements, it may become relevant for clients to send multiple operations in a single HTTP request.Begin with SP04, SAP Net Weaver Gateway offers the capability for client operations to batch multiple operations into a single HTTP request.

Pre-requisites:


  1. Access to SAP Net Weaver ABAP 7.02 SP7 or system with higher configuration, having SAP Net Weaver Gateway ABAP add-ons installed.

  2. Installation of back-end SAP ECC 6.0 or higher version along with the IW_BEP gateway add-on(Optional)

  3. Google chrome with Advanced Rest Client (ARC) extension or other compatible REST Client that can send RAW HTTP requests.

  4. Basic understanding of ABAP Development.


Batch request consists of two components

  1. Batch request header

  2. Batch request body


Batch request header

Batch request are sent as a single HTTP POST request to the batch end point of the service.

E.g.: http://:base service URL/sap/opu/odata/iwfnd/Servicename/$batch

The batch request must consists of a Content-Type header that specifies a content type of “multipart/mixed” and a “boundary” specification.

Content-Type:multipart/mixed boundary=batch

For reference please check the below screenshot.



Batch request body:

The body of a batch request is comprised of an ordered series of retrieve operations and/or change sets. Retrieve operations are generally Query or Read operations executed with the HTTP GET method.

When modify such operations, they are referred as “Change Sets” in OData batch processing terms. Change sets can consists of Create, Update or Delete operations executed using the POST, PUT and DELETE methods.

Handling of a Batch Request in Gateway

Retrieve and change set operations are handled differently by Gateway.

Retrieve operations:

Each retrieve operations such as a Query or Read operation within a $batch request will be transferred separately form gateway to the data provider application in the back-end system for processing.

Change Set Operations:

Every change set is to be treated as one Logical Unit of Work (LUW), all operations of a change set will be sent at once from gateway to the data provider application in the backend system for processing.

Result:

Results from all operations will be collected at the Gateway system and then sent as one HTTP response to the OData Consumer.

Batch Process: In $batch functionality delivers two additional methods to the /IWBEP/IF_MGW_APPL_SRV_RUNTIME data provider interface.

  • CHANGESET_BEGIN

  • CHANGESET_END


In SAP Gateway by default, only one operation per change set is allowed. If multiple operations are continued in the change set, the default implementation will throw an exception.

In Order to process multiple operations in a change set, the default implementation must be overwritten by the application using these methods (Changeset_begin and Changeset_end)

In SAP we don't have to write any additional logic to implement batch, just have to redefine the methods as shown in below.

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN  and

      /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGE SET_END

 

Create a Project and then right click on the Data Model folder and select import DDIC structure and give the entity type name as ..... and select the required properties for the entity type.

Then click on Generate Run time Objects. It displayed "Generate Objects Successfully", that time generated all classes automatically.

Right click on class ends with DPS_EXT and select go to ABAP workbench, then redefine the following methods.

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~ CHANGESET_BEGIN



/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END



Read Operation with BATCH:

In this below process I am getting two entity sets of data by using single request through Batch request.

URL: /sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/$batch

HEADER:

Authorization: SAP ID & PASSWORD

x-csrf-token:   Enter Token

Content-Type: multipart/mixed; boundary=batch

Request Body:

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET EmpDSet(EmpId='1') HTTP/1.1     “Read Operation based on Employee ID

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET EmpDSet HTTP/1.1                “Getting All Employees Data(Set Data)

--batch—



Create Operation with BATCH:

Example of executing a batch request containing multiple create operations.

URL: /sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/$batch

HEADER :

Authorization: SAP ID & PASSWORD

x-csrf-token:   Enter Token

Content-Type: multipart/mixed; boundary=batch

Request Body:

--batch
Content-Type: multipart/mixed; boundary=changeset

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

POST EmpDSet HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 588

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/EmpDSet('1')</id>
<title type="text">EmpDSet('1')</title>
<updated>2015-08-31T05:52:12Z</updated>
<category term="ZHK_BATCH_REQUEST1_SRV.EmpD" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="EmpDSet('1')" rel="self" title="EmpD"/>
<link href="EmpDSet('1')/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EmpPhotoSet" type="application/atom+xml;type=feed" title="EmpPhotoSet"/>
<link href="EmpDSet('1')/$links/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/EmpPhotoSet" type="application/xml" title="EmpPhotoSet"/>
<content type="application/xml">
<m:properties>
<d:EmpId>7</d:EmpId>
<d:Name>TEST7</d:Name>
<d:Address>KKD</d:Address>
<d:Salary>1234</d:Salary>
</m:properties>
</content>
</entry>

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

POST EmpDSet HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 588

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/EmpDSet('1')</id>
<title type="text">EmpDSet('1')</title>
<updated>2015-08-31T05:52:12Z</updated>
<category term="ZHK_BATCH_REQUEST1_SRV.EmpD" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="EmpDSet('1')" rel="self" title="EmpD"/>
<link href="EmpDSet('1')/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EmpPhotoSet" type="application/atom+xml;type=feed" title="EmpPhotoSet"/>
<link href="EmpDSet('1')/$links/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/EmpPhotoSet" type="application/xml" title="EmpPhotoSet"/>
<content type="application/xml">
<m:properties>
<d:EmpId>8</d:EmpId>
<d:Name>TEST8</d:Name>
<d:Address>KKD</d:Address>
<d:Salary>1234</d:Salary>
</m:properties>
</content>
</entry>

--changeset--
--batch--

Output Screen Shot:



 

Result in back-end:



Update Operation with BATCH:

Example of executing a batch request containing multiple Update operations (Change names).

URL: /sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/$batch

HEADER :

Authorization: SAP ID & PASSWORD

x-csrf-token:   Enter Token

Content-Type: multipart/mixed; boundary=batch

Before Update:




Response Body:

--batch
Content-Type: multipart/mixed; boundary=changeset

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

PUT EmpDSet('8') HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 588

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/EmpDSet('1')</id>
<title type="text">EmpDSet('1')</title>
<updated>2015-08-31T05:52:12Z</updated>
<category term="ZHK_BATCH_REQUEST1_SRV.EmpD" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="EmpDSet('1')" rel="self" title="EmpD"/>
<link href="EmpDSet('1')/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EmpPhotoSet" type="application/atom+xml;type=feed" title="EmpPhotoSet"/>
<link href="EmpDSet('1')/$links/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/EmpPhotoSet" type="application/xml" title="EmpPhotoSet"/>
<content type="application/xml">
<m:properties>
<d:EmpId>8</d:EmpId>
<d:Name>uPDATED</d:Name>
<d:Address>rjy</d:Address>
<d:Salary>56</d:Salary>
</m:properties>
</content>
</entry>

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

PUT EmpDSet('9') HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 588

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>http://sapserver.mouritech.in:8000/sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/EmpDSet('1')</id>
<title type="text">EmpDSet('1')</title>
<updated>2015-08-31T05:52:12Z</updated>
<category term="ZHK_BATCH_REQUEST1_SRV.EmpD" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="EmpDSet('1')" rel="self" title="EmpD"/>
<link href="EmpDSet('1')/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EmpPhotoSet" type="application/atom+xml;type=feed" title="EmpPhotoSet"/>
<link href="EmpDSet('1')/$links/EmpPhotoSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/EmpPhotoSet" type="application/xml" title="EmpPhotoSet"/>
<content type="application/xml">
<m:properties>
<d:EmpId>9</d:EmpId>
<d:Name>UPDATED</d:Name>
<d:Address>TEST</d:Address>
<d:Salary>78</d:Salary>
</m:properties>
</content>
</entry>

--changeset--
--batch--

 Output Screen Shot:





Delete Operation with BATCH:

URL: /sap/opu/odata/sap/ZHK_BATCH_REQUEST1_SRV/$batch

HEADER :

Authorization: SAP ID & PASSWORD

x-csrf-token:   Enter Token

Content-Type: multipart/mixed; boundary=batch

Before:



Response Body:

--batch
Content-Type: multipart/mixed; boundary=changeset

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

DELETE EmpDSet(EmpId='7') HTTP/1.1

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

DELETE EmpDSet(EmpId='8') HTTP/1.1

--changeset--
--batch--

Output Screen Shot:





Hope it's useful 🙂  Harikrishna

 

 
4 Comments
Labels in this area