Skip to Content

Hi All,


This blog is continuation of Simple Step-by-Step SAP-Gateway Service Guide ,

In above mentioned blog you’ll find all structures,tables,entities,entity sets,association and all basic operations(CRUD), Once you done with basic operations, When the requirement is as follows.. you can continue with this blog


Again this is for beginners,not for experts  😉


In some cases, business entity instances may logically belong together and need to be handled or processed together in the same logical unit of work. For example, on a sales order, an update of two or more related item entries could be required and must be processed together in a single request (all or none).


SAP Net Weaver Gateway can be used to process such scenarios with its capability to execute multiple operations in a single request.


Starting with SP 04, SAP Net Weaver Gateway provides the capability for client applications to batch multiple operations into a single HTTP request, allowing for a series of retrieve operations and/or modifying operations to be executed using one request.


O Data Batch requests allow the grouping of multiple operations into a single HTTP request payload. The components of a batch request, how the request is handled, and the components of the batch response have some significant differences from components and processing of a normal, single-operation OData request.


Batch Requests are submitted as a single HTTP POST request to the batch endpoint of a service.


Initial (Mandate) Steps :


     1. Go to transaction SEGW.

                    SEGW.PNG

     2. Expand  Project(which we created in above mentioned blog) -> Run time Artifacts.

     3. Right click on class ends with DPS_EXT.

     4. Select Go to ABAP Workbench.

               Workbench.png

     5. Go to edit mode.

                    Edit_Mode.PNG

     6. Redefine methods.

          a.       /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN.

          b.       /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END.

          Steps:

          a.       Click on /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN   and click redefine button.

          b.       Click on /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END      and click redefine button.

               redefine.PNG

           Only redefine and comment the code inside.

               Changeset_begin.PNG

               changeset_end.PNG

     7. Activate the service.

     8. Go to gateway client .(Please refer Simple Step-by-Step SAP-Gateway Service Guide ).

———————————————————————————————————


Batch Read :

     Steps:-


    1.  Check HTTP Method as POST.

    2.  Request URI -> Append /$batch at the end of the service name.

          ————/sap/ZEMPLOYEE_INFO_SRV/$batch

    3.  Click on Add Header.

         AddHeader.png

    4.  Enter Content-Type as

multipart/mixed; boundary=batch

    PopUpContentType.PNG

    5.     Paste the code in http request body.

   


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

 GET EmpDetailsSet('76')?$format=xml HTTP/1.1


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

 GET  EmpDetailsSet('77')?$format=xml HTTP/1.1


 --batch—














     6. Replace Entity Set and Values according to yours.

     Batch_Read_Request _final.PNG

    7. Click Execute.

        BatchReadSuccess.PNG

         You’ll get two records in HTTP Response body.

———————————————————————————————————


Batch Create :

    Steps :-


Follow steps 1- 4 of Batch Read.

    1.  Paste the code in http request body.



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


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


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


 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
 xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
 <atom:content type="application/xml">
 <m:properties>
 <d:DETAILS m:type="ZEMPLOYEE_INFO_SRV.Details">
 <d:Street1>Pai Layout</d:Street1>
 <d:Street2>Bangalore</d:Street2>
 <d:City>BANGALORE</d:City>
 <d:Country>INDIA</d:Country>
 </d:DETAILS>
 <d:EMP_ID>76</d:EMP_ID>
 <d:NAME>ARSHAD SHAIKH CREATE</d:NAME>
 <d:ADDRESS>BANGALORE</d:ADDRESS>
 <d:SALARY>100000000</d:SALARY>
 </m:properties>
 </atom:content>
 </atom:entry>


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


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


 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
 xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
 <atom:content type="application/xml">
 <m:properties>
 <d:DETAILS m:type="ZEMPLOYEE_INFO_SRV.Details">
 <d:Street1>Pai Layout</d:Street1>
 <d:Street2>KR Puram</d:Street2>
 <d:City>BANGALORE</d:City>
 <d:Country>INDIA</d:Country>
 </d:DETAILS>
 <d:EMP_ID>77</d:EMP_ID>
 <d:NAME>LK SONI CREATE</d:NAME>
 <d:ADDRESS>BANGALORE</d:ADDRESS>
 <d:SALARY>100000000</d:SALARY>
 </m:properties>
 </atom:content>
 </atom:entry>



 --changeset--
 --batch—















     6. Click Execute.

          BatchCreateRequest.PNG


          Your No of records maintained in above request body will be created.

———————————————————————————————————

Batch Update :

     Steps:-


Follow steps 1- 4 of Batch Read.

   5    . Paste the code in http request body.


    


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


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


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


 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
 xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
 <atom:content type="application/xml">
 <m:properties>
 <d:DETAILS m:type="ZEMPLOYEE_INFO_SRV.Details">
 <d:Street1>Pai Layout</d:Street1>
 <d:Street2>Bangalore</d:Street2>
 <d:City>BANGALORE</d:City>
 <d:Country>INDIA</d:Country>
 </d:DETAILS>
 <d:EMP_ID>76</d:EMP_ID>
 <d:NAME>ARSHAD SHAIKH UPDATE</d:NAME>
 <d:ADDRESS>BANGALORE</d:ADDRESS>
 <d:SALARY>100000000</d:SALARY>
 </m:properties>
 </atom:content>
 </atom:entry>


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


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


 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
 xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
 <atom:content type="application/xml">
 <m:properties>
 <d:DETAILS m:type="ZEMPLOYEE_INFO_SRV.Details">
 <d:Street1>Pai Layout</d:Street1>
 <d:Street2>KR Puram</d:Street2>
 <d:City>BANGALORE</d:City>
 <d:Country>INDIA</d:Country>
 </d:DETAILS>
 <d:EMP_ID>77</d:EMP_ID>
 <d:NAME>LK SONI UPDATE</d:NAME>
 <d:ADDRESS>BANGALORE</d:ADDRESS>
 <d:SALARY>100000000</d:SALARY>
 </m:properties>
 </atom:content>
 </atom:entry>



 --changeset--
 --batch—
















     6. Click Execute.

          BatchUpdateRequest.PNG

          Your No of records maintained in above request body will be updated.

———————————————————————————————————


Batch Delete :

     Steps:-


Follow steps 1- 4 of Batch Read.

    5    .Paste the code in http request body.



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

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

 DELETE EmpDetailsSet('76') HTTP/1.1


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

 DELETE EmpDetailsSet('77') HTTP/1.1


 --changeset--
 --batch—
















    6. Click Execute.

                         BatchDeleteRequest.PNG

         Your No of records maintained in above request body will be Deleted.


  Thanks,

Arshad Shaikh — 🙂

To report this post you need to login first.

29 Comments

You must be Logged on to comment or reply to a post.

  1. Michelle Kuiee

    Nice article!

    May I please ask – how long will the Gateway be supporting the ABAP Workbench?

    Are there other methods available today?

    If so, what are they?

    BR

    Michelle

    (0) 
    1. ARSHAD SHAIKH Post author

      Hi Michelle Kuiee,

           Yes,we have other methods to achieve, Not exactly like same as we do here..

           we can do it by creating web services(SICF).

      BR,

      Arshad

      (0) 
  2. Soumya R

    hi Arshad,

    I am trying to do batch operation for my EntitySet which is of media type. Can i implement the same way to send data of some 3 different data of 4000 characters each, through this create_Stream method. i got the error: “The specified HTTP method is not allowed for the resource identified by the Data Service Request URI”

    the request body:

    –batch 

    Content-Type: multipart/mixed; boundary=changeset 

         

    –changeset 

    Content-Type: application/http 

    Content-Transfer-Encoding: binary 

      

      

    POST DataSet HTTP/1.1 

    Content-Type: application/json

         {json data of hierarchy{{{{{values}}}}}

    –changeset 

    Content-Type: application/http 

    Content-Transfer-Encoding: binary

    POST DataSet HTTP/1.1 

    Content-Type: application/json

         {json data of hierarchy{{{{{values}}}}}

    –changeset 

    Content-Type: application/http 

    Content-Transfer-Encoding: binary

    POST DataSet HTTP/1.1 

    Content-Type: application/json

         {json data of hierarchy{{{{{values}}}}}

    –changeset– 

    –batch—

    the entityset is not a flat structure, its of 4 level hierarchy structures. so, how can i achieve this here?

    (0) 
      1. Soumya R

        So, even i create the usual entityset but it a 4 hierarchy structure, so it has created 10 complex types. So, how to achieve this for internal table of 4 level hierarchy and with table types in between. So, i need some guide here.

        thanks,

        Soumya

        (0) 
  3. German Mumma

    Hi, over all interesting document. But how would you perform the CREATE and READ operations from the front-end (Javascript). There you can’t just add the code snippet into the header.

    How would creating batch requests look like on the front-end using javascript/json?

    (0) 
  4. Long Zheng

    When I execute it will return error message:

    HTTP Receive failed: SSL handshake with <server name>:443 failed: SSSLERR_SERVER_CERT_MIS

    And I saw in your screenshot that there’s a X-CSRF-Token in header, how do you generate this token?

    (0) 
    1. Soumya R

      Initially you do a Get call for the service, you will get csrf token and you can use it for the post call. But, when you do batch in Gateway client, it will generate the csrf token.

      Best Regards,

      Soumya

      (0) 
  5. Nageswara Reddy Alla

    Hi Arshad,

    Very good document.

    I followed your document for Batch Read and getting below response.

    Status code:202 Accepted./

    But i am not getting the desired data.(My RFC is working fine )

    I tested my service in browser with normal read and it is working fine.

    But in BATCH READ i am not getting data.

    My BATCH READ file:

    Authorization: Basic R1dERU1POmFiY2QxMjM0

    –batch

      Content-Type: application/http

      Content-Transfer-Encoding: binary

       GET test_batchSet(‘0000004970’)?$format=xml HTTP/1.1

      –batch

      Content-Type: application/http

      Content-Transfer-Encoding: binary

       GET test_batchSet(‘0000004971’)?$format=xml HTTP/1.1

    My OUTPUT:

    Capture.JPG

    Please check and let me know what i am missing here.

    (0) 
    1. Ashwin Dutt R

      Hello Nages,

      It is because incorrect spacing between the operations inside the batch payload.

      So please correct that.

      Try this it should work.

      –batch

      Content-Type: application/http

      Content-Transfer-Encoding: binary

      Accept: application/json

      GET test_batchSet(‘0000004970’) HTTP/1.1

      –batch

      Content-Type: application/http

      Content-Transfer-Encoding: binary

      Accept: application/json

      GET test_batchSet(‘0000004971’) HTTP/1.1

      –batch–

      Regards,

      Ashwin

      (0) 
      1. Praveen Antony

        HI Ashwin,

        i have the same problem. My request is as below. I tried the spacing that you suggested but still dont get an output. Please see screen below. Appreciate your help!

        Thanks,

        Praveen

        Screen1.PNGScreen2.PNG

        (0) 
  6. Nageswara Reddy Alla

    Hi Ashwin,

    Thanks for your quick reply.

    Issue is solved and now i am getting desired output.

    Do you have any idea how we can test same scenario through browser.

    Please let me know if you know anything.

    Thanks

    Nagesh

    (0) 
      1. Nageswara Reddy Alla

        Hi Ashwin,

        How can we use Filter for sending multiple values.

        I am using like below and getting some type error.

        GET test_batchSet/?$filter=Vbeln eq ‘0000000001’ and Vbeln eq ‘0000004970’ HTTP/1.1

        Error:

        Invalid type for ‘$filter’ system query option. Expected type is ‘Edm.Boolean’

        (0) 
        1. Ashwin Dutt R

          Need to pass as below. Sample for your reference.

          GET EmployeeSet?$filter=Userid+eq+’00001’+and+Name+eq+’Ashwin’ HTTP/1.1

          Change yours accordingly.

          (0) 
          1. Nageswara Reddy Alla

            Hi Ashwin,

            Do you have any code example to check the same from sap ui5 application, if you have any thing please provide me.

            My requirement is to pass multiple records from UI5 to Gateway, how can we handle it with Batch processing.

            Thanks

            Nagesh

            (0) 
  7. Scott Zheng

    Hi Arshad,

    Every helpful documents. It is specific and clear for each point. The coding and screenshot part are really useful.

    Thank you so much. 🙂

    (0) 
  8. Evandro Gouveia Sales da Mata

    Hi everybody!!

    I Did this example, but I get an error when I execute the service:

    I tried to execute this batch operation:

    --batch
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    GET BaiaSet('UNIB')?$format=xml HTTP/1.1
    
    
    --batch
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    GET BaiaSet('UNPOL')?$format=xml HTTP/1.1
    
    --batch-

    Anyone had this problem?

    Thanks!!

    (0) 
  9. sivaraman Thiru

    Hi Arshad,

    I am not getting records in response…

    But getting status code 202


    SPAN {
    font-family: “Courier New”;
    font-size: 10pt;
    color: #000000;
    background: #FFFFFF;
    }
    .L1S32 {
    color: #7D9EC0;
    }
    .L1S33 {
    color: #009300;
    }
    –batch
    Content-Type: application/http
    Content-Transfer-Encoding: binary

    GET SorditemSet(‘Vbeln=’40000336‘,Posnr=’00010‘)?$format=xml HTTP/1.0

     –batch
     Content-Type: application/http
     Content-Transfer-Encoding: binary

     GET SorditemSet(‘Vbeln=‘40000336’,Posnr=‘00020’)?$format=xml HTTP/1.0

    –batch—

    I supposed to get item details of 10 and 20 ..

    but did not..

    Is there any issue in the coding ..

    Appreciate your help..

    (0) 
  10. Isaac Samuel Arancon

    Hi Everyone,

     

    i did the example above. But i am not getting any response. Status is 202 but the HTTP response is only  body <RESPONSE_BODY/>.

     

    Here is my request.

    –batch
    Content-Type: multipart/mixed; boundary=changeset
    –changeset
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    POST TestEntitySet HTTP/1.1
    Content-Type: application/atom+xml
    Content-Length: 588
    <?xml version=“1.0” encoding=“utf-8” standalone=“yes”?>
    <atom:entry xmlns:atom=“http://www.w3.org/2005/Atom” xmlns:d=“http://schemas.microsoft.com/ado/2007/08/dataservices” xmlns:m=“http://schemas.microsoft.com/ado/2007/08/dataservices/metadata”>
    <atom:content type=“application/xml”>
    <m:properties>
    <d:Zfirst>Second</d:Zfirst>
    <d:Zlast>Last</d:Zlast>
    <d:Zlevel>LVL10</d:Zlevel>
    <d:Zproj>PROJECT C</d:Zproj>
    </m:properties>
    </atom:content>
    </atom:entry>
    –changeset
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    POST TestEntitySet HTTP/1.1
    Content-Type: application/atom+xml
    Content-Length: 588
    <?xml version=“1.0” encoding=“utf-8” standalone=“yes”?>
    <atom:entry xmlns:atom=“http://www.w3.org/2005/Atom” xmlns:d=“http://schemas.microsoft.com/ado/2007/08/dataservices” xmlns:m=“http://schemas.microsoft.com/ado/2007/08/dataservices/metadata”>
    <atom:content type=“application/xml”>
    <m:properties>
    <d:Zfirst>Third</d:Zfirst>
    <d:Zlast>Last</d:Zlast>
    <d:Zlevel>LVL11</d:Zlevel>
    <d:Zproj>PROJECT B</d:Zproj>
    </m:properties>
    </atom:content>
    </atom:entry>
    –changeset–
    –batch–

     

    My custom table was also not updated. I also followed Ashwin’s suggestion regarding the spacing. Can help me?

     

    Thanks,

    Isaac

    (0) 
  11. Abhilash Pradhan

    Hello All,

     

    I have a scenario to update multiple records at the same time. Now i want to know what happens if some of the update fails ? Can we record and send it to the front end which records failed to update ?

    (0) 

Leave a Reply