Generic Usage of Read Requests
$batch is used to perform several service calls in one single HTTP request. $batch is defined on the service level, and the URI that is called is always the same: /sap/opu/odata/sap/<service_name>/$batch.
The multiple service calls are sent in a multipart MIME v1.0 message. Each operation needs to define its Content-Type.
Batch Request Format
At least two blank lines have to be used between two single operations in a batch request. Each single operation has two proceeding hyphens (--). The last operation has double hyphens as follows.
--batch_mybatch
...
//http request #1
...
--batch_mybatch
...
//http request #2
...
--batch_mybatch—
URL Parameter: $Batch Read Operation
$batch requests can be tested with the SAP Gateway client.
Batch Read Operation with Query Options
Since the URIs are secured in the HTTP body, the query options are also secured. Without using $batch, this can be a potential problem since URLs and the query options are not secured by the HTTPS protocol.
Change Sets for Change Requests
Multiple changes can be grouped in changesets. This way, logical units of work (LUW) can be used. For example, you can update two sales orders of one business partner.
ChangeSet Sample Code
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT BusinessPartners('0100000044') HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 10210
<entry ...>
...
</entry>
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT SalesOrders('0500000009') HTTP/1.1
Content-Type: application/atom+xml
Content-Length: 10210
<entry ...>
...
</entry>
--changeset--
--batch--
ChangeSet Methods Used for LUW Behavior
Methods CHANGESET_BEGIN and CHANGESET_END are used for LUW behavior. CHANGESET_BEGIN has the following characteristics:
CHANGESET_END has the following characteristics:
Deferred Processing ($batch at Once)
With SAP Gateway 2.0 SP9 a performance improvement for $batch changeset processing became available. The SAP Gateway framework is now able to handle the entire operation of changeset at once at the end of the changeset. For this to be possible, the data provider must implement the changeset handling API to process all changeset operations within one API call (method CHANGESET_PROCESS) and return the consolidated result of all operations to the SAP Gateway Framework. This handling is also called processing a changeset in defer mode or $batch at once.
When method CHANGESET_BEGIN is called a data provider can use the changing parameter CV_DEFER_MODE to inform the framework that it can process all changeset operations at once (deferred processing). Based on the list of entity set name, entity type name and action name, a data provider can dynamically set the exporting parameter mentioned above to inform the framework that it will process the current changeset at once or to reset this parameter to have single processing as usual. The default implementation is single processing. That means without any changes in a data provider each changeset operation will be processed one after another as usual.
If CV_DEFER_MODE is set, the framework will call the data provider using the new method CHANGESET_PROCESS