BATCH Request in SAP GATEWAY
BATCH Request in SAP GATEWAY
BATCH Request in SAP GATEWAY
Manikandan Rajasekaran
May 6, 2018 12 minute read
Hello Guys,
I am from SAP Gateway team,this post will help you get a glimpse of what $batch request really means in
Odata .
How to get the $batch concept implemented in your existing Odata Service ?
How do I implement CHANGESET process to make the data modi cation process in sync with each other?
How to make read operations also in sync with one another?
Prerequisite
How to register the service and extract data relevant information out of it ?
Explained in layman terms , to make it easier in the beginning and technical in later part.
Batch processing -Enables multiple retrieval operation in a single HTTP request in parallel.
However, the CHANGESET request can be posted along with GET request but it will not be processed parallelly.
Example: If I have two GET request and one CHANGESET set request rst GET request will processed parallelly
(2) and then change set will be processed.
To activate the batch processing the below con guration needs to be activated in SPRO.
Maximum no -No of batch queries that can be executed in parallel.
It is always recommendable to give the no of parallel process keeping the system performance in time-Because
based on the number the existing work process will be allocated for processing the job.
Example: Say I have 3 Get Request , 2 Post Request, 1 Change request, 1 delete request.
For con guration of 3 as above depicted.
1st step: 3 Get Request
2nd step: 1 post request,
3rd step: 1 post request,
4th Step:1 Change request
5th Step: 1 delete request.
But this number of maximum parallel processing request will be voided if the available work process in system
is low for parallel processing.
But this con guration can be disabled for particular service if required with transaction
Transaction: /IWBEP/REG_SERVICE
Display->Con guration
Enable Deactivation from the below check box .
The below
Batch request:
The body of a batch request is made up of an ordered series of retrieve operations and/or 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, that is, a change set cannot contain a
change set.
The batch boundary in HTTP header –“ Content-Type “ speci ed in the GW client is valid only for retrieve
operations.
For Update/Delete/Create request the boundary needs to speci ed again the “Changeset” exclusively apart
from “Content Type” in HTTP header.
After GET, PUT, POST, DELETE statement before the input of “Batch” or “Changeset” statement line there
should be two-line space as depicted below, if not it will result in error.
GET Statement in line 5, batch close call in line 8.
1. Before the GET statement or POST/DELETE/PUT request we will always have the below headers by default
Content-Type: application/http
Content-Transfer-Encoding: binary
2. Within a batch request to segregate each request separately for every new action (GET/CHANGESET) we
have to use the pre x “Boundary value”
And again, within a “Changeset” to segregate each action we need to use boundary value de ned for
“Changeset” which is passed with begin of content type to segregate “Changeset”
SAP will process the operations such as CREATE/UPDATE/DELETE as it is in the same order, which is de ned
in the input time.
So it is business responsibility to take care of sequence in which batch “Changeset” calls would be de ned.
The response of a batch request will exactly correspond to the order of retrieval / change operation in the batch
request.
Each response includes a Content-Type header with a value of application/http, and a Content-Transfer-
Encoding MIME header with a value of binary.
We can use one or more Update/delete/insert operation within a “Changeset” but when you use such template
we need to make sure there is no “Commit work” statement within any one UPDATE/CREATE/DELETE entity.
If it exists, the system will dump the request and no further processing will happen.
Each Changeset process will be single LUW (logical unit of work) so ideally no Commit Work statement would
be required.
So why do I use batch processing in that why for Update/delete/create I must use Changeset?
This parallel query process will be executed only for Local and frontend system which has only one registered
backend system.
When you use Multi Origin Composition with multiple backend system , the parallel query process will not be
triggered each and every request will be processed separately.
Because in class /IWFND/CL_TRANSACTION_HANDLER under method SET_IS_MDC is set as abap_true.
The other way of calling batch request with multi origin request if you want the data to be retrieved from single
backend only we can use Origin option in the URI.
Example: /sap/opu/odata/SAP/ZRM_BATCH_LEARNING_SRV;o=GXX_000/$batch
This will enable parallelization if the required con guration in done in backend.
From SAP 740 SP09 Batch processing, performance has been improved by introducing new API for Changeset
processing in defer mode.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN,
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_PROCESS,
/IWBEP/IF_MGW_APPL_SRV_RUNTIMECHANGESET_END.
Each change set processing can also be improved if the data provider can handle the whole change set at once.
That means the provider must implement the new API for change set handling to process all change set
operations within the new API CHANGESET_PROCESS.
In this case a data provider must return the result of all operations back to the gateway framework.
The below di erence in call stack can be seen clearly.
When we intend to use DEFER mode its must to rede ne
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN of the service, this is where we need to set
CV_DEFER_MODE = ABAP_TRUE.
There is an option if you want to disable defer mode for certain Entity type, Operation Information so it will
follow normal process, instead of hitting CHANGESET_PROCESS.
CHANGESET_BEGIN method has importing parameter IT_OPERATION_INFO which has ENTITY_TYPE, ENTITY
SET, OPERATION_TYPE, CONTENT_ID, CONTENT_ID_REF elds which gives us a chance to decide if we want to
switch CV_DEFER_MODE on or o .
In simple the response structure for all the entities will be set together in case of DEFER Mode with changing
parameter table CT_CHANGESET_RESPONSE.
In the internal table, IT_CHANGESET_REQUEST we have a eld called ‘REQUEST_CONTEXT’ which bears entity
speci c details this must be down casted to a class ‘/IWBEP/IF_MGW_REQ_ENTITY_C’ method
‘GET_ENTITY_TYPE_NAME’ to have only Entity Type speci c information so that we can retrieve the Entity Type
and do the required action as per eld “OPERATION_TYPE”.
The eld “ENTRY_PROVIDER” in internal table has the data related to ‘Entity’. This eld has reference to
interface class ‘/IWBEP/IF_MGW_ENTRY_PROVIDER ‘the method ‘READ_ENTRY_DATA’ will get the data in
result structure as per entity structure dynamically.
The Changeset request-operation number should be set to eld Changeset response-operation number
structure because the operation number is a unique eld which maps to the output request order as per input
request order.
The best use for “Defer Mode” is for ‘CREATE’ request in case of $batch request, the use can be identi ed by
using a ‘CONTENT_ID’ and ‘CONTENT_ID_REF’ of ‘IT_CHANGESET_REQUEST’ parameter in
‘CHANGESET_PROCESS’.
If a hierarchical CREATE request is to be done, via batch processing in a single Changeset we can use this
‘CONTENT_ID’ concept.
Example: I have CHANGESET request where I must create ‘Sales Order Header’ entity ‘Sales Order Item’ entity.
In this case I either want to create both sales order header and item entity using the REQUEST information or
nothing at all.
In this case I can use CHANGESET_BEGIN and CHANGESET_PROCESS method to ensure my success.
The $BATCH navigation and framework expand works like non-batch process.
Frame work expand: This will expand both the principal entity and dependent entity in URI.
/sap/opu/odata/SAP/ZRM_BATCH_LEARNING_SRV/ZEMPLOYEE_DETAILSet(EmpId=’0000000004′)?
$expand=ZEMPLOYEE_SALARY
Navigation: This will expand only the depend entity based on key eld from principal entity.
Data-Provider Expand: This will work like Frame work expand but here we can alter the return entity structure
such that both the principal and dependent entity will be under one result structure (ER_ENTITY)
Attribute: MV_BATCH_DEFERRED_RESP_CREA
Sample implementation:
There are two main methods introduced in DPC generator class
/IWBEP/CL_MGW_ABS_DATA.
/IWBEP/IF_MGW_CORE_SRV_RUNTIME~BATCH_BEGIN
/IWBEP/IF_MGW_CORE_SRV_RUNTIME~BATCH_END
The logic in above BATCH_BEGIN method will check if there any request other than READ request .
If any other operations (Changeset) are present, the Deferred response creation mode will be disabled.
When a batch request is executed in case of Hubway and Gateway /IWBEP/CL_MGW_REMOTE_HANDLER will
be executed PROCESS_BATCH, in case of co-deployed /IWBEP/CL_MGW_LOCAL_HANDLER and same method
name PROCESS_BATCH.
The BATCH_BEGIN and BATCH_END if once implemented for a service, IT_REQUEST_HEADER will have value
‘SAP-IW-BATCH_DEF_RESP_CREA’.
The execution will be done based on no of operations (CRUD) operations in $batch request.
When processing the batch request rst check will be made for each if its if its ‘Query’ ( ‘GET’ )request or
CHANGESET (Modify operations) request.
Batch request will be processed in packets of information-so rst let’s see how query request will be
categorized further.
If only one request/Operation is present in the received BATCH request, it will be direct call for processing the
request without using batch parallelization concept.
The method PROCESS_REQUEST will process the request related to retrieval of data.
The export structure IT_REQUEST header will have the function code value.
Multiple GET request in $batch request: A check will be made if the service is enabled for ‘Parallelization’ with
below class and method
This will check in Global con guration /N/IWBEP/GLOBAL_CONFIG give maximum no. of parallel processing
request and if batch parallelization is enabled for service.
This will in turn check for that service if parallelization is disabled with the below class.
Class/Method: /IWBEP/CL_SCO_MANAGER=>IS_BATCH_PARAL_DISABLED
The class which will parallelize the incoming request with below class
Class/Method: /IWBEP/CL_MGW_QUERY_SCHEDULER=>PARALLELIZE_BATCH_QUERIES
Variable: LV_USE_DEFERRED_RESP_CREA
will be used if BATCH deferred response creation is used and implemented using BEGIN_BATCH method.
So, this way even for GET request we can use Deferred response either all or none (results)
Either display all or nothing even for GET requests similar to CHANGESET request.
Sample implementation:
Step1:
First to enable Batch deferred response mode enable it in MPC_EXT model features as explained previously.
Step2:
Rede ne method and set the ag as Deferred response creation as ABAP_TRUE.
Step3:
Introduce a new table attribute in DPC_EXT class.
This is to consolidate the response from GET ,EXPANDED (entity, entity set) and use it in BATCH_END class to
display the response in one time.
Example:
Step4: Now you must rede ne GET, EXPANDED (entity, entity set) as below for interface
/IWBEP/IF_MGW_APPL_SRV_RUNTIME.
This is required to consolidate the response and display in one shot in BATCH_END method.
Step5:
Consolidate and display the result as below in BATCH_END method.
Call Stack: With Deferred response creation enabled
Assigned tags
View more...
Related Questions
19 Comments
Syam Babu
Hi Mani,
Indeed Blog for GW developers on BATCH processing in nowadays.
Thanks,
Syam
Like (0)
Thanks Syam
Like (0)
Bilen Cekic
Is there any di erence between using batch or sending 2 parallel process from Ui5 side ? (for GET method).
Like (0)
Hi Bilen,
Conceptual wise both are same, but $batch request is Gateway framework induced to improve the response
time, by parallel processing of the READ requests and it gives you exibility to make synchronous read (Either
All the request should be processed successfully or none -with BATCH_BEGIN).
Like (0)
Alexander K
May 8, 2018 at 2:18 am
Thanks for blog, Manikandan.
I have creating ListReport with AnalyticalTable and user in ListReport setting panel selet some eld for
grouping
Can I get group elds( elds for group by) from parameter IO_TECH_REQUEST_CONTEXT of method
Z_*_DPC_EXT->Z_*_GET_ENTITYSET ?
For items, for groups and for totals. How can I nd out request for groups ?
Like (0)
1.MR_REQUEST will contain information related to the service, service version being called , by which user etc.
2.There is another parameter MO_MODEL which has complete details of Model related information -Entities,
association, mapping related information.
Like (0)
Alexander K
Thanks, Manikandan..
I am trying to nd in MO_MODEL.
Like (0)
Ashwin Bhaskar
May 11, 2018 at 2:19 am
Like (1)
Thanks
Like (0)
Alexander K
Can I change lter in parameter, IO_TECH_REQUEST_CONTEXT ? I need to clear one lter from odata service.
Like (0)
Yeah, you will have the Filter parameters in attribute MR_REQUEST.
Like (0)
Srinivas Rao
Hi Manikandan,
Thanks for the wonderful blog. I came across this blog while searching for possibility of using batch for GET
media streams in succession. Could you please let me know if that is possible and how to put each request in
batch for the GET stream ? Could you please explain this with an example ?
Like (0)
Hi Srinivas,
If my understanding is clear you want to retrieve the GET media request if the earlier one is success else it
should not ? If yes, you can search for Variable: LV_USE_DEFERRED_RESP_CREA in my blog which will give
insight with an example.
Like (0)
Rajesh Paruchuru
Hello Manikandan
some of the features explained in the blog are not available in our backend system but are available in our hub
system, for ex: the attribute “use_deferred_batch_resp_crea”
in /IWBEP/IF_MGW_APPL_TYPES=>TY_S_MODEL_FEATURES and the methods BATCH_BEGIN and
BATCH_END are not available in our back end system but are available in our hub system, with this kind of set
up, is there any way that we can implement deferred processing for GET only requests in batch mode?
Thanks
Rajesh
Like (0)
Like (0)
Asif Pasha Shaik
Dear Manikandan,
First of all thank you very much for sharing this post.
I have a question.
As I cannot use Commit statement in the function module, tables data for the document numbers are not
getting updated(Classi cations)
Example :
let say I have created 3 documents using function module, the only third value is getting updated at the end.
First two values are not getting updated because there is no COMMIT statement.
Thank you,
Like (1)
Prabaharan Asokan
Hi Manikandan Rajasekar
Thanks for the detailed sharing. I tried to experiment the same in the hub system which is connected to
backend system(CRM). But none of the $batch requests are getting executed in the system and receiving error
like ‘The server has not found any resource matching the Data Services Request URI’. I have put this question in
a new thread https://answers.sap.com/questions/12664759/weird-error-occurred-when-using-batch-
request.html Could you please shed some lights there ?
Prabaharan Asokan
Like (0)
Hitesh Arora
I am facing a strange issue when I am trying to include 3 changesets in one batch request.I get empty response
with response code 202 for 3 changesets in payload but same service with 2 changesets in payload works ne
and i get response in body. Am I missing something?
Like (0)
bala krishna
hi manikandan,
what will be the response if i have 3 change set requests in batch request if on of the change sets is failed.does
it fail all the change sets requests or that particular request gets failed?
Find us on
Trademark
Newsletter Support