Skip to Content
Technical Articles
Author's profile photo Uğur ilhan

Implementation of $Batch Processing in the Odata with CDS

Hello ABAPPERS,

Today I want to tell you a funny topic. The topic is ‘$Batch operation on the Gateway Services with CDS’. In Odata, generally we use deep entity method for implementing table or header-item relationship. But sometimes we do not want to implement deep structure methodology, we want to send data in just one request or try to do different thing.

This blogpost will explain details of Odata implimentation ’$Batch Processing’ step by step.

First topic is the reason of why we use $Batch method, Aim of the Odata Batch method is send several request in just one HTTP request. It helps us to use; get or put or post (etc.) methods in a parallel. This is very effective method for computing.

Secondly , We can start implimentation, create ZTABLE and CDS .

The main CDS View

@AbapCatalog.sqlViewName: 'ZUICDS001'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '$Batch Processing Example'
define view zui_cds_001
  as select from zui_t001
{
  key column0 as Column0,
      column1 as Column1,
      column2 as Column2
}

The ODATA CDS View Entity

The ODATA CDS View Entity
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'ODATA $Batch'
@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true
@OData.publish: true
@OData.entitySet.name: 'Odata_Test'
define view entity zui_odata_001
  as select from zui_cds_001
{
  key Column0,
      Column1,
      Column2
}

After that we can go to the SEGW Tcode to create Gateway Service

 

Then, We can just right click to DATA MODEL -> REFERENCE -> DATA SOURCE and write the our CDS View name.

And Generate the Our Service builder to create automatically our Model provider class and Data Provider Class.

 

!!! After definition, We will redefine this three methods to use $Batch Processing else we can get errors. To use Batch processing this step is very important!

In the Changeset_begin method,

To use all operations at the same time.

Then we will modify our codes into the /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_PROCESS method

    DATA : ls_change_request TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_request.
    DATA : ls_change_response TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_response.

    DATA: ls_entity TYPE zui_t001.
    DATA: lt_entity TYPE TABLE OF  zui_t001.

    LOOP AT it_changeset_request INTO ls_change_request WHERE operation_type EQ 'CE' ."To Create Operation
      ls_change_request-entry_provider->read_entry_data(
            IMPORTING
              es_data = ls_entity ).
      APPEND ls_entity TO lt_entity.
      CLEAR : ls_entity.
    ENDLOOP.
    IF lt_entity IS NOT INITIAL.
      INSERT zui_t001 FROM TABLE lt_entity.
      COMMIT WORK AND WAIT.
    ENDIF. 

Inside the operation type domain we can manipulate as we want.

Then , inside the changeset_end method we can just write commit work.

After that , we have to go to the Gateway to test and display the data .

Then we can go to the  /n/IWFND/MAINT_SERVICE  tcode to add  our service in the gateway.

Later that, we can test the get entity method. The important part is, we call get entity but in the $Batch process we choose POST Method to display. And the other important part is we must 2 blank row as you can see

 

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


GET zui_odata_001(Column0='1000') HTTP/1.1


--batch--       
//If you want to display json format you can also use;

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


GET zui_odata_001(Column0='1000') HTTP/1.1
sap-context-accept: header
Content-Type: application/json
Accept: application/json


--batch--

If you want to create new entries you can use HTTP Request like;

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

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

POST zui_odata_001 HTTP/1.1
sap-context-accept: header
Content-Type: application/json
Accept: application/json

     {
        "Column0" : "1111",
        "Column1" : "9999888877",
        "Column2" : "9999888877"
        }

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

POST zui_odata_001 HTTP/1.1
sap-context-accept: header
Content-Type: application/json
Accept: application/json

     {
        "Column0" : "2222",
        "Column1" : "9999888877",
        "Column2" : "9999888877"
        }

--changeset--

--batch--

You can use $Batch Processing for your own needs, don’t forget to check the awesome BLOG also you can watch the  amazing video for learning odata and Batch Process.

Thank you,

Don’t hesitate to ask a question and share your comments please 😊

Best Regards!

-Uğur İlhan

 

 

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo ABHAY KUMAR
      ABHAY KUMAR

      Nice blog , really helpful

      Author's profile photo Uğur ilhan
      Uğur ilhan
      Blog Post Author

      Thank you for your nice opinion!