Hi Friends,

In this document I am trying to show case of $batch operation on Gateway services with multiple operations on multiple entitysets in a single call.

1.  Introduction

The OData batch concept is used to send the data of several requests in a single HTTP request from the client to the SAP Net Weaver Gateway server.  In real time scenario it will increases the mobile offline capabilities as well.

This document covers the following Batch operations.

            1. Batch operation on READ
            2. Batch operation on QUERY
            3. Batch operation on READ and QUERY with multiple entity set
            4. Batch operation on POST
            5. Batch operation on POST with multiple entity set
            6. Batch operation on PUT
            7. Batch operation on PUT with multiple entity set
            8. Batch operation on READ, QUERY, POST and PUT on multiple entity set


2. Batch operation Formation

2.1  Batch Request:

        • The body of a batch request is made up of an ordered series of retrieve operations and change sets.
        • A change set is an atomic unit of work that is made up of an unordered group of one or more of the insert, update or delete operations.
        • Change sets cannot contain retrieve requests and cannot be nested, i.e a change set cannot contain a change set

       2.2 Set the header name:


                   Set the content-type as show in the screen shot. Name the batch name in the boundary (here I used batch_123)/wp-content/uploads/2014/11/1_587824.jpg

Setting the Line Gaps in the request payload:         

        1. There should be min 2 lines of gap between content type and batch.
        2. GET operation should have one line up and two lines down gap.
        3. Batch should be closed.
        4. Batch can be implemented on POST operation only
        5. If you are using changeset means it should close

          The Sample URI which i am using for this project      URI: /sap/opu/odata/sap/ZBATCH_PUT_SRV/$batch


                                               Sample request.                                     

/wp-content/uploads/2014/11/2_587861.jpg

3. Batch operation on READ
/wp-content/uploads/2014/11/2_587861.jpg


    Execute the URI then you will get the successful status 202. Your response body will execute the query with

   the status code 200.


4. Batch operation on Query


                                                  /wp-content/uploads/2014/11/3_587863.jpg



5. Batch operation on READ and QUERY with multiple entity set

Here I am executing the batch operation with different Entity sets ( GET_SAVESEARCHSet and SET_SAVESEARCHSet )

/wp-content/uploads/2014/11/4_587867.jpg


6. Batch operation on POST

For the POST,PUT,PATCH and DELETE operations we have to use the changeset tag.


Sample payload.

          –batch_1234

          Content-Type: multipart/mixed; boundary=changeset_01234

          –changeset_01234

          Content-Type: application/http

          Content-Transfer-Encoding: binary

          POST SET_SAVESEARCHSet HTTP/1.1

          Content-Type: application/atom+xml

          Content-Length: 9999

          <Payload Body>

          –changeset_01234–

          –batch_1234–

7. Batch operation on POST with multiple entity set

Here I am using the two entity sets and  posting the data at a time.
Sample payload.



–batch_123

             Content-Type: multipart/mixed; boundary=changeset_1234

           –changeset_1234

           Content-Type: application/http

           Content-Transfer-Encoding: binary

           POST SET_SAVESEARCHSet HTTP/1.1

           Content-Type: application/atom+xml

           Content-Length: 9999

          <Payload Body1>

          –changeset_1234

          Content-Type: application/http

          Content-Transfer-Encoding: binary

          POST GET_SAVESEARCHSet HTTP/1.1

          Content-Type: application/atom+xml

          Content-Length: 9999

          <Payload Body2>

        –changeset_1234–

        –batch_123–

  8. Batch operation on PUT

             Now i am going to implement the PUT opearation.

sample payload


          –batch_123

          Content-Type: multipart/mixed; boundary=changeset_1234

          –changeset_1234

          Content-Type: application/http

          Content-Transfer-Encoding: binary

          PUT GET_SAVESEARCHSet(Reempid=’0000000250′,Rdistr=’1100′) HTTP/1.1

          Content-Type: application/atom+xml

          Content-Length: 9999

          <Payload Body>

          –changeset_1234–

          –batch_123–


9. Batch operation on PUT with multiple entity set

                Here I am doing PUT operation on two different entity sets.

       sample payload


          –batch_123

          Content-Type: multipart/mixed; boundary=changeset_1234

          –changeset_1234

          Content-Type: application/http

          Content-Transfer-Encoding: binary

          PUT GET_SAVESEARCHSet(Reempid=’0000000250′,Rdistr=’1100′) HTTP/1.1

          Content-Type: application/atom+xml

          Content-Length: 9999

          <Payload Body1>

          –changeset_1234

          Content-Type: application/http

          Content-Transfer-Encoding: binary

          PUT SET_SAVESEARCHSet(Reempid=’0000000250′,Rdistr=’1100′) HTTP/1.1

          Content-Type: application/atom+xml

          Content-Length: 9999

          <Payload Body2>

          –changeset_1234–

          –batch_123–

10. Batch operation on READ, QUERY, POST and PUT on multiple entity sets

Now I am going to implement all the operations (READ, QUERY, POST, and PUT) on multiple entity sets in a single call.

Note: Here PUT and POST operations all together come under Changeset begin and Changeset close

(i.e.  –changeset   …..< Body>  …  –changeset–)

    For sample payload Refer attachment file Batch_Multi


So Try it Happy Learning



Regards

Kiran Adhikarla

To report this post you need to login first.

6 Comments

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

  1. Vinayshree S

    Hello,

    I am trying to have 2 Put request in one batch call, Is there any specific methods i need to redfine for the same, other than /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_BEGIN.

    (0) 
  2. sivaraman Thiru

    Hi Kiran ,

    I ma trying $batch for creating entity using below payload …but I get status code 202 …not getting the result created ..even it is not stooping at create entity method


    SPAN {
    font-family: “Courier New”;
    font-size: 10pt;
    color: #000000;
    background: #FFFFFF;
    }
    .L1S32 {
    color: #7D9EC0;
    }
    -batch
    Content-Type: multipart/mixed; boundary=changeset

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

    POST SorditemSet 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:Erdat>20161115</d:Erdat>
    <d:Netwr>    94.35</d:Netwr>
    <d:Waerk>GBP</d:Waerk>
    <d:Kunnr>0000001066</d:Kunnr>
    <d:Posnr>000010</d:Posnr>
    <d:Matnr>90251178</d:Matnr>
    <d:Kwmeng>    1.000</d:Kwmeng>
    <d:Status>UNAU</d:Status>
    <d:Vbeln>40000336</d:Vbeln>
    </m:properties>
    </atom:content>
    </atom:entry>

    –changeset–
    –batch–-

    Appreciate your help..

    Kind Regards
    Sthiru

    (0) 

Leave a Reply