0% found this document useful (0 votes)
368 views84 pages

Odata

Uploaded by

karthick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
368 views84 pages

Odata

Uploaded by

karthick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

10/19/24, 11:40 AM

SAP Business Technology Platform


Generated on: 2024-10-19 11:40:48 GMT+0000

SAP Business Technology Platform (SAP BTP) | Cloud

PUBLIC

Original content: https://help.sap.com/docs/BTP/65de2977205c403bbc107264b8eccf4b?locale=en-


US&state=PRODUCTION&version=Cloud

Warning

This document has been generated from the SAP Help Portal and is an incomplete version of the official SAP product
documentation. The information included in custom documentation may not reflect the arrangement of topics in the SAP Help
Portal, and may be missing important aspects and/or correlations to other topics. For this reason, it is not for productive use.

For more information, please visit the https://help.sap.com/docs/disclaimer.

This is custom documentation. For more information, please visit the SAP Help Portal 1
10/19/24, 11:40 AM

OData Outbound Communication


The OData Client Proxy is the interface between the client (consumer of a service) and the service implementation (data
provisioning) in the OData service consumption in ABAP. This enables ABAP developers to create OData client coding to run OData
requests in your ABAP coding.

OData outbound connectivity enables you to consume OData services from other systems. To enable OData outbound
communication, there are two different stages that are performed by different roles:

Development Tasks
Development tasks are performed by developers. Development tasks are all tasks that are performed within ABAP development
tools for Eclipse, such as:

Creating a Communication Scenario

Creating an outbound service

For more information, see Enable OData Communication in Your ABAP Code.

Administrator Tasks

Administrator tasks are performed by administrators. Administrator tasks are all tasks that are performed in SAP Fiori launchpad,
such as:

Creating a communication system

Creating a communication arrangement

Creating communication users

For more information, see Set Up OData Communication.

Enable OData Communication in Your ABAP Code


Set Up OData Communication
To set up OData communication, use the corresponding communication management apps.
OData Client Proxies
There are several consumption types and OData versions for your OData Client Proxy configurations, depending on your
use case.
OData Client Proxy Overview
Get an overview of some of the most common OData Client Proxy tasks.
OData Client Proxy User Guide
See examples and steps for using the Data Client Proxy.
OData Requests
Learn how to use OData Requests.

Enable OData Communication in Your ABAP Code

This is custom documentation. For more information, please visit the SAP Help Portal 2
10/19/24, 11:40 AM

Feature Scope

Based on a service metadata file, you can genereate the ABAP code for an OData call by using a Service Consumption Model. See
Service Consumption Model as OData Consumer for more information.

Service Consumption Model as OData Consumer


A Service Consumption Model is the main requirement for consuming an OData service in the ABAP environment. To learn how to
create a Service Consumption Model with ABAP development tools for Eclipse (ADT), see Creating Service Consumption Model.

 Note
We recommend to create a new package for the Service Consumption Model. Generated objects are then created within this
package. This allows better organization and clarity.

A Service Consumption Model generates ABAP code from the service metadata file (EDMX file) of the OData service you want to
consume. For every operation (Create, Read, Read List, Update, and Delete), a code snippet is generated that indicates
how to perform the corresponding operation.

For more information on creating a Service Consumption Model, see Generating Proxies for Remote OData Service.

OData Communication via Communication Arrangements


OData outbound communication can be established using so-called communication arrangements.

Prerequisites
You've created a communication scenario as described in Defining a Communication Scenario Including Authorization
Values.

You have a service meta data file (EDMX file) for the service you want to consume.

You have created and activated a service consumption model (SRVC) of type OData. See Creating Service Consumption
Model for more information.

Procedure
1. Create a corresponding outbound service of type HTTP.

a. In your ABAP project, select the relevant package node in the Project Explorer.

Open the context menu and choose File New Other ABAP Repository Object Cloud Communication
Management Outbound Service Next to launch the creation wizard.

b. Select HTTP Service in the Service Type dropdown list.

c. Choose Next and select a transport request.

d. Optional: Go to your outbound service and enter the URL in the field Default Path Prefix.

e. Save the outbound service.

2. Add the newly created outbound service to a communication scenario. See Service Consumption via Communication
Arrangements for more information.

This is custom documentation. For more information, please visit the SAP Help Portal 3
10/19/24, 11:40 AM
3. Publish the communication scenario. The administrator can then create the required communication management objects
as described in Next Steps.

4. Call the OData service as described in the example. Copy the code snippet from the Overview tab in your SRVC and add the
comm_system_id and service_id parameters if necessary. According to your developed communication scenario, add
the following:

comm_scenario mandatory ID of the developed communication


scenario

comm_system_id optional ID of the configured communication


system

service_id optional ID of the developed outbound service

Example

The following code is generated by the SRVC for the create operation of the OData service Business User.

 Sample Code
DATA:
ls_business_data TYPE business_user=>tys_users,
lo_http_client TYPE REF TO if_web_http_client,
lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,
lo_request TYPE REF TO /iwbep/if_cp_request_create,
lo_response TYPE REF TO /iwbep/if_cp_response_create.

TRY.
* Create http client
DATA(lo_destination) = cl_http_destination_provider=>create_by_comm_arrangement(
* comm_scenario = '<Comm Scenario>'
* comm_system_id = '<Comm System Id>'
* service_id = '<Service Id>' ).
*lo_http_client = cl_web_http_client_manager=>create_by_http_destination( lo_destination ).
lo_client_proxy = /iwbep/cl_cp_factory_remote=>create_v4_remote_proxy(
EXPORTING
is_proxy_model_key = VALUE #( repository_id = 'DEFAULT'
proxy_model_id = 'BUSINESS_USER'
proxy_model_version = '0001' )
io_http_client = lo_http_client
iv_relative_service_root = '<service_root>' ).

ASSERT lo_http_client IS BOUND.

* Prepare business data


ls_business_data = VALUE #(
id = '11112222333344445555666677778888'
first_name = 'FirstName'
last_name = 'LastName'
phone = 'Phone'
email = 'Email'
address = 'Address' ).

" Navigate to the resource and create a request for the create operation
lo_request = lo_client_proxy->create_resource_for_entity_set( 'USERS' )->create_request_for_crea

" Set the business data for the created entity


lo_request->set_business_data( ls_business_data ).

" Execute the request


lo_response = lo_request->execute( ).

" Get the after image


*lo_response->get_business_data( IMPORTING es_business_data = ls_business_data ).

This is custom documentation. For more information, please visit the SAP Help Portal 4
10/19/24, 11:40 AM

CATCH /iwbep/cx_cp_remote INTO DATA(lx_remote).


" Handle remote Exception
" It contains details about the problems of your http(s) connection

CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).


" Handle Exception

CATCH cx_web_http_client_error INTO DATA(lx_web_http_client_error).


" Handle Exception
RAISE SHORTDUMP lx_web_http_client_error.

ENDTRY.

 Note
We recommend to retrieve the correct destination reference based on the communication scenario and a customer-defined
property as described in Service Consumption via Communication Arrangements.

Next Steps

To test your outbound call, you have to provide a configuration for the outbound service you want to call in your code.

Create a communication system and communication arrangement for the communication scenario in the Communication
Systems and Communication Arrangements apps and maintain the required data.

These tasks are performed by the administrator. For more information, see Set Up OData Communication.

Set Up OData Communication


To set up OData communication, use the corresponding communication management apps.

Context

The communication management is done by the administrator in SAP Fiori launchpad.

Procedure
1. Create a communication system. A communication system determines which target system is called and which
authentication methods are used. It also provides the user that is required to register at the target system. For more
information, see Communication Systems.

2. In the communication system, create an outbound communication user.

3. Create a communication arrangement. The communication arrangement is based on the communication scenario, that is
created by the developer in ABAP Development Tools for Eclipse. For more information, see How to Create a
Communication Arrangement.

Results

The communication management established a connection to the system from which you want to consume the OData service. You
can now perform the service call as described in OData Communication via Communication Arrangements

OData Client Proxies


This is custom documentation. For more information, please visit the SAP Help Portal 5
10/19/24, 11:40 AM
There are several consumption types and OData versions for your OData Client Proxy configurations, depending on your use case.

Consumption Types

The OData Client Proxy can be either local or remote.

Local Client Proxy

Use this Client Proxy for the consumption of an OData service on the current server without HTTP.

No HTTP overhead

The OData service is processed in the same application session. This allows integration testing, for example, including
stubbing.

Remote Client Proxy

Use this Client Proxy for the consumption of an OData service that is offered on a remote server.

OData Versions

OData Version 2 Client Proxy

Use this Client Proxy for the consumption of an OData Version 2 service.

OData Version 4 Client Proxy

Use this Client Proxy for the consumption of OData Version 4 services.

 Note
These configurations (the OData version and consumption type) depend on each other. For example, there is a local OData
Version 2 Client Proxy or a remote OData Version 4 Client Proxy, but not a local Client Proxy independent of the OData version.
The asynchronous Client Proxy is only available for remote consumption of OData Version 4 services.

Client Proxy

OData V2 OData V4

Local Remote Local Remote


Consumption Consumption Consumption Consumption

This is custom documentation. For more information, please visit the SAP Help Portal 6
10/19/24, 11:40 AM

Constraints
For Client Proxy known constraints, see SAP Note 2428114 - SAP Gateway Foundation SAP_GWFND OData Client Proxy - Known
Constraints .

Related Information
OData Request Terms
OData Outbound Communication

OData Client Proxy Overview


Get an overview of some of the most common OData Client Proxy tasks.

OData Client Proxy tasks include:

Client Proxy Instance Types


Create remote and local Client Proxy instances in OData Version 2 or Version 4.
Batch and Change Set Request Instance
Batch requests group multiple individual requests into a single HTTP request payload.
Deep Create Data Description Node
In OData Version 4, deep create requests create an entity that includes related entities.
Expand Node Instance
An expand node instance causes related entities to be included inline in the response.
Resource Instance
A resource instance represents a resource that is shared between applications and identified using URLs and defined in the
data model.
Filter Node Instance
A filter node instance filters and returns only the results that match the specified expressions.
Request Instance
A request instance describes the action you want to take on a resource.
Response Instance
A response instance includes information that the request returns.
Handling Exceptions
Handling exceptions when running Client Proxy-related coding.

Client Proxy Instance Types


Create remote and local Client Proxy instances in OData Version 2 or Version 4.

Client Proxy Versions

Client Proxy Version 2 and Version 4

Depending on the OData service you want to consume (Version 2 or Version 4 service), you'll create a Version 2 or Version 4 Client
Proxy instance. The underlying OData protocols differ between Version 2 and Version 4. You can't provide a version-agnostic Client
Proxy.

This is custom documentation. For more information, please visit the SAP Help Portal 7
10/19/24, 11:40 AM

Consumption Types
The decision of using a local or remote Client Proxy instance depends on the current use case.

Remote Client Proxy

A remote Client Proxy is used to consume an OData service offered on a remote server. If you want to create a remote Client Proxy
instance, the following is required:

A configured HTTP client instance

The relative service root pointing to the service document

Service Consumption model

If you want to create an HTTP client instance, see Enable HTTP Communication in Your ABAP Code.

Relative Service Root: The relative service root (combined with the HTTP destination) should point to the service document for
the OData service you want to consume. The service document is the top-level representation of an OData service. It lists the
entity sets, singletons, and service functions. It is available at http(s)://host/service/ base URL. You can access the
resources in the service document using a URL that is the concatenation of the base URL and the resource URL.

 Example
You want to consume the OData Version 4 service TEA_BUSI in version 2, which is part of the /IWBEP/TEA OData service
group and belongs to the service repository DEFAULT.

If the absolute URL to fetch the corresponding service document is


http://xyzia1b.rot.sap.corp:1234/sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0002/, the
relative service URL is /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0002/.

The remote Client Proxy needs a model object, which is the runtime representation of a model (compared to the model defined by
a model provider class (MPC) for an OData service). The Service Consumption Model is needed since we don't have (for example)
statically generated OData service specific proxies. Instead, we have one generic Client Proxy. To handle everything needed to
process a client request, the framework needs this information:

Name and definition of the EDM artifacts

The mapping from EDM to ABAP names (most importantly for properties)

ABAP data types

ABAP conversion exits

A Service Consumption Model defines the characteristics, properties, or parameters (such as, the number or the age of
employees).

For detailed examples on how to create a Service Consumption Model, see Service Consumption Model.

The OData Client Proxy supports SAP Passport to trace and monitor requests between different systems. To send SAP Passport
via the header sap-passport, you need to take one of the following actions:

Define the destination type 'H' (ABAP-ABAP communication) if you instantiated the HTTP client object with
CL_HTTP_CLIENT=>CREATE_BY_DESTINATION.

Set the attribute lo_http_client->PROPERTYTYPE_SEND_SAP_PASSPORT = lo_http_client->CO_ENABLED.

This is custom documentation. For more information, please visit the SAP Help Portal 8
10/19/24, 11:40 AM
Local Client Proxy

Use the local Client Proxy when a locally-deployed OData service is consumed. The local Client Proxy delegates a request to the
backend component of the corresponding Version 2 or Version 4 runtime without an HTTP overhead. The use case for this scenario
is to create Unit Tests, for example, when you want to build an integration test for your service data provider.

 Note
Since the local Client Proxy is designed for writing tests of your data provider, it skips several layers inside the SAP Gateway
Framework and directly calls the data provider class. This has following effects:

Certain tests that are usually executed during OData request processing are skipped.

For both Version 2 and Version 4, the business data received from the (local consumption) response is not re-converted
for outbound processing.

When using the Version 4 local client proxy, the business data you enter is not converted for inbound processing. The
data provider receives the data exactly how you entered in the request.

For creating a local Client Proxy instance, the service key is required. The service key includes the service repository id (for
example, DEFAULT), the service id (the ODATA service internal name), and the service id version (for example, 0003). You don't
need an HTTP client instance or a Service Consumption model.

Creating an Instance

You can create an instance of the Client Proxy using class cl_web_odata_client_factory, which provides these static
methods:

create_v2_local_proxy

create_v2_remote_proxy

create_v4_local_proxy

create_v4_remote_proxy

 Note
All returned instances are from type /iwbep/if_cp_client_proxy and offer the same methods. Certain methods are only
used by a specific Client Proxy (for example, a remote OData Version 4 proxy) and can raise an exception if the wrong Client
Proxy instance is called.

Functionality
The Client Proxy instance is the starting point for the OData service consumption with ABAP.

The Client Proxy instance provides a corresponding Resource Instance (for example, an action import or an entity set).

The Client Proxy instance provides methods for creating $batch and delta link requests (with certain delta link-centered
utility methods).

Examples

For examples on how to create and use Client Proxy instances, see Client Proxy Examples.

This is custom documentation. For more information, please visit the SAP Help Portal 9
10/19/24, 11:40 AM

Related Information
Resource Instance
OData Request as Batch Including Changesets
OData Request: Delta Link Query Option

Batch and Change Set Request Instance


Batch requests group multiple individual requests into a single HTTP request payload.

OData Version 4 Batch Requests


These individual requests can be included in a batch request:

Metadata

Data

Data Modification

Action Invocation

Function Invocation

Batch requests are submitted as a single HTTP POST request to the batch endpoint of a service at the $batch URL that is related
to the service root. Individual requests in a batch request are evaluated according to the same semantics used with an individual
request.

In the Multipart format, you can group data modification requests or action invocation requests as part of an atomic change set.
Operations outside the change set are executed sequentially. Operations in the change set are executed in any order.

 Note
In batch requests, operation is an individual request in the batch request payload. A change set request is a part of this type of
batch request.

Creating a Batch Request Instance


A batch request instance is created on the Client Proxy instance. It adds individual requests, executes the batch request, and
checks the execution. The batch request instance creates a change set request instance.

After you create a batch request instance, you can define the operations and add them to the batch request or to a change set. The
change set request instance is created directly on the batch request instance.

Related Information
OData Client Proxy Overview
OData Request as Batch Including Changesets

Deep Create Data Description Node


In OData Version 4, deep create requests create an entity that includes related entities.

This is custom documentation. For more information, please visit the SAP Help Portal 10
10/19/24, 11:40 AM

Overview

A deep create is also known as deep insert). In this example, you want to create a new customer and the first sales order
from this customer. You can first create the new customer and then the first sales order or you can use a deep create to create
both at the same time:

POST http://host/service/Customers

This request contains the following payload:

{ "CustomerName" : "James Bond",


"CustomerId" : 007,
"Customer_2_Salesorders" : {
"Object" : "Walther PPK",
"Category" : "Pistols"
}
}

You must use a Data Description node to describe the properties and inline navigations for deep business data for a request. The
Data Description node is necessary to describe the structure of your deep business data to the Client Proxy.

A Data Description node is always created on the corresponding create Request Instance.

 Note
In OData Version 2, complex properties can't have associations, such as navigation properties. You can only define navigation
properties in entity types. In OData Version 4, you can define navigation properties for a complex property.

Creating an Instance
A Data Description node instance is always created in the corresponding Request Instance.

Functionality

The Data Description node instances describe the payload for a deep create request to the Client Proxy. This is required to execute
any deep create request.

Example

For examples of how to create and work with Data Description nodes, see OData Request: Deep Create.

Related Information
OData Request: Deep Create

Expand Node Instance


An expand node instance causes related entities to be included inline in the response.

This is custom documentation. For more information, please visit the SAP Help Portal 11
10/19/24, 11:40 AM

Overview

When reading an entity with a GET request, related entities can also be requested using the $expand statement on a navigation
property. In this example, you want to read the data about customer “Posey” and the open sales orders for this customer (with
navigation property “Customer_2_Salesorders”). Here is an example of this OData request:

 Sample Code

GET http://host/service/Customers(‘Posey’)?$expand=Customer_2_Salesorders

Creating an Instance
In the Client Proxy Framework, an expand expression is described by an expand node instance. It is created directly in the
corresponding read request instance.

 Note
In OData Version 2, complex properties can't have associations, such as navigation properties. You can only define navigation
properties in entity types. In OData Version 4, you can define navigation properties for a complex property.

An expand node instance is always created in the corresponding Request Instance. These request types can be used to create an
expand node:

read entity

read entity list

read entity zero-to-one

Functionality
The expand node instances add an expand expression into the underlying read request. You can also set the selected properties for
each expand node. If not all properties of the expanded entity are returned, compare to GET
http://host/service/Customers(‘Posey’)?$expand=Customer_2_Salesorders($select=Date,Status).

Example

For examples of how to create and work with expand nodes, see $expand Option.

Related Information
Request Instance

Resource Instance
A resource instance represents a resource that is shared between applications and identified using URLs and defined in the data
model.

Overview

This is custom documentation. For more information, please visit the SAP Help Portal 12
10/19/24, 11:40 AM
In OData Version 4, a resource is anything in the model that can be addressed (an entity set, entity, property, or operation).

The OData instance creates REST-based data services that allows resources (identified using URLs and defined in an Entity Data
Model), to be published and edited by web clients with simple HTTP messages.

For a standard OData request, you must preovide a corresponding URL that points to a resource (for example,
entity_list(id=‘1‘) points to a specific resource:

 Sample Code

/sap/opu/odata/sap/srv/entity_list(id=‘1‘)/entity

 Note
The resources aren't OData protocol-specific (Version 2 or Version 4).

In the Client Proxy, you don't need to provide the URI. But you need to create an instance of the resource you want to access (for
example, a function or a single entity).

Creating an Instance

Depending on the resource type, the instance creation can vary. Some resources (for example, an entity set or action resources)
are created at the Client Proxy Instance Types. Other resources are created on another resource instance (for example, an entity
resource, created on the entity set resource). You can't call an entity resource without providing the corresponding entity set
resource.

Examples

GET/sap/opu/odata/sap/srv/teams The target resource is an entity set (teams). The resource instance is created
at the Client Proxy instance. For more information, see OData Request: Read Entity List.

GET /sap/opu/odata/sap/srv/order(customer=’Jane Doe’) The target resource is a single entity (Jane Doe),
so the resource instance is created at the parent resource instance (entity set order).

Resource Types

These resource types are available to users:

/IWBEP/IF_CP_RESOURCE_ACTION: Describes the resource of an action that is created on the Client Proxy instance
(for action imports) or on an entity (set) resource (for bound actions).

/IWBEP/IF_CP_RESOURCE_ENTITY: Describes the resource of a single entity that is created on an entity (set) resource.

/IWBEP/IF_CP_RESOURCE_ENTITY01: Describes the resource of an optional entity (the target entity of a zero-to-one
navigation) that is created on an entity resource.

/IWBEP/IF_CP_RESOURCE_FUNCTION: Describes the resource of a function that is created on the Client Proxy instance
(for function imports) or on an entity (set) resource (for bound functions).

/IWBEP/IF_CP_RESOURCE_LIST: Describes the resource of an entity set that is created on the Client Proxy instance or
an entity resource.

Functionality

This is custom documentation. For more information, please visit the SAP Help Portal 13
10/19/24, 11:40 AM
Resource instances are used to create requests (for example, an update request on an entity) or other resource instances (for
example, an action resource from an entity list resource). The options that a resource instance offers depends on the different
resource types.

Example
For examples of how to create and work with resources see Actions and Functions and OData Request: Using Navigation.

Related Information
OData Request: Read Entity List

Filter Node Instance


A filter node instance filters and returns only the results that match the specified expressions.

Overview

The $filter system query option restricts the set of items returned. It allows you to filter are source collection addressed by a
request URI. The expression specified with $filter is evaluated for each resource in the collection. Only items where the
expression is true are included in the response.

In this example, you want to read a collection of sales orders and get only the unpaid orders. Here's an example of the OData
request:

 Sample Code

GET http://host/service/SalesOrders?$filter=Payment eq ‘open’

A filter expression is described by a filter node instance that a filter factory instance creates and can be set into the Client Proxy
instance.

 Note
The filter nodes are not OData protocol-specific (Version 2 or Version 4).

Creating an Instance
A filter node instance is always created by a filter factory instance. You can create a filter factory instance in a read list request
instance.

Functionality

The main functionality of filter node instances is to create a filter expression for a read request on an entity list, which can be
integrated into the corresponding request to only show a subset of the complete result.

Example

For examples of how to create and work with filter nodes, see $filter Option.

This is custom documentation. For more information, please visit the SAP Help Portal 14
10/19/24, 11:40 AM

Related Information
OData Request: Read Entity

Request Instance
A request instance describes the action you want to take on a resource.

Overview
You can read or modify an OData Resource Instance by sending an OData request on this resource. This example reads all entities
for the entity set “teams”:

 Sample Code

GET /sap/opu/odata/sap/srv/teams

This example deletes the “order” entity of customer "Jane Doe":

 Sample Code

DELETE /sap/opu/odata/sap/srv/order(customer=’Jane Doe’)

A request instance describes the actual operation you want to perform on the corresponding resource. It includes all relevant
information (for example. the request body data for updating an entity) for the operation execution.

 Note
The requests are not OData protocol-specific (Version 2 or. Version 4).

Creating an Instance

Request instances are created on the resource instance the request will act on (for example, a request to update an entity is
created on the corresponding entity resource. The only exceptions are $batch/changeset requests (these can contain
requests acting on different resources), and delta link requests, that are both created on the Proxy Instance

Request Examples

/IWBEP/IF_CP_REQUEST_ACTION: A request to execute an ACTION (using action import or as a bound action.

/IWBEP/IF_CP_REQUEST_BATCH: A $batch request. It can be used to add other requests (for example. a DELETE
request) and execute them together as part of a $batch.

/IWBEP/IF_CP_REQUEST_CHANGESET: A request for a changeset. This request can be used to add other requests (for
example, CREATE request) into one changeset. The changeset request can only be executed as part of a $batch request
(for example, it must be added to a $batch request before executing the request).

/IWBEP/IF_CP_REQUEST_CREATE: A request to CREATE an entity.

/IWBEP/IF_CP_REQUEST_DELETE : A request to DELETE an entity

/IWBEP/IF_CP_REQUEST_FUNCTION: A request to execute a FUNCTION (using function import or as bound function.

/IWBEP/IF_CP_REQUEST_READ: A request to READ an entity.

This is custom documentation. For more information, please visit the SAP Help Portal 15
10/19/24, 11:40 AM
/IWBEP/IF_CP_REQUEST_READ_01: A request to READ an entity WITH a zero-to-one navigation.

/IWBEP/IF_CP_REQUEST_READ_DLTA: A request to READ the delta of a list of entities

/IWBEP/IF_CP_REQUEST_READ_LIST: A request to READ a list of entities.

/IWBEP/IF_CP_REQUEST_UPDATE: A request to UPDATE an entity.

/IWBEP/IF_CP_REQUEST_UPDATE_L : A request to UPDATE a list of entities.

Functionality

Request instances create an OData request and a corresponding Response Instance. The options a request instance offers depend
on the different request types.

Example
For examples of how to create and work with requests, see the OData Requests.

Response Instance
A response instance includes information that the request returns.

Overview
Most OData requests return a corresponding response body after the request is successful (an exception can be a successful
DELETE request with HTTP return code 204 with no content).

The Client Proxy response instance contains information returned by the request. You can use it to read all relevant response
information (for example. the entity business data).

 Note
The responses aren't OData protocol-specific (Version 2 or Version 4).

Creating an Instance
A response instance is always created by the corresponding request instance when a request is created.

Response Types

These response types are available:

/IWBEP/IF_CP_RESPONSE_ACTION: ACTION request response.

/IWBEP/IF_CP_RESPONSE_CREATE: CREATE request response.

/IWBEP/IF_CP_RESPONSE_DELETE: DELETE entity request response.

/IWBEP/IF_CP_RESPONSE_FUNCTION: FUNCTION request response.

/IWBEP/IF_CP_RESPONSE_READ: READ entity request response.

/IWBEP/IF_CP_RESPONSE_READ_01: READ entity (with zero-to-one navigation) request response.

This is custom documentation. For more information, please visit the SAP Help Portal 16
10/19/24, 11:40 AM
/IWBEP/IF_CP_RESPONSE_READ_LST: READ entity list request response.

/IWBEP/IF_CP_RESPONSE_UPDATE: UPDATE entity request response.

/IWBEP/IF_CP_RESPONSE_UPDATE_L: UPDATE entity list request response.

Functionality

Response instances return the response business data of a successful OData request execution. The options a response instance
offers depend on the different response types.

Example

For examples of how to create and work with responses, see the OData Requests.

Handling Exceptions
Handling exceptions when running Client Proxy-related coding.

Overview

There are two types of exceptions in the Client Proxy context:

/IWBEP/CX_GATEWAY: for client issues (for example, if the provided entity set name is unknown or if you try to fetch
business data from a response instance that doesn't have any response data).

/IWBEP/CX_CP_REMOTE: for server issues in remote scenarios (for example, the returned HTTP status code is not 2xx
(internal server errors [500] or missing authorizations [401]).

The remote server exception contains this information:

HTTP Status Code

HTTP Status Reason Message

OData Error Details

HTTP Client Error Details

HTTP error body

Content type

HTTP method

Handling Exceptions

Overview

For the remote client proxy: always catch both exceptions (/IWBEP/CX_GATEWAY and /IWBEP/CX_CP_REMOTE) separately and
implement corresponding exception handling.

For the local client proxy: catch /IWBEP/CX_GATEWAY. The remote exception isn't raised in the local scenario.

Example

This is custom documentation. For more information, please visit the SAP Help Portal 17
10/19/24, 11:40 AM
Use remote client proxy to consume an OData request. Include proper exception handling in your coding:

DATA: lv_http_status_code TYPE /iwbep/cx_gateway=>ty_http_status_code,


lv_http_status_message TYPE string,
lv_error_body TYPE string,
ls_odata_error TYPE /iwbep/cx_cp_remote=>ty_s_odata_error,
lv_client_error_text TYPE string,
lx_remote TYPE REF TO /iwbep/cx_cp_remote,
lx_gateway TYPE REF TO /iwbep/cx_gateway.

TRY.

“Your Client Proxy Coding


catch /iwbep/cx_cp_remote into lx_remote.
lv_http_status_code = lx_remote->http_status_code.
lv_http_status_message = lx_remote->http_status_message.
lv_error_body = lx_remote->http_error_body.
ls_odata_error = lx_remote->s_odata_error.

“Further error handling


catch /iwbep/cx_gateway into lx_gateway.
lv_client_error_text = lx_gateway->get_text( ).

“Further error handling


...

Steps

Step 1: Catch the remote exception and fetch the information on the exception (in addition to your own exception handling):

DATA: lv_http_status_code TYPE /iwbep/cx_gateway=>ty_http_status_code,


lv_http_status_message TYPE string,
lv_error_body TYPE string,
ls_odata_error TYPE /iwbep/cx_cp_remote=>ty_s_odata_error,
lx_remote TYPE REF TO /iwbep/cx_cp_remote.

CATCH /iwbep/cx_cp_remote INTO lx_remote.

lv_http_status_code = lx_remote->http_status_code.
lv_http_status_message = lx_remote->http_status_message.
lv_error_body = lx_remote->http_error_body.
ls_odata_error = lx_remote->s_odata_error.

“Further error handling


...

Step 2: Catch the gateway exception and fetch the corresponding error text (in addition to your own exception handling):

DATA: lx_gateway TYPE REF TO /iwbep/cx_gateway,


lv_client_error_text TYPE string.

CATCH /iwbep/cx_gateway INTO lx_gateway.


lv_client_error_text = lx_gateway->get_text( ).

“Further error handling


...

OData Client Proxy User Guide


See examples and steps for using the Data Client Proxy.

The OData Client Proxy User Guide includes:

This is custom documentation. For more information, please visit the SAP Help Portal 18
10/19/24, 11:40 AM

Client Proxy Examples


OData Proxy examples for OData Version 2 and Version 4 for local and remote client proxies.
Actions and Functions
Create an OData request to run an operation (an action or function) in the Client Proxy instance.

Related Information
OData Request Terms

Client Proxy Examples


OData Proxy examples for OData Version 2 and Version 4 for local and remote client proxies.

Overview

For information about the Client Proxy Instance, see Client Proxy Instance Types.

OData Version 2: Local Client Proxy


Overview

You can create a Client Proxy instance with class IWBEP/CL_CP_CLIENT_PROXY_FACTORY. It offers the static method
CREATE_V2_LOCAL_PROXY to create a local V2 Client Proxy instance. The service key parameters (service_id and
service_version) are required for the V2 OData service you want to consume. You can also specify if you want to write a
workload trace (you can later check in transaction STAD.

 Note
A workload trace is not written by default.

Example

Create a Client Proxy instance to consume the OData V2 service “ODATA_V2_TEST_SERVICE” in version number 1:

 Sample Code
DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy.
lo_client_proxy = cl_web_odata_client_factory=>create_v2_local_proxy( VALUE #( service_

OData Version 2: Remote Client Proxy

Overview

You can create a Client Proxy instance using class CL_WEB_ODATA_CLIENT_FACTORYT. It offers the static method
CREATE_V2_REMOTE_PROXY to create a remote V2 Client Proxy instance. The relative service root parameter
(service_definition_name) and a configured HTTP web client instance are required.

For more information about how to create a configured HTTP web client instance, see:

Enable HTTP Communication in your ABAP Code.


This is custom documentation. For more information, please visit the SAP Help Portal 19
10/19/24, 11:40 AM
HTTP Communication via Communication Arrangements.

The service definition is automatically generated when you create a Service Consumption Model.

The concatenated HTTP destination and the relative service root must point to the service document of the OData service.
Depending on your HTTP web client instance configuration, the way your relative service root looks can vary. In our example, we
assume that your HTTP destination doesn't have a path prefix (for example, doesn't point to a specific OData service). The relative
service root follows the general pattern /sap/opu/odata/<service_id>.

Example

Create a Client Proxy instance to consume the OData Version 2 service with the service definition
ODATA_V2_SERVICE_DEFINITION and the service id ODATA_V2_SERVICE.

 Sample Code

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_web_http_client TYPE REF TO if_web_http_client.

lo_client_proxy = cl_web_odata_client_factory=>create_v2_remote_proxy(
iv_service_definition_name = 'ODATA_V2_SERVICE_DEFINITION'
io_http_client = lo_web_http_client
iv_do_fetch_csrf_token = abap_true

iv_relative_service_root = '/sap/opu/odata/ODATA_V2_SERVICE' ).

 Note
In this example, the Client Proxy automatically fetches a cross-site request forgery (CSRF) token. It does a HEAD request to
fetch a CSRF token. This token is automatically reused for all requests executed with this Client Proxy instance. If you want to
change this behavior, set iv_do_fetch_csrf_token to abap_false.

OData Version 4: Local Client Proxy

Overview

Create a Client Proxy instance using class CL_WEB_ODATA_CLIENT_FACTORY. It offers the static method
CREATE_V4_LOCAL_PROXY to create a local Version 4 Client Proxy instance. The service key parameters (service_id,
relative_service_root, which is “SRVD, and the service_version) are required for the Version 4 OData service you want
to consume.

 Note
The local Version 4 Client Proxy can't be used to consume SAP OData services. You can only use it to consume your own
services.

Example

Create a Client Proxy instance to consume the OData Version 4 service ODATA_V4_TEST_SERVICE in version number 1:

 Sample Code

This is custom documentation. For more information, please visit the SAP Help Portal 20
10/19/24, 11:40 AM

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy.


lo_client_proxy = /cl_web_odata_client_factory=>create_v4_local_proxy( VALUE #( servic

OData Version 4: Remote Client Proxy

Overview

You can create a Client Proxy instance using class CL_WEB_ODATA_CLIENT_FACTORY. It offers the static method
CREATE_V4_REMOTE_PROXY to create a remote Version 4 Client Proxy instance. The relative service root parameters
(relative_service_root) definition and a configured HTTP web client instance are required.

The concatenated HTTP destination and the relative service root must point to the OData service document. Depending on your
HTTP web client instance configuration, the way your the relative service root looks can vary. In our example, we assume that your
HTTP destination does not contain a path prefix (i.e. does not point to a specific OData service); then, the relative service root
follows the general pattern /sap/opu/odata4/<service group id>/<repository id>/<service id>/<service
version>

Example

You want to create a Client Proxy instance to consume the OData Version 4 service with the service definition named
ODATA_V4_SERVICE_DEFINITION and the service id ODATA_V4_SERVICE (version 1), stored in service group ODATA_GROUP
and repository SRVD.

 Sample Code

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_web_http_client TYPE REF TO if_web_http_client.

lo_client_proxy = cl_web_odata_client_factory=>create_v4_remote_proxy(iv_service_defini

 Note
In this example, the Client Proxy automatically fetches a cross-site request forgery (CSRF) token. It does a HEAD request to
fetch a CSRF token. This token is automatically reused for all requests executed with this Client Proxy instance. If you want to
change this behavior, set iv_do_fetch_csrf_token to abap_false.

Constraints
The local Client Proxy (both Version 2 and Version 4) can't be used to consume SAP OData services.

Related Information
Service Consumption Model

Actions and Functions


This is custom documentation. For more information, please visit the SAP Help Portal 21
10/19/24, 11:40 AM
Create an OData request to run an operation (an action or function) in the Client Proxy instance.

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

Function

A Service Operation is represented by a Function Import and can return:

Primitive type

A single Entity-Type instance

A single Complex-Type instance

Collection of Complex-Type instances

Collection of Primitive types

The corresponding Function Import can have side effects and can be invoked by any pre-defined HTTP method.

OData Version 4
See OData Version 4.01. Part 1: Protocol .

Function

Functions are operations exposed by an OData service that don't have side effects. Functions must return data and can include
additional path segments. Functions are invoked using HTTP method GET.

Action

Actions are operation exposed by an OData service that can have side effects. Actions can return data but must not be composed
with additional path segments. Actions are invoked using HTTP method POST.

Operation

Functions and Actions are operations that can return data. Operations are either bound to a resource (for example, an entity type),
that makes them members of that instance type. Operations can also be unbound. Unbound operations are called as static
operations (using “action imports” or “function imports”) since a static (unbound) operation can't be called directly.

Example Requests

Version 4 Function Import

“GetEmployeeByManagerId” with non-binding parameter “ManagerId”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/GetEmployeeByManagerID(ManagerID='0001')

V4 Bound Action

“AcChangeTeamOfEmployee” with non-binding parameter “TeamId”

This is custom documentation. For more information, please visit the SAP Help Portal 22
10/19/24, 11:40 AM

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES('2')/SAP__self.AcChangeTeamOfE

Request body JSON:

{
"TeamID" : "TEAM_02"
}

Version 2 Function

“SetEmployeeSalary” with non-binding parameter “Id” and “Amount”

PUT /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/SetEmployeeSalary?Id='0001'&Amount=200

For examples and steps for Import and Bound operations, see:

Import Operation

Bound Operation

Constraints
If-Match header is only supported for remote consumption.

For function imports, the If-Match header is only supported for OData Version 2 requests.

Composable Functions are not supported.

$expand with operations is not supported.

$select is not supported for actions.

Return-Prefer header is not supported for actions.

System query options are not supported for Version 4 functions.

If the return type of a Version 2 function is an entity type and this entity type is used by more than one entity set, the
Version 2 request context only contains the (EDM) name of the first entity set with the underlying entity type. A precise
mapping is currently not possible. For remote consumption, this can be handled in the proxy model by setting the correct
entity set via method . /iwbep/if_v4_med_func_imp->set_entity_set_name

Import Operation
Overview

The starting point for an operation import is the corresponding operation resource that is created directly on the Client Proxy
instance. You can use the resource instance to create a request instance. You can use the response instance to retrieve the
response business data of the successfully executed request. This is fetched from the request instance.

 Note
In OData Version 2, all Operation requests must be created as Function Import requests.

This is custom documentation. For more information, please visit the SAP Help Portal 23
10/19/24, 11:40 AM
Example

To invoke the Version 2 function ‘PromoteEmployee’ with the non-binding (for example, input) parameters “Id=’0001’” and
“Level=2’:

POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/PromoteEmployee?Id='0001'&Level=2

TYPES:
BEGIN OF tys_parameter,
id TYPE /iwbep/tea_employee_id,
level TYPE i,
END OF tys_parameter.

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_function_resource TYPE REF TO /iwbep/if_cp_resource_function,
lo_function_request TYPE REF TO /iwbep/if_cp_request_function,
lo_function_response TYPE REF TO /iwbep/if_cp_response_function,
ls_parameter TYPE tys_parameter,
ls_busi_data TYPE /iwbep/tea_employee.

lo_function_resource = lo_client_proxy->create_resource_for_function( 'PROMOTE_EMPLOYEE').


ls_parameter = VALUE #( id = '0001' level = 2 ).

lo_function_resource->set_parameter( ls_parameter ).
lo_function_request = lo_function_resource->create_request( ).
lo_function_request->set_if_match( ‘2407’ ).

lo_function_response = lo_function_request->execute(/iwbep/if_cp_request_function=>gcs_http_metho
CHECK lo_function_response->has_business_data( ) = abap_true.

lo_function_response->get_business_data( IMPORTING ea_response_data = ls_busi_data ).

Steps

Step 1: Create the function resource “PROMOTE_EMPLOYEE” with the internal name of function “PromoteEmployee”:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,

lo_function_resource TYPE REF TO /iwbep/if_cp_resource_function.

lo_function_resource = lo_client_proxy->create_resource_for_function( 'PROMOTE_EMPLOYEE').

Step 2: Set the non-binding (for example. input) parameters on the function resource instance. You can do this on the function
resource, using method “SET_PARAMETER”:

TYPES:

BEGIN OF tys_parameter,

id TYPE /iwbep/tea_employee_id,

level TYPE i,

END OF tys_parameter.

DATA: ls_parameter TYPE tys_parameter.

ls_parameter = VALUE #(id = '0001' level = 2 ).

lo_function_resource->set_parameter( ls_parameter ).

Step 3: Create a function request in the function resource instance:

This is custom documentation. For more information, please visit the SAP Help Portal 24
10/19/24, 11:40 AM

DATA: lo_function_request TYPE REF TO /iwbep/if_cp_request_function.

lo_function_request = lo_function_resource->create_request( ).

Step 4: Select the corresponding HTTP method to invoke the function on the request object. In this example, it is POST. You must
do this in method SET_HTTP_METHOD or directly in the EXECUTE method. You can use the given constants in
GCS_HTTP_METHOD of interface /IWBEP/IF_CP_REQUEST_FUNCTION:

DATA: lo_function_response TYPE REF TO /iwbep/if_cp_response_function.

“Option one: Set http method on the request


lo_function_request->set_http_method( /iwbep/if_cp_request_function=>gcs_http_method-post ).

“Option two: Directly set the http method when executing the function
lo_function_response = lo_function_request->execute( /iwbep/if_cp_request_function=>gcs_http_meth

 Note
Setting the HTTP method is only allowed for OData Version 2 requests. In OData Version 4, functions must always be called with
GET and actions with POST. You don't need to set the HTTP method if the function is called with GET.

Step 5: Set the If-Match header to provide an ETag (if needed for this request). For example, if the corresponding request
header is if-match: W/"2407", the required input for SET_IF_MATCH is ‘2407':

lo_function_request->set_if_match( ‘2407’ ).

 Note
Only Version 2 remote consumption supports the If-Match header.

Step 6: Create the Function request:

DATA: lo_function_response TYPE REF TO /iwbep/if_cp_response_function.

lo_function_response = lo_function_request->execute( /iwbep/if_cp_request_function=>gcs_http_meth

Step 7: Check if the response object contains business data. This is especially useful for nullable operations, where the operation
might not return data (compare to HTTP return code 204 – No Content):

CHECK lo_function_response->has_business_data( ) = abap_true.

Step 8: Fetch the business data from the response object (if the corresponding function does return business data):

DATA: ls_busi_data TYPE /iwbep/tea_employee.

lo_function_response->get_business_data( IMPORTING ea_response_data = ls_busi_data ).

 Note

When using the Version 4 local client proxy, the business data you enter is not converted for inbound processing. The
data provider receives the data exactly how you entered it in the request. For both Version 2 and Version 4, the business
data received from the (local consumption) response is also not re-converted for outbound processing.

This is custom documentation. For more information, please visit the SAP Help Portal 25
10/19/24, 11:40 AM
Using an OData Version 4 action import works the same way. Use method CREATE_RESOURCE_FOR_ACTION instead
of CREATE_RESOURCE_FOR_FUNCTION.

Constraints
If-Match header is only supported for remote consumption.

For function imports, the If-Match header is only supported for OData Version 2 requests.

Composable Functions are not supported.

$expand with operations is not supported.

$select is not supported for actions.

Return-Prefer header is not supported for actions.

System query options are not supported for Version 4 functions.

If the return type of a Version 2 function is an entity type and this entity type is used by more than one entity set, the
Version 2 request context only contains the (EDM) name of the first entity set with the underlying entity type. A precise
mapping is currently not possible. For remote consumption, this can be handled in the proxy model by setting the correct
entity set via method . /iwbep/if_v4_med_func_imp->set_entity_set_name

Related Information
Actions and Functions
Bound Operation

Bound Operation

Bound Operation

Overview

The starting point for invoking a bound operation is the corresponding operation resource. This resource is not created directly at
the client proxy instance. It is created at the resource object the operation is bound to (for example, an entity resource or an entity
list resource). You can use the resource instance to create a request instance. You can use the response instance to retrieve the
response business data for the successfully executed request and can be fetched from the request instance.

 Note
Bound Operations are only available for OData Version 4 requests. All Operation related OData Version 2 requests must be
created as Function Import requests.

Example

Invoke the Version 4 bound action ‘IncreaseSalary’ with the non-binding (for example, input) parameters “NewSalary=5000”
and “Currency=’EUR’”. The action is bound to one entity of the entity set “Employees”:

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘0006’) /com.sap.gateway.defau

This is custom documentation. For more information, please visit the SAP Help Portal 26
10/19/24, 11:40 AM

WITH the request body

{
"NewSalary" : 5000, "Currency" : "EUR"
}

TYPES:

BEGIN OF tys_parameter,
new_salary TYPE i,
currency TYPE c LENGTH 3,
END OF tys_parameter,

BEGIN OF tys_key,
id TYPE /iwbep/v4_tea_employee_id,
END OF tys_key.

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_action_request TYPE REF TO /iwbep/if_cp_request_action,
lo_action_resource TYPE REF TO /iwbep/if_cp_resource_action,
lo_action_response TYPE REF TO /iwbep/if_cp_response_action,

lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,


ls_parameter TYPE tys_parameter,
ls_employee TYPE /iwbep/s_v4_tea_employee,
ls_key TYPE tys_key.

ls_key = VALUE #( id = ‘0006’ ).

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES')->navigate_with

lo_action_resource = lo_entity_resource->bind_action( 'INCREASE_SALARY' ).


lo_action_request = lo_action_resource->create_request( ).

ls_parameter = VALUE #( new_salary = 5000 currency = ‘eur’ ).

lo_action_request->set_parameter( ls_parameter ).
lo_action_request->set_if_match( '1234' ).
lo_action_response = lo_action_request->execute( ).

CHECK lo_action_response->has_business_data( ) = abap_true.


lo_action_response->get_business_data( IMPORTING ea_business_data = ls_employee ).

Steps

Step 1: Create the entity resource with the employee Id ‘0006’ of the entity set ‘Employees’ (with internal name ‘EMPLOYEES’):

TYPES:
BEGIN OF tys_key,
id TYPE /iwbep/v4_tea_employee_id,
END OF tys_key.

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,
ls_key TYPE tys_key.

ls_key = VALUE #( id = ‘0006’ ).

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES')->navigate_with

Step 2: Create the action resource instance on the instance the action is bound to (In this example, an entity of entity set
‘Employees’). ‘INCREASE_SALARY’ is the internal name of action ‘IncreaseSalary’:

DATA: lo_action_resource TYPE REF TO /iwbep/if_cp_resource_action.

This is custom documentation. For more information, please visit the SAP Help Portal 27
10/19/24, 11:40 AM
lo_action_resource = lo_entity_resource->bind_action( 'INCREASE_SALARY' ).

Step 3: Create an action request instance with the action resource:

DATA: lo_action_request TYPE REF TO /iwbep/if_cp_request_action.

lo_action_request = lo_action_resource->create_request( ).

Step 4: Set the non-binding (for example, input) parameters of the bound action on the action request:

TYPES:
BEGIN OF tys_parameter,
new_salary TYPE i,
currency TYPE c LENGTH 3,
END OF tys_parameter,

DATA: ls_parameter TYPE tys_parameter.

ls_parameter = VALUE #( new_salary = 5000 currency = ‘eur’ ).


lo_action_request->set_parameter( ls_parameter ).

Step 5: Set the If-Match header to provide an ETag (if needed for this request) on the action request. In this example, the
corresponding request header is if-match: W/"2407", the required input for SET_IF_MATCH is ‘2407’:

Lo_action_request->set_if_match( ‘2407’ )

 Note
Only remote consumption supports the If-Match header.

Step 6: Create the action request and get the action response instance:

DATA: lo_action_response TYPE REF TO /iwbep/if_cp_response_action.

lo_action_response = lo_action_request->execute( ).

Step 7: Check if the response object contains business data. This is especially useful for nullable operations, where the operation
might not return data (compare to HTTP return code 204 – No Content):

CHECK lo_action_response->has_business_data( ) = abap_true.

Step 8: Fetch the business data from the response object (if the corresponding action does return business data):

DATA: ls_employee TYPE /iwbep/s_v4_tea_employee.

lo_action_response->get_business_data( IMPORTING ea_business_data = ls_employee

 Note

When using the Version 4 local client proxy, the business data you enter isn't converted for inbound processing. The
data provider receives the exact data you entered in the request. The business data received from the (local
consumption) response is also not re-converted for outbound processing.

This is custom documentation. For more information, please visit the SAP Help Portal 28
10/19/24, 11:40 AM
Invoking an OData Version 4 bound function works the same way. Use method BIND_FUNCTION instead of
BIND_ACTION.

Constraints
If-Match header is only supported for remote consumption.

For function imports, the If-Match header is only supported for OData Version 2 requests.

Composable Functions are not supported.

$expand with operations is not supported.

$select is not supported for actions.

Return-Prefer header is not supported for actions.

System query options are not supported for Version 4 functions.

If the return type of a Version 2 function is an entity type and this entity type is used by more than one entity set, the
Version 2 request context only contains the (EDM) name of the first entity set with the underlying entity type. A precise
mapping is currently not possible. For remote consumption, this can be handled in the proxy model by setting the correct
entity set via method . /iwbep/if_v4_med_func_imp->set_entity_set_name

Related Information
Actions and Functions
Import Operation

OData Requests
Learn how to use OData Requests.

OData is a standardized protocol built over existing HTTP and REST protocols supporting CRUD (Create, Read, Update, Delete)
operations for creating and consuming data APIs. There are various types of requests (including Create, Update, Read, and
more) and system query options you can use for your particular use case.

OData Request Terms


An overview of some OData Request terminology.
OData Request as Batch Including Changesets
Create an $batch request, including changesets in the Client Proxy instance.
OData Request: Create Entity
Create an entity in the Client Proxy instance with insert entity request.
OData Request: Update Entity
Create an OData request to update an entity in the Client Proxy instance.
OData Request: Read Entity
To create an OData request to read an entity in the Client Proxy instance.
OData Request: Read Optional Entity
Create an OData request to read an optional entity in the Client Proxy instance.
OData Request: Delete Entity
Create an OData request to delete an entity in the Client Proxy instance.

This is custom documentation. For more information, please visit the SAP Help Portal 29
10/19/24, 11:40 AM
OData Request: Read Entity List
Create an OData request to read an entity list (entity collection) in the Client Proxy instance.
OData Request: Update Entity List
Create an OData request to update an entity list in the Client Proxy instance.
OData Request: Custom Query Option
Create an OData request using a custom query option that isn't one of the OData-defined system query options in the
Client Proxy instance.
OData Request: Deep Create
Create an OData request to execute a “deep create” (deep insert) in the Client Proxy instance.
OData Request: Delta Link Query Option
Create an OData request with $delta token query option in the Client Proxy instance.
OData Request: Using Navigation
Create an OData request using a navigation in the Client Proxy instance.
OData Request: Including a Nextlink
Create an OData request to read an entity list (entity collection) with a next link in the Client Proxy instance.
OData Request System Query Options
Learn how to use OData system query options. System query options include:

Related Information
OData Request Terms
OData Outbound Communication
OData Request System Query Options

OData Request Terms


An overview of some OData Request terminology.

Here's a list of some common terms you'll see when creating OData Requests.

Term Definition

Request OData Protocol enables clients to make requests and retrieve responses from the OData service.

Entity An entity is an instance of the EntityType element (for example, Customer or Employee) that is a structured record with a
key that uniquely identifies it.

Entity Key Each entity has a key that uniquely identifies it (for example, CustomerId or EmployeeId). The key is defined by a subset of
the entity type properties.

Entity An entity type is a collection or category that a particular entity belongs to.
Type

Entity Set An entity set is a group of all entities (for example, the EntitySet Customers is a set of Customer instances) for a particular
entity type at any point in time.

Property An entity type has one or more properties that define the entity type's structure. Each property has a name and one or more
values.

OData Request as Batch Including Changesets


This is custom documentation. For more information, please visit the SAP Help Portal 30
10/19/24, 11:40 AM
Create an $batch request, including changesets in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

A batch request is a single standard HTTP request that includes multiple application requests. Within that main HTTP request,
each of the parts contains a nested HTTP request. $batch request is useful to group multiple requests and sends a batch to the
data service in a single HTTP request. This section explains how a Batch Request works using ChangeSet syntax to logically group
requests into a single value in a batch.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

Batch requests group multiple individual requests into a single HTTP request payload. An individual request in a batch request is
one of the following:

Metadata request

Data request

Data modification request

Action invocation request

Function invocation request

Batch requests are sent as a single HTTP POST request to the batch endpoint of a service in the URL $batch that is relative to
the service root.

Individual requests in a batch request are evaluated according to the same semantics that are used when the request isn't part of a
batch request.

In the Multipart format, data modification or action invocation requests can be grouped as part of an atomic change set.
Operations outside the change set are executed sequentially. Operations within the change set are executed in any order.

Example Requests
Version 4

Get all entities of entity set “EMPLOYEES” with Id = ‘1’ and execute the Action Import “ChangeTeamBudgetByID”:

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/$batch

With request body

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

GET EMPLOYEES?$filter=ID%20eq%20%271%27 HTTP/1.1

--batch

This is custom documentation. For more information, please visit the SAP Help Portal 31
10/19/24, 11:40 AM
Content-Type: multipart/mixed;boundary=change_set_1

--change_set_1
Content-Type: application/http

Content-Transfer-Encoding: binary
Content-ID: 1

POST ChangeTeamBudgetByID HTTP/1.1


Content-Type: application/json
{
"TeamID" : "TEAM_01",
"Budget" : 700.00
}
--change_set_1--
--batch--

Version 2

Update two entities of entity set ‘Conversions’

POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/$batch

With request body

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

--changeset Content-Type: application/http


Content-Transfer-Encoding: binary

PUT Conversions(Id='0001') HTTP/1.1


Content-Type: application/json

{
"Id" : "1",
"price_1" : "-180.59",
"currency_1" : "EUR",
"price_2" : "1.706",
"currency_2" : "KWD",
"amount_1" : "1.1235",
"unit_1" : "D",
"amount_2" : "1.123",
"unit_2" : "CMS",
"oSQL_Where_Cl" : "",
"Is_Boolean" : true
}

--changeset--

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

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

PUT Conversions(Id='0001') HTTP/1.1


Content-Type: application/json

{
"Id" : "1",
"price_1" : "-000.00",
"currency_1" : "EUR",
"price_2" : "1.706",
"currency_2" : "KWD",
"amount_1" : "1.1235",
"unit_1" : "D",
"amount_2" : "1.123",

This is custom documentation. For more information, please visit the SAP Help Portal 32
10/19/24, 11:40 AM
"unit_2" : "CMS",
"oSQL_Where_Cl" : "",
"Is_Boolean" : true
}

--changeset--
--batch--

Batch with Changesets Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create a BATCH request on an
entity.

The starting point for a $batch request is the Client Proxy instance. It's possible to create a $batch request that you can use to
create a changeset request.

Example

Get all entities of entity set “Employees” and create a new entity in entity set “Teams”:

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/$batch

With request body

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

GET Employees HTTP/1.1

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

--change_set_1
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1

POST Teams HTTP/1.1


Content-Type: application/json

{
"Id" : "TEAM_04",
"Name" : "Test Team"
}

--change_set_1--
--batch--

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_read_request TYPE REF TO /iwbep/if_cp_request_read_list,
lo_read_response TYPE REF TO /iwbep/if_cp_response_read_lst,
lo_create_request TYPE REF TO /iwbep/if_cp_request_create,
lo_create_response TYPE REF TO /iwbep/if_cp_response_create,
lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch,

This is custom documentation. For more information, please visit the SAP Help Portal 33
10/19/24, 11:40 AM
lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset,
lt_employee TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee,ls_team
TYPE /iwbep/s_v4_tea_team.

lo_batch_request = lo_client_proxy->create_request_for_batch( ).

lo_changeset_request = lo_batch_request->create_request_for_changeset( ).
lo_changeset_request->add_request( lo_create_request ).

lo_batch_request->add_request( lo_read_request ).
lo_batch_request->add_request( lo_changeset_request ).
lo_batch_request->execute( ).

lo_batch_request->check_execution( ).
lo_changeset_request->check_excecution( ).
lo_read_request->check_execution( ).
lo_create_request->check_execution( ).

lo_read_response = lo_read_request->get_response( ).
lo_read_response->get_business_data( IMPORTING et_business_data = lt_employee ).

lo_create_response = lo_create_request->get_response( ).
lo_create_response->get_business_data( IMPORTING es_business_data = ls_team ).

Steps

Step 1: Create the $batch request at the client proxy instance:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch.

lo_batch_request = lo_client_proxy->create_request_for_batch( ).

Step 2: Create the changeset request using the $batch request instance:

DATA: lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch,


lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset.

lo_changeset_request = lo_batch_request->create_request_for_changeset( ).

Step 3: Add the CREATE request to the changeset request:

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset.

lo_changeset_request->add_request( lo_create_request ).

Step 4: Add both the READ and the change_set request into the $batch request. Run the $batch request:

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch,
lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset.

lo_batch_request->add_request( lo_read_request ).
lo_batch_request->add_request( lo_changeset_request ).
lo_batch_request->execute( ).

Step 5: Check that the four requests ran successfully. (optional):

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_create_request TYPE REF TO /iwbep/if_cp_request_create,
lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch,
This is custom documentation. For more information, please visit the SAP Help Portal 34
10/19/24, 11:40 AM
lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset.

lo_batch_request->check_execution( ).
lo_changeset_request->check_excecution( ).
lo_read_request->check_execution( ).
lo_create_request->check_execution( ).

 Note
If the exception didn't run successfully, CHECK_EXECUTION raises an exception. See Handling Exceptions for more
information.

Step 6: Get the READ response instance using the READ request instance and use it to fetch the corresponding business data:

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_read_response TYPE REF TO /iwbep/if_cp_response_read_lst, lt_employee
TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee.

lo_read_response = lo_read_request->get_response( ).
lo_read_response->get_business_data( IMPORTING et_business_data = lt_employee ).

Step 7: Get the CREATE response instance using the CREATE request instance and use it to fetch the corresponding business
data:

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_create_response TYPE REF TO /iwbep/if_cp_response_create, ls_team
TYPE /iwbep/s_v4_tea_team.

lo_create_response = lo_create_request->get_response( ).
lo_create_response->get_business_data( IMPORTING es_business_data = ls_team ).

 Note
When you're using the Version 4 local client proxy, the business data you receive from the local consumption response isn't
converted again for outbound processing.

Related Information
OData Request Terms

Content ID Referencing
Create an OData $batch request using Content ID Referencing in the Client Proxy instance.

OData Specification

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

Multipurpose Internet Mail Extensions (MIME) is set of extensions that redefines and expands support for various types of content
in email messages. Each MIME part that represents a request in a Change Set can include a Content-ID MIME header. See
[RFC2045 Section 7: Content-ID Header Field] for more information.

This is custom documentation. For more information, please visit the SAP Help Portal 35
10/19/24, 11:40 AM
If a MIME part defines an InsertEntity request and includes a Content-ID header, the new entity is defined by the
InsertEntity request. You can reference the new entity in future requests in the Change Set using the "$<Content-ID
value of your previous request>" token in place of a Resource Path that identifies the new resource. The token acts as
an alias for the Resource Path that identifies the new entity. Requests in different Change Sets can't reference one another, even if
they are in the same Batch.

OData Version 4

See OData Version 4.01. Part 1: Protocol .

Each request in a batch request can have an assigned request identifier. The request identifier:

is case-sensitive.

Must be unique within the batch request.

Must satisfy the rule request-id in [OData-ABNF] .

The body part contents that represent a change set must be a multipart document with one body part for each operation in the
change set. See [RFC2046] . Each body part that represents an operation in the change set must specify a Content-ID
header with a unique request identifier in the batch request.

Example Requests

Version 4

Create new entity in entity set “TEAMS” and update it afterwards:

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/$batch

With request body

--batch
content-type: multipart/mixed; boundary=changeset

--changeset
content-type: application/http
content-id: 111

POST TEAMS HTTP/1.1


Content-Type: application/json

{
"Name":"Unit Test Task Force",
"MANAGER_ID":"3",
"BudgetCurrency":"JPY",
"Budget":111100
}

--changeset
content-type: application/http
content-id: 222

PATCH $111 HTTP/1.1


Content-Type: application/json

{
"MEMBER_COUNT":66
}

--changeset--

This is custom documentation. For more information, please visit the SAP Help Portal 36
10/19/24, 11:40 AM
--batch—

Version 2

Create a new entity in entity set “Decimals”, then read it:

POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/$batch

With request body

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

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

POST Decimals HTTP/1.1


Content-Type: application/json
Accept: application/json
Content-Id: 1

{
"Id" : 1,
"Name" : "Decimal 10",
"Decimal1" : "1.1000000000"
}

--changeset---

--batch

Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET $1?$format=json HTTP/1.1

--batch--

Create a $batch request using Content ID Referencing

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create an OData $batch
request using Content ID Referencing.

The starting point for a using Content ID Referencing is a create request instance and create an entity resource with a Content ID
reference.

Example

Create a new entity in entity set “Teams”, then update the member count:

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/$batch

With request body


This is custom documentation. For more information, please visit the SAP Help Portal 37
10/19/24, 11:40 AM

--batch
content-type: multipart/mixed; boundary=changeset

--changeset
content-type: application/http
content-id: 111

POST Teams HTTP/1.1


Content-Type: application/json

{
"Name":"Unit Test Task Force"
}
--changeset
content-type: application/http
content-id: 222

PATCH $111 HTTP/1.1


Content-Type: application/json

{
"MemberCount":42
}

--changeset--
--batch--

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch,
lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset,
lo_update_request TYPE REF TO /iwbep/if_cp_request_update,
lo_entity_resource_w_cir TYPE REF TO /iwbep/if_cp_resource_entity,

ls_patch_data TYPE /iwbep/s_v4_tea_team.

lo_entity_resource_w_cir = lo_create_request->create_res_w_content_id_ref( ).
lo_update_request = lo_entity_resource_w_cir->create_request_for_update( /iwbep/if_
ls_patch_data = VALUE #( member_count = 42 ).
lo_update_request->set_business_data( is_business_data = ls_patch_data

It_provided_property = VALUE #( ( `MEMBER_COUNT` ) ) ).

lo_changeset_request->add_request( lo_create_request ).
lo_changeset_request->add_request( lo_update_request ).
lo_batch_request->add_request( lo_changeset_request ).
lo_batch_request->execute( ).

Steps

Step 1: Create the entity resource with a Content ID reference in the create request instance:

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_entity_resource_w_cir TYPE REF TO /iwbep/if_cp_resource_entity.
lo_entity_resource_w_cir = lo_create_request->create_res_w_content_id_ref( ).

Step 2: Create the update request instance at the entity resource instance:

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_update,


lo_entity_resource_w_cir TYPE REF TO /iwbep/if_cp_resource_entity.
lo_update_request = lo_entity_resource_w_cir->create_request_for_update( /iwbep/if

Step 3: Define the corresponding update data and set it into the update request:

This is custom documentation. For more information, please visit the SAP Help Portal 38
10/19/24, 11:40 AM

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_update,


ls_patch_data TYPE /iwbep/s_v4_tea_team.
ls_patch_data = value #( member_count = 42 ).
lo_update_request->set_business_data( is_business_data = ls_patch_data

It_provided_property = VALUE #( ( `MEMBER_COUNT` ) ) ).

Step 4: Add the CREATE and UPDATE requests into the changeset request. Then add the changeset request into the $batch
request:

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch,
lo_changeset_request TYPE REF TO /iwbep/if_cp_request_changeset,
lo_update_request TYPE REF TO /iwbep/if_cp_request_update.

lo_changeset_request->add_request( lo_create_request ).
lo_changeset_request->add_request( lo_update_request ).
lo_batch_request->add_request( lo_changeset_request ).

Step 5: Run the $batch request:

DATA: lo_batch_request TYPE REF TO /iwbep/if_cp_request_batch.


lo_batch_request->execute( ).

Constraints

You can't use Content ID Referencing with navigation (for example, POST $1/NavigationProperty).

Related Information
Request Instance
Resource Instance
OData Request as Batch Including Changesets

OData Request: Create Entity


Create an entity in the Client Proxy instance with insert entity request.

OData Specification

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

The InsertEntity request enables a new EntityType instance with new related entities you add to an EntitySet.

OData Version 4

See OData Version 4.01. Part 1: Protocol .

To create an entity in a collection, the client sends a POST request to the collection's URL. The POST body MUST contain a single
valid entity representation.

This is custom documentation. For more information, please visit the SAP Help Portal 39
10/19/24, 11:40 AM

Example Requests

Version 4

Create the employee with id ‘007’ in the entity set “Employees”

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees

With request body

{
"Id" : "007",
"Name" : "James Bond",
"Gun" : "Walther PPK",
"Car" : "Aston Martin DB5"
}

Version 2

Create the employee with id ‘007’ in the entity set “Employees”

POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees

With request body

{
"Id" : "007",
"Name" : "James Bond",
"Gun" : "Walther PPK",
"Car" : "Aston Martin DB5"
}

Create Entity Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create a CREATE request on
an entity..

The starting point for a POST request on an entity list is the Client Proxy instance. It's possible to create an entity list resource,
which can then be used to create a create request.

Running the create request provides the create response instance, which can return the business data for the CREATE entity
request.

Example

Create the employee with key id = '007 'of the Version 4 entity set ‘Employees':

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees

This is custom documentation. For more information, please visit the SAP Help Portal 40
10/19/24, 11:40 AM
With request body

{
"Id" : "007",
"Name" : "James Bond",
"Age" : 38,
"Entrydate" : "1962-10-05",
"ManagerId" : "001",
"RoomId" : "1",
"TeamId" : "TEAM_BRITANIA",
"IsManager" : false,
"Status" : "Available"
}

TYPES: BEGIN OF tys_entity_data,


Id TYPE i,
Name TYPE string,
age TYPE i,
entry_date TYPE dats,
manager_id TYPE i,
room_id TYPE i,
team_id TYPE string,
is_manager TYPE abap_bool,
status TYPE string,
END OF tys_entity_data.

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_create_request TYPE REF TO /iwbep/if_cp_request_create,
lo_create_response TYPE REF TO /iwbep/if_cp_response_create,
lo_entity_list_resource TYPE REF TO /iwbep/if_cp_resource_list,
ls_entity_data TYPE tys_entity_data, ls_employee
TYPE /iwbep/s_v4_tea_employee.

lo_entity_list_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOY


lo_create_request = lo_entity_list_resource->create_request_for_create( ).
ls_entity_data = VALUE #( id = 007
name = ‘James Bond’
age = 38
entry_date = ‘19621005’
manager_id = 001
room_id = 1
team_id = ‘team_britania’
is_manager = abap_false
status = ‘Available’ ).

lo_create_request->set_business_data( is_business_data = ls_entity_data


It_provided_property = VALUE #( ( |ID| )
( |NAME| )
( |AGE| )
( |ENTRY_DATE| )
( |MANAGER_ID| )
( |ROOM_ID| )
( |TEAM_ID| )
( |IS_MANAGER| )
( |STATUS| ) ).

lo_create_response = lo_create_request->execute( ).
lo_create_response->get_business_data( IMPORTING es_business_data = ls_employee ).

Steps

Step 1: Create the entity list resource for entity set ‘Employees’ (with internal name ‘EMPLOYEES’'):

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_entity_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

This is custom documentation. For more information, please visit the SAP Help Portal 41
10/19/24, 11:40 AM

lo_entity_list_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOY

Step 2: Run the create request instance on the entity list resource.

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_create,


lo_entity_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

lo_create_request = lo_entity_list_resource->create_request_for_create( ).

Step 3: Set the business data for your create request. In our example, the create request properties are:

Properties Internal Names

Id ID

Name NAME

Age AGE

EntryDate ENTRY_DATE

ManagerId MANAGER_ID

RoomId ROOM_ID

TeamId TEAM_ID

Status STATUS

IsManager IS_MANAGER

Define the values and set the business data into the create request:

TYPES: BEGIN OF tys_entity_data,


Id TYPE i,
Name TYPE string,
age TYPE i,
entry_date TYPE dats,
manager_id TYPE i,
room_id TYPE i,
team_id TYPE string,
is_manager TYPE abap_bool,
status TYPE string,
END OF tys_entity_data.

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_create,


ls_entity_data TYPE tys_entity_data,
ls_employee TYPE /iwbep/s_v4_tea_employee.

ls_entity_data = VALUE #( id = 007


name = ‘James Bond’
age = 38
entry_date = ‘19621005’
manager_id = 001
room_id = 1
team_id = ‘team_britania’
is_manager = abap_false
status = ‘Available’ ).

lo_create_request->set_business_data( is_business_data = ls_entity_data


it_provided_property = VALUE #( ( |ID| )
( |NAME| )
( |AGE| )

This is custom documentation. For more information, please visit the SAP Help Portal 42
10/19/24, 11:40 AM
( |ENTRY_DATE| )
( |MANAGER_ID| )
( |ROOM_ID| )
( |TEAM_ID| )
( |IS_MANAGER| )
( |STATUS| ) ).

 Note
(Optional) Provide the properties when calling SET_BUSINESS_DATA. If you provide properties, only the properties you set are
considered. If you don't provide properties, all properties are considered for the CREATE request.

 Note
If the entity has value control or VCS properties, these properties should also be part of the provided data container
(ls_entity_data in this example). If the value control/VCS properties are not provided, the behavior (for example:
conversion exits) is undefined and can cause unexpected side-effects.

Step 4: Run the create request and get the create response instance:

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_create,


lo_update_response TYPE REF TO /iwbep/if_cp_response_create.

lo_create_response = lo_create_request->execute( ).

Step 5: You fetch the business data from the response object:

DATA: lo_update_response TYPE REF TO /iwbep/if_cp_response_create,ls_employee


TYPE /iwbep/s_v4_tea_employee.

lo_create_response->get_business_data( IMPORTING es_business_data = ls_employee )

 Note
When you're using the Version 4 local client proxy, the business data you receive from the local consumption response isn't
converted again for outbound processing.

Related Information
OData Request Terms

OData Request: Update Entity


Create an OData request to update an entity in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

An UpdateEntity Request is used by a client to update an existing AtomPub Entry Resource, as specified in RFC5023 , that
maps to an EntityType instance in the abstract data model.

This is custom documentation. For more information, please visit the SAP Help Portal 43
10/19/24, 11:40 AM
OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

To update an individual entity, the client makes a PATCH or PUT request to a URL that identifies the entity. Services can be
restricted to only request updates addressing the edit URL of the entity.

Example Requests

Version 4

Update the employee with id ‘007’ of entity set “Employees

PATCH /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)

With request body

{
"Car" : "Aston Martin DB5"
}

Version 2

Update the employee with id ‘007’ of entity set “Employees”:

PUT /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees(‘007’)

With request body

{ "Id" : "007",
"Name" : "James Bond",
"Gun" : "Walther PPK",
"Car" : "Aston Martin DB5"
}

Update Entity Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create a UPDATE request on
an entity.

The starting point for a PUT/PATCH entity request is the Client Proxy instance. You can create an entity resource based on
an entity list resource, and use it to create an update request.

Running the update request provides the update response, which can return the business data of the UPDATE entity request.

Example

Update the employee with key “id = ‘007'” of the Version 4 entity set ‘Employees':

This is custom documentation. For more information, please visit the SAP Help Portal 44
10/19/24, 11:40 AM

PATCH /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)

With request body

{
"Age" : 38,
"IsManager" : true,
"Status" : "Available"
}

TYPES: BEGIN OF tys_patch_data,


types: BEGIN OF tys_patch_data,
age TYPE i,
is_manager TYPE abap_bool,
status TYPE string,
END OF tys_patch_data.

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_update_request TYPE REF TO /iwbep/if_cp_request_update,
lo_update_response TYPE REF TO /iwbep/if_cp_response_update,
lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,
ls_patch_data TYPE tys_patch_data,
ls_employee TYPE /iwbep/s_v4_tea_employee.

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES


lo_update_request = lo_entity_resource->create_request_for_update( /iwbep/if_cp_r

ls_patch_data = VALUE #( age = 38


is_manager = abap_true
status = ‘Available’ ).

lo_update_request->set_business_data( is_business_data = ls_patch_data


it_provided_property = VALUE #( ( |AGE| )
( |IS_MANAGER| )
( |STATUS| ) ).

lo_update_request->set_if_match( ‘1234’ ).
lo_update_response = lo_update_request->execute( ).
lo_update_response->get_business_data( IMPORTING es_business_data = ls_employee )

Steps

Step 1: Create the entity resource for the employee with the following:

key “Id=‘007” in the entity set ‘Employees’ (internal name ‘EMPLOYEES’)

type “ty_s_employee_key” in the interface /iwbep/if_v4_tea_busi_types”

DATA lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES

Step 2: Create the update request instance on the entity resource. You need to provide the correct semantic (either PATCH or
PUT). PUT creates a full new resource representation. If some attributes are not provided, these attributes should be removed (set
to null) or set to their default value. PATCH also updates a resource, but unlike PUT, it applies a delta rather than replacing the
entire resource. The PATCH payload is a different content-type than the entity that it is modifying. Instead of being a full resource,
it is a resource that describes modifications that be made to a resource.

This is custom documentation. For more information, please visit the SAP Help Portal 45
10/19/24, 11:40 AM
In our example, we use PATCH semantic. You can use the constants in structure gcs_update_semantic of interface
/iwbep/if_cp_request_update as input:

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_update,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_update_request = lo_entity_resource->create_request_for_update( /iwbep/if_cp_r

Step 3: Set the business (for example, update) data for your update request. In our example, we want to update three properties.
We define the new values and set the business data into the update request:

Properties Internal Names

Age AGE

Status STATUS

IsManager IS_MANAGER

TYPES: BEGIN OF tys_patch_data,


age TYPE i,
is_manager TYPE abap_bool,
status TYPE string,
END OF tys_patch_data.

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_update,


ls_patch_data TYPE tys_patch_data.

ls_patch_data = VALUE #( age = 38


is_manager = abap_true
status = ‘Available’ ).

lo_update_request->set_business_data( is_business_data = ls_patch_data


it_provided_property = VALUE #( ( |AGE| )
( |IS_MANAGER| )
( |STATUS| ) ).

 Note
Providing the properties is required when calling SET_BUSINESS_DATA for a PATCH request.

Step 4: Set the If-Match header to provide a ETag (if needed for this request). For example, if the corresponding request header
is if-match: W/"1234", the required input for SET_IF_MATCH is ‘1234’:

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_update.

lo_update_request->set_if_match( ‘1234’ ).

Step 5: Run the update request and get the update response instance:

DATA: lo_update_request TYPE REF TO /iwbep/if_cp_request_update,


lo_update_response TYPE REF TO /iwbep/if_cp_response_update.

lo_update_response = lo_update_request->execute( ).

Step 6: Fetch the business data from the response object:

This is custom documentation. For more information, please visit the SAP Help Portal 46
10/19/24, 11:40 AM

DATA: lo_update_response TYPE REF TO /iwbep/if_cp_response_update,


ls_employee TYPE /iwbep/s_v4_tea_employee.

lo_update_response->get_business_data( IMPORTING es_business_data = ls_employee )

 Note
When you're using the Version 4 local client proxy, the business data you receive from the local consumption response isn't
converted again for outbound processing.

Related Information
OData Request Terms

OData Request: Read Entity


To create an OData request to read an entity in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

A client uses a RetrieveEntity request to retrieve an AtomPub Entry Resource. See RFC5023: Atom Publishing Protocol for more
information on the Atom Publishing Protocol.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

OData services support requests for data using HTTP GET requests. The URL path includes the request target (for example, the
collection of entities, entity, navigation property, structural property, or operation).

Example Requests

Version 4

Get the employee with id ‘007' from the “Employees” entity set.

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)

Version 2

Get the employee with id ‘007’ from the “Employees” entity set.

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees(‘007’)

OData Request: Read Entity

Overview
This is custom documentation. For more information, please visit the SAP Help Portal 47
10/19/24, 11:40 AM

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create a READ request on an
entity.

The starting point for a GET entity request is the Client Proxy instance. You can create an entity resource based on an entity list
resource, which can use create an entity resource based on an entity list resource. Use the entity resource to create a read request.

Running the read request provides a response, which can return the business data of the READ entity request.

Example

From the Version 4 entity set ‘Employees’, fetch the employee with key id ‘007’:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_read_request TYPE REF TO /iwbep/if_cp_request_read,
lo_read_response TYPE REF TO /iwbep/if_cp_response_read,
lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,
ls_employee TYPE /iwbep/s_v4_tea_employee.

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES')->navigate_with


lo_read_request = lo_entity_resource->create_request( ).
lo_read_response = lo_read_request->execute( ).
lo_read_response->get_business_data( IMPORTING es_business_data = ls_employee ).

Steps

To run an OData request to read an entity:

Step 1: Create the entity resource for the employee with the key Id=‘007' from the entity set ‘Employees’ (with internal name
‘EMPLOYEES’). Use type ty_s_employee_key in interface /iwbep/if_v4_tea_busi_types that includes the key property
id:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES')->navigate_with

Step 2: Create the read request instance on the entity resource:

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_read_request = lo_entity_resource->create_request( ).

Step 3: Execute the read request and get the read response instance:

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read,


lo_read_response TYPE REF TO /iwbep/if_cp_response_read.

lo_read_response = lo_read_request->execute( ).

Step 4: Fetch the business data from the response object:

This is custom documentation. For more information, please visit the SAP Help Portal 48
10/19/24, 11:40 AM

DATA: lo_read_response TYPE REF TO /iwbep/if_cp_response_read,


ls_employee TYPE /iwbep/s_v4_tea_employee.

lo_read_response->get_business_data( IMPORTING es_business_data = ls_employee ).

 Note
When you're using the Version 4 local client proxy, the business data you receive from the local consumption response isn't
converted again for outbound processing.

Related Information
OData Request Terms

OData Request: Read Optional Entity


Create an OData request to read an optional entity in the Client Proxy instance.

An optional entity is accessed using navigation with cardinality (for example, the measure of the number of elements in a set) zero-
to-one (for example, the accessed entity has either zero or one entry).

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

The client uses a RetrieveEntity Request to retrieve an AtomPub Entry Resource, as specified in RFC5023 , and potentially
related entities that map to EntityType instances.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

OData services support requests for data with HTTP GET requests. The URL path specifies thespecifies the target of the request
(for example, the collection of entities, entity, navigation property, structural property, or operation).

Example Requests

Version 4

Get the manager of the Employee with Id ‘0004’ via zero-to-one navigation property ‘Employee2Manager’:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees('0004')/Employee2Manager

Version 2

Get the technical info of the Team ‘TEAM_02’ via zero-to-one navigation property “Technical_Info”

GET/sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Teams('TEAM_02')/Technical_Info

This is custom documentation. For more information, please visit the SAP Help Portal 49
10/19/24, 11:40 AM

Read Optional Entity Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to read a an optional entity .

The starting point for a $read optional entity request is an optional entity in the Client Proxy instance. It's possible to create a
$read request with a corresponding zero-to-one navigation.

On the optional entity resource, it's possible to create an optional read request instance.

Running the zero-to-one read request provides the zero-to-one read response, which can return the business data of the optional
READ entity request.

Example

Get the manager of the Employee with Id ‘0004’ via zero-to-one navigation property ‘Employee2Manager’:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees('0004')/Employee2Manager

Steps

DATA: lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity01,


lo_read_request TYPE REF TO /iwbep/if_cp_request_read_01,
lo_read_response TYPE REF TO /iwbep/if_cp_response_read_01,
lt_manager TYPE STANDARD TABLE OF /iwbep/s_v4_tea_manager.

lo_read_request = lo_entity_resource->create_request_for_read( ).
lo_read_response = lo_read_request->execute( ).
lo_read_response->get_business_data( IMPORTING et_business_data = lt_manager ).

Step 1: Create the read request instance using the entity resource instance:

DATA: lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity01,


lo_read_request TYPE REF TO /iwbep/if_cp_request_read_01.

lo_read_request = lo_entity_resource->create_request_for_read( ).

 Note
See OData Request: Using Navigation for more information about how to create an optional entity resource instance.

 Note
Instead of a READ request, you can also to set up an UPDATE or DELETE request for the optional entity.

Step 2: Execute the read request and fetch the corresponding read response instance:

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read_01,


lo_read_response TYPE REF TO /iwbep/if_cp_response_read_01.

lo_read_response = lo_read_request->execute( ).

Step 3: Retrieve the business data from the read response instance:

This is custom documentation. For more information, please visit the SAP Help Portal 50
10/19/24, 11:40 AM

DATA: lo_read_response TYPE REF TO /iwbep/if_cp_response_read_01,


lt_manager TYPE STANDARD TABLE OF /iwbep/s_v4_tea_manager.

lo_read_response->get_business_data( IMPORTING et_business_data = lt_manager ).

 Note
The zero-to-one read request response is always a table that contains either zero or one entry.

Related Information
OData Request Terms
OData Request: Using Navigation

OData Request: Delete Entity


Create an OData request to delete an entity in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

The DeleteEntity Request enables an EntityType instance to be deleted from a data service. The base rules and
semantics of this request type are defined by AtomPub, as specified in RFC5023 section 9.4 -- Deleting Resources with
DELETE.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

To delete an individual entity, the client makes a DELETE request to a URL that identifies the entity.

When the delete is successfully completed, the response MUST be <response code and name> and contain an empty body.

Example Requests

Version 4

Delete the employee with id ‘007’ of entity set “Employees”

DELETE /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)

Version 2

Delete the employee with id ‘007’ of entity set “Employees”

DELETE /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees(‘007’)

Delete Entity Request


This is custom documentation. For more information, please visit the SAP Help Portal 51
10/19/24, 11:40 AM
Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create a DELETE entity
request.

The starting point for a DELETE entity request is the Client Proxy instance. You can create an entity resource based on an entity list
resource, which you can use to create a delete request.

Example

Delete the employee with key “id = ‘007’” of the Version 4 entity set ‘Employees’:

DELETE /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’) with IF-MATCH header

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_delete_request TYPE REF TO /iwbep/if_cp_request_delete,
lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES')->navigate_with


lo_delete_request = lo_entity_resource->create_request_for_delete( ).
lo_delete_request->set_if_match( ‘mi6’ ).
lo_delete_request->execute( ).
lo_delete_request->check_execution( ).

Steps

Step 1: Create the entity resource for the employee with the key “Id=‘007’” of entity set ‘Employees’ (with internal name
‘EMPLOYEES’). Type “ty_s_employee_key” in interface "/iwbep/if_v4_tea_busi_types” is a structure containing the
key property “id”:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_entity_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES')->navigate_with

Step 2: Create the delete request instance on the entity resource:

DATA: lo_delete_request TYPE REF TO /iwbep/if_cp_request_delete,


lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_delete_request = lo_entity_resource->create_request_for_delete( ).

Step 3: Set the If-Match header to provide an ETag (if needed for this request). If the corresponding request header is, for example,
if-match: W/"MI6", the required input for SET_IF_MATCH is ‘MI6’:

DATA: lo_delete_request TYPE REF TO /iwbep/if_cp_request_delete.

lo_delete_request->set_if_match( ‘mi6’ ).

Step 4: Run the delete request:

DATA: lo_delete_request TYPE REF TO /iwbep/if_cp_request_delete.

This is custom documentation. For more information, please visit the SAP Help Portal 52
10/19/24, 11:40 AM
lo_delete_request->execute( ).

 Note
A successful delete request doesn't have response data, which means that the EXECUTE method doesn't return a delete
response object.

Step 5: Check if the execution was successful:

DATA: lo_delete_request TYPE REF TO /iwbep/if_cp_request_delete.

lo_delete_request->check_execution( ).

 Note
Normally, any issues during the request execution raises an exception in method EXECUTE. This method call is optional.

Related Information
OData Request Terms

OData Request: Read Entity List


Create an OData request to read an entity list (entity collection) in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

A RetrieveEntitySet Request is used by a client to update the entries in an AtomPub Collection, as specified in RFC5023 ,
that maps to an EntitySet in the abstract data model.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

OData services support data requests for using HTTP GET requests. The URL path specifies the target of the request (for example,
the collection of entities, entity, navigation property, structural property, or operation).

Example Requests

Version 4

Get all entities of entity set “Employees”

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees

Version 2

This is custom documentation. For more information, please visit the SAP Help Portal 53
10/19/24, 11:40 AM
Get all entities of entity set “Employees”

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees

Read Entity List Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to create a READ request on an
entity list.

The starting point for a GET entity request is the Client Proxy Examples. You can create a read list request based on an
entity list resource.

Running the read list request provides the read list response that can provide the business data of the READ entity list
request.

Example

Fetch all entities of the Version 4 entity set ‘Employees':

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,
lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,
lo_entity_list_resource TYPE REF TO /iwbep/if_cp_resource_list,
lt_employee TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee.

lo_entity_list_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES' ).


lo_read_list_request = lo_entity_list_resource->create_request_for_read( ).
lo_read_list_response = lo_read_list_request->execute( ).
lo_read_list_response->get_business_data( IMPORTING et_business_data = lt_employee ).

Steps

Step 1: Create the entity list resource for entity set ‘Employees’ (with internal name ‘EMPLOYEES’):

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_entity_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

lo_entity_list_resource = lo_client_proxy->create_resource_for_entity_set( 'EMPLOYEES' ).

Step 2: Create the read list request instance on the entity resource:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_entity_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

lo_read_list_request = lo_entity_list_resource->create_request_for_read( ).

Step 3: Run the read list request and get the read list response instance:

This is custom documentation. For more information, please visit the SAP Help Portal 54
10/19/24, 11:40 AM

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

lo_read_list_response = lo_read_list_request->execute( ).

Step 4: Fetch the business data from the response object:

DATA: lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,


lt_employee TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee.

lo_read_list_response->get_business_data( IMPORTING et_business_data = lt_employee ).

 Note
When you're using the Version 4 local client proxy, the business data you receive from the local consumption response isn't
converted again for outbound processing.

Related Information
OData Request Terms

OData Request: Update Entity List


Create an OData request to update an entity list in the Client Proxy instance.

You want

OData Specification

OData Version 2

An update request for an entity list is not supported in OData Version 2.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

You can update entity collections by submitting a PATCH request to the collection's resource path. The body of the request:

MUST be a delta payload.

the resource path of the collection MUST NOT include type cast or filter segments.

MUST NOT include any system query options that affect the shape of the result.

Added/changed entities are applied as upserts. Deleted entities are applied as deletions.

Example Requests

Version 4

Update the complete entity set “Teams”:

This is custom documentation. For more information, please visit the SAP Help Portal 55
10/19/24, 11:40 AM

PATCH /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams

With request body

{
"@context" : "#$delta",
"value" : [
{
"Id" : "NEW 1",
"Name" : "Created",
"MemberCount" : 2,
"ManagerId" : "3",
"BudgetCurrency" : "USD",
"Budget" : 555.55
},
{
"Id" : "TEAM_02",
"Name" : "Update?"
},
{
"Id" : "New 3",
"Name" : "Created"
}
]
}

Updata Entity List Request

Overview

The starting point for a PATCH entity request is the Client Proxy instance. You can create an entity resource based on an
update list request, and use it to create an update request.

Running the update list provides the update list response, which can return the business data of the UPDATE entity list
request.

Example

Update the entity set “Teams”:

PATCH /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams

With request body

{
"@context" : "#$delta",
"value" : [
{
"Id" : "New Team",
"Name" : "Created",
"BudgetCurrency" : "USD",
"Budget" : 555
},
{
"Id" : "TEAM_02",
"Name" : "New Team Name"
}
]
}

This is custom documentation. For more information, please visit the SAP Help Portal 56
10/19/24, 11:40 AM

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_update_list_request TYPE REF TO /iwbep/if_cp_request_update_l,
lo_update_list_response TYPE REF TO /iwbep/if_cp_response_update_l,
lo_list_resource TYPE REF TO /iwbep/if_cp_resource_list,
lt_response_data TYPE STANDARD TABLE OF /iwbep/s_v4_tea_team,
lt_request_data TYPE STANDARD TABLE OF /iwbep/s_v4_tea_team.

lo_list_resource = lo_client_proxy->create_resource_for_entity_set( 'TEAMS’ ).


lo_update_list_request = lo_list_resource->create_request_for_update( ).

lt_request_data = value #( ( id =‘New team’ name =‘Created’ budget =555 budget_cur


( id = ‘TEAM_02’ name = ‘New Team Name’ ) ) .

lo_update_list_request->set_business_data( it_business_data = lt_request_data ).


lo_update_list_request->request_continue_on_error( ).
lo_update_list_response = lo_update_list_request->execute( ).
lo_update_list_response->get_business_data( IMPORTING et_business_data = lt_respon

Steps

Step 1: Create the entity list resource for entity set ‘Teams’ (with internal name ‘TEAMS’):

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

lo_list_resource = lo_client_proxy->create_resource_for_entity_set( 'TEAMS’ ).

Step 2: Create the update list request instance on the entity list resource:

DATA: lo_update_list_request TYPE REF TO /iwbep/if_cp_request_update_l,


lo_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

lo_update_list_request = lo_list_resource->create_request_for_update( ).

Step 3: Set the business data (for example, update) for your update list request. Define the corresponding business data and set it
into the update list request:

DATA: lo_update_list_request TYPE REF TO /iwbep/if_cp_request_update_l,


lt_request_data TYPE STANDARD TABLE OF /iwbep/s_v4_tea_team.

lt_request_data = VALUE #( ( id = ‘New team’ name = ‘Created’ budget = 555 budget_


( id = ‘team_02’ name = ‘New Team Name’ ) ) .

lo_update_list_request->set_business_data( it_business_data = lt_request_data ).

Step 4: (Optional) Request that the request processing continues even when there is an error (if supported).

If the server supports this setting, a failed operation for one entity doesn't cause the complete request to fail. The failed entity is
marked with the instance annotation Core.DataModificationException:

DATA: lo_update_list_request TYPE REF TO /iwbep/if_cp_request_update_l.

lo_update_list_request->request_continue_on_error( ).

 Note

This is custom documentation. For more information, please visit the SAP Help Portal 57
10/19/24, 11:40 AM
This information is mapped into the request header prefer:odata.continue-on-error. This preference is optional. The
consumed OData service does not have to follow this preference.

Step 5: Run the update list request and get the update list response instance:

DATA: lo_update_list_request TYPE REF TO /iwbep/if_cp_request_update_l,


lo_update_list_response TYPE REF TO /iwbep/if_cp_response_update_l.

lo_update_list_response = lo_update_list_request->execute( ).

Step 6: Fetch the business data from the response list object:

DATA: lo_update_list_response TYPE REF TO /iwbep/if_cp_response_update_l,


lt_response_data TYPE STANDARD TABLE OF /iwbep/s_v4_tea_team.

lo_update_list_response->get_business_data( IMPORTING et_business_data = lt_respon

Constraints

Updating an entity list is only supported for OData Version 4

This feature is not supported for local consumption

Only PATCH is supported. PUT is not supported.

IF-MATCH handling is not supported

Query options are not supported

Updating an entity list within a $batch is not supported

Related Information
OData Request Terms

OData Request: Custom Query Option


Create an OData request using a custom query option that isn't one of the OData-defined system query options in the Client Proxy
instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

Custom Query Options enable you to include data service-specific information in a data service URI query string.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

Services can support additional custom query options that are not defined in the OData specification. The custom query options:

This is custom documentation. For more information, please visit the SAP Help Portal 58
10/19/24, 11:40 AM
can't begin with the "$" or "@" character

can't conflict with any OData-defined system query options defined in the OData version that the service supports

Example Requests

Version 4

Use custom query option “sap-statistics”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?sap-statistics=true

Version 2

Use custom query option “sap-statistics”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Prices?sap-statistics=true

Custom Query Option Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to use $count.

The starting point for a custom query option request is an entity list read request. You can set a custom query option on the entity
list read request.

Example

Use custom query option “sap-statistics”

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?sap-statistics=true

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_http_client TYPE REF TO if_http_client,
lv_sap_statistics_result TYPE string.

lo_read_list_request->set_custom_query_options( VALUE #( ( name = ‘sap-statistics’ value = ‘true’


lo_read_list_request->execute( ).
lv_sap_statistics_result = lo_http_client->response->get_header_field( name = ‘sap-statistics’ ).

Steps

Step 1: Set the custom query option directly at the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->set_custom_query_options( VALUE #( ( name = ‘sap-statistics’ value = ‘true’

Step 2: Run the read request and fetch the sap statistics result from the HTTP client instance:

This is custom documentation. For more information, please visit the SAP Help Portal 59
10/19/24, 11:40 AM

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_http_client TYPE REF TO if_http_client,
lv_sap_statistics_result TYPE string.

lo_read_list_request->execute( ).
lv_sap_statistics_result = lo_http_client->response->get_header_field( name = ‘sap-statistics’ ).

 Note
lo_http_client must be the same HTTP client instance as the one used for creating the Client Proxy.

Constraints
Regardless of the Client Proxy OData version, input MUST conform with the more stricter OData Version 4 specification.

You can only use custom query options for remote consumption. Custom query options are not supported in local
consumption scenarios.

Related Information
OData Request Terms
Client Proxy Instance Types

OData Request: Deep Create


Create an OData request to execute a “deep create” (deep insert) in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

In the Deep Create request, you can insert a new EntityType instance (E1) into an EntitySet and insert new entities related to E1.
This is described by a NavigationProperty on the EntityType associated with E1) in a single InsertEntity Request. For example, in a
customer relationship management-focused data service, you can insert a new customer entity and new related order entities in a
single InsertEntity Request. This type of an InsertEntity Request is also known as a "deep insert".

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

A "deep insert" request creates an entity that includes related entities using the appropriate inline representation

Example Requests

Version 4

Create a new team (entity set “TEAMS”) and a new manager (entity set “MANAGERS”) via navigation property
“TEAM_2_MANAGER”:

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/TEAMS

This is custom documentation. For more information, please visit the SAP Help Portal 60
10/19/24, 11:40 AM
With request body

{
"Name" : "Business Suite",
"MEMBER_COUNT" : 2,
"MANAGER_ID" : "8",
"BudgetCurrency" : "USD",
"Budget" : 555.55,
"TEAM_2_MANAGER" : {
"ID" : "8",
"TEAM_ID" : ""
}
}

Version 2

Create the employee with id ‘1’ (entity set “EMPLOYEES”) and the corresponding team (entity set “TEAMS”) with navigation
property “My_Team”:

POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees

With request body

{
"Location" : {
"Country" : "Germany",
"City" : {
"PostalCode" : "69124",
"CityName" : "Heidelberg",
"VeryLongPropertyNameForOrderBy" : ""
}
},
"Id" : "1",
"Name" : "Walter Winter",
"Age" : " 52",
"EntryDate" : "\/Date(915148800000)\/",
"Manager_ID" : "1",
"Room_ID" : "1",
"Team_ID" : "TEAM_01",
"My_Team" : {
"Team_Identifier" : "TEAM_01",
"Name" : "Business Suite"
}
}

Deep Create Request


Overview

 Note
As the coding itself is independent of the OData version, we will just present one general example on how to create a execute a
deep create request.

As the coding is independent of the OData version, we're presenting a general example on how to create a deep create
request on an entity.

The main difference between a create and a deep create request in the Client Proxyinstance is that the deep create
request requires a data description node. You create a data description node at the create request instance and it is used later
when setting the deep business data.

This is custom documentation. For more information, please visit the SAP Help Portal 61
10/19/24, 11:40 AM

 Note
See OData Request: Create Entity for more information.

Example

Create a new team (entity set “Teams”) and a new manager (entity set “Managers”):

POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Team

With request body

{
"Id" : "TEAM_04",
"MemberCount" : 2,
"Team2Manager" : {
"Id" : "0009"
}
}

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_create_response TYPE REF TO /iwbep/if_cp_response_create,
lo_data_des_node_root TYPE REF TO /iwbep/if_cp_data_desc_node,
lo_data_desc_node_child TYPE REF TO /iwbep/if_cp_data_desc_node,
ls_deep_busi_data TYPE /iwbep/if_v4_tea_busi_types=>ty_s_team_and_manager,
ls_response_data TYPE /iwbep/if_v4_tea_busi_types=>ty_s_team_and_manager.

lo_data_desc_node_root = lo_create_request->create_data_description_node( ).
lo_data_desc_node_root->set_properties( VALUE #( ( |ID| ) ( |MEMBER_COUNT| ) ) ).

lo_data_desc_node_child = lo_data_desc_node_root->add_child( ‘team_2_manager’ ).


lo_data_desc_node_child->set_properties( VALUE #( ( |ID| ) ) ).

ls_deep_busi_data = VALUE #( id = ‘team_04’


member_count = 2
team_2_manager = VALUE #( id = ‘0009’ ) ).

lo_create_request->set_deep_business_data( is_business_data = ls_deep_busi_data


io_data_description_node = lo_data_desc_node_root ).
lo_create_response = lo_create_request->execute( ).

lo_create_response->get_business_data( IMPORTING es_business_data = ls_response_dat

lo_create_response->get_business_data( IMPORTING es_business_data = ls_response_dat

Steps

Step 1: Creation of the data description node for the root entity (here: “Teams”) on the create request instance:

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_data_des_node_root TYPE REF TO /iwbep/if_cp_data_desc_node.

lo_data_desc_node_root = lo_create_request->create_data_description_node( ).

 Note
See OData Request: Create Entity for more information.

This is custom documentation. For more information, please visit the SAP Help Portal 62
10/19/24, 11:40 AM
Step 2: Set the properties for the root entity. In our example, the properties are “Id” (internal name “ID”) and “MemberCount”
(internal name “MEMBER_COUNT”):

DATA: lo_data_des_node_root TYPE REF TO /iwbep/if_cp_data_desc_node.

lo_data_desc_node_root->set_properties( VALUE #( ( |ID| ) ( |MEMBER_COUNT| ) ) ).

Step 3: Create the data description node for the child entity (in this example, “Managers”) on the root data description node.
“TEAM_2_MANAGER” is the internal name of navigation property “Team2Manager”:

DATA: lo_data_des_node_root TYPE REF TO /iwbep/if_cp_data_desc_node,


lo_data_desc_node_child TYPE REF TO /iwbep/if_cp_data_desc_node.

lo_data_desc_node_child = lo_data_desc_node_root->add_child( ‘team_2_manager’ ).

Step 4: Set the properties for the child entity (in this example, “Managers”). Only property “Id” (with internal name “ID” ) is
included:

DATA: lo_data_desc_node_child TYPE REF TO /iwbep/if_cp_data_desc_node.

lo_data_desc_node_child->set_properties( VALUE #( ( |ID| ) ) ).

Step 5: Define the request data for the deep create and set the deep business data into the request instance (in the root data
description node):

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_data_des_node_root TYPE REF TO /iwbep/if_cp_data_desc_node,
ls_deep_busi_data TYPE /iwbep/if_v4_tea_busi_types=>ty_s_team_and_manager.

ls_deep_busi_data = VALUE #( id = ‘team_04’


member_count = 2
team_2_manager = VALUE #( id = ‘0009’ ) ).

lo_create_request->set_deep_business_data( is_business_data = ls_deep_busi_data


io_data_description_node = lo_data_desc_node_root ).
ENDCLASS.

 Note
The property that references the child entity business data MUST be named using the internal name of the corresponding
navigation property (in this example, the property is “TEAM_2_MANAGER”, which describes the business data for the child
entity “Managers”).

 Note
If the underlying entity has value control or VCS properties. The VCS properties should also be part of the provided data
container (in this example, ls_deep_busi_data). If the properties aren't part of the data container, the behavior (for
example conversion exits) is undefined and can cause nexpected errors.

Step 6: Run the deep create request and fetch the response business data from the create response instance:

DATA: lo_create_request TYPE REF TO /iwbep/if_cp_request_create,


lo_create_response TYPE REF TO /iwbep/if_cp_response_create,
ls_response_data TYPE /iwbep/if_v4_tea_busi_types=>ty_s_team_and_manager.

This is custom documentation. For more information, please visit the SAP Help Portal 63
10/19/24, 11:40 AM
lo_create_response = lo_create_request->execute( ).
lo_create_response->get_business_data( IMPORTING es_business_data = ls_response_dat

 Note
This part is identical to handling a typical create request in the Client Proxy instance.

Related Information
OData Request Terms

OData Request: Delta Link Query Option


Create an OData request with $delta token query option in the Client Proxy instance.

OData Specification
OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

Delta links are service-generated links the client uses to access newly created, updated, or deleted entities without a full read of
the target resource with every request.

Delta links are based on a defining query that tracks the changes of the set of results. For example, the request that generated the
results containing the delta link. The delta link encodes the entity collection that tracks the changes. Also, it includes a starting
point to begin track changes.

Example Requests

Version 4

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_tech/0001/PagedDeltaEntities?$deltatoken=2017061200

Delta Link Query Request

Overview

The starting point for a delta link in the Client Proxy instance is either a Client Proxy instance or a read list request instance
(depending on your use case).

Example 1: Create a new delta link

You ran a read list request in the Client Proxy instance and you want to save a delta link for this response, so you can track future
changes to the current response:

Step 1: Save the current response as delta link (in this example under the name ‘DELTA_LINK_NAME’):

DATA: lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

lo_read_list_response->save_delta_link ( ‘delta_link_name’ ).

This is custom documentation. For more information, please visit the SAP Help Portal 64
10/19/24, 11:40 AM
Example 2: Create a delta request from an existing delta link

You have an existing delta link and want to use it to create a delta request:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_delta_read_request TYPE REF TO /iwbep/if_cp_request_read_dlta,
lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

CHECK lo_client_proxy->does_delta_link_exist( ‘delta_link_name’ ) = abap_true.


CHECK lo_client_proxy->can_delta_request_be_created( ‘delta_link_name’ ) = abap_true.

lo_delta_read_request = lo_client_proxy->create_request_for_delta( ‘delta_link_name’ ).


lo_read_list_response = lo_delta_read_request->execute( ).

Steps

Step 1: Check that the delta link:

does exist (in this example, ‘DELTA_LINK_NAME’).

can be used to create a delta request. If the stored delta link was manually changed, the delta link can't be used).

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_delta_read_request TYPE REF TO /iwbep/if_cp_request_read_dlta,
lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

CHECK lo_client_proxy->does_delta_link_exist( ‘delta_link_name’ ) = abap_true.


CHECK lo_client_proxy->can_delta_request_be_created( ‘delta_link_name’ ) = abap_true.

 Note
You can only find and use delta links that you created.

Step 2: Use the stored delta link to create a delta link request instance:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_delta_read_request TYPE REF TO /iwbep/if_cp_request_read_dlta.

lo_delta_read_request = lo_client_proxy->create_request_for_delta( ‘delta_link_name’ ).

Step 3: Run the delta link request and fetch the corresponding response instance:

DATA: lo_delta_read_request TYPE REF TO /iwbep/if_cp_request_read_dlta,


lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

lo_read_list_response = lo_delta_read_request->execute( ).

Example 3: Insert an existing delta link into an existing request

You have an existing request and want to use it in combination with an existing delta link:

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,


lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,
lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

CHECK lo_client_proxy->does_delta_link_exist( ‘delta_link_name’ ) = abap_true.


CHECK lo_client_proxy->can_delta_request_be_created( ‘delta_link_name’ ) = abap_false.

This is custom documentation. For more information, please visit the SAP Help Portal 65
10/19/24, 11:40 AM
lo_read_list_request->use_delta_link( ‘delta_link_name’ ).
lo_read_list_response = lo_read_list_request->execute( ).

Steps

Step 1: Check that the delta link:

does exist (in this example, ‘DELTA_LINK_NAME’).

can be used to create a delta request. If it can be used to create a delta request, you use method
CREATE_REQUEST_FOR_DELTA, in example 2.

DATA: lo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy.

CHECK lo_client_proxy->does_delta_link_exist( ‘DELTA_LINK_NAME’ ) = abap_true.


CHECK lo_client_proxy->can_delta_request_be_created( ‘DELTA_LINK_NAME’ ) = abap_false.

 Note
You can only find and use delta links that you created.

Step 2: Insert the delta link into the existing read list request:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->use_delta_link( ‘delta_link_name’ ).

Step 3: Get the read list response instance using the read list request

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,

lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.

lo_read_list_response = lo_read_list_request->execute( ).

Related Information
OData Request Terms
OData Request: Read Entity List
Client Proxy Instance Types

OData Request: Using Navigation


Create an OData request using a navigation in the Client Proxy instance.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

A unidirectional (one-way) relationship (for example, a Link) is when two entity types are related by association, but only one of the
entity types defines a NavigationProperty that binds to the association.

This is custom documentation. For more information, please visit the SAP Help Portal 66
10/19/24, 11:40 AM
OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

Relationships from one entity to another are represented as navigation properties. Navigation properties are defined as part of an
entity type, but can also appear on entity instances as undeclared dynamic navigation properties. Each relationship has a
cardinality.

Example Requests

Version 4

Get all employees associated with Team ‘TEAM_01’ via navigation property ‘Team2Employees’:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams('TEAM_01')/Team2Employees

Version 2

Get the team of the employee with Id ‘0005’ via navigation property “My_Team”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees(Id='0005')/My_Team

Using Navigation Request

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to use navigations.

The starting point for a request using a navigation is an entity resource. On the entity resource, you can create a resource for the
corresponding navigation target.

Example 1

Navigate to an entity list with Navigation Property “Department2Teams”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Departments(Id='1',Sector='Consulting')/D

Steps

Step 1: Create the target resource on the entity resource using the internal name of the navigation property
(“DEPARTMENT_2_TEAMS”):

DATA: lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,


lo_target_list_resource TYPE REF TO /iwbep/if_cp_resource_list.

lo_target_list_resource = lo_entity_resource->navigate_to_many( ‘department_2_teams’ ).

 Note
You can use the target resource to create a READ request.

This is custom documentation. For more information, please visit the SAP Help Portal 67
10/19/24, 11:40 AM
Example 2

Navigate to a single entity using the Navigation Property “Team2Manager”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams('TEAM_01')/Team2Manager

Steps

Step 1: Create the target resource on the entity resource using the internal name of the navigation property
(“TEAM_2_MANAGER”):

DATA: lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,


lo_target_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity.

lo_target_entity_resource = lo_entity_resource-> navigate_to_single( ‘team_2_manager’ ).

 Note
You can use the target resource to create a READ request.

Example 3

Navigate to an optional (for example. zero-to-one navigation) entity using the Navigation Property “Employee2Manager”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees('0004')/Employee2Manager

Step-by-step

Step 1: Create the target resource on the entity resource using the internal name of the navigation property
(“EMPLOYEE_2_MANAGER”):

DATA: lo_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity,


lo_target_entity_resource TYPE REF TO /iwbep/if_cp_resource_entity01.

lo_target_entity_resource = lo_entity_resource-> navigate_to_optional( ‘employee_2_manager’ ).

 Note
You can use the target resource to create an optional READ request.

Related Information
OData Request: Read Entity

OData Request: Including a Nextlink


Create an OData request to read an entity list (entity collection) with a next link in the Client Proxy instance.

OData Specification

OData Version 4

This is custom documentation. For more information, please visit the SAP Help Portal 68
10/19/24, 11:40 AM
See also: OData Version 4.01. Part 1: Protocol .

In responses that include a partial set of the items identified by the request, the URL MUST include a link (a next link) that allows
retrieving the next partial set of items.A next link representation is format-specific. The final partial set of items MUST NOT contain
a next link.

Nextlink Request
Overview

The starting point for a next link request is the Client Proxy instance, is read list response instance.

Example

You created a read list request in the Client Prox instance and want to manage potential next links:

DATA: lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,


lt_employee TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee.

lo_read_list_response->get_business_data( IMPORTING et_business_data = lt_employee ).

WHILE lo_read_list_response->has_next( ).
lo_read_response = lo_read_response->get_next( ).
lo_read_list_response->get_business_data( IMPORTING et_business_data = lt_employee ).
ENDWHILE.

Steps

Step 1: Fetch the first batch of entities from the read list response instance:

DATA: lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,


lt_employee TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee.

lo_read_list_response->get_business_data( IMPORTING et_business_data = lt_employee ).

Step 2: Check that there are still next links using the HAS_NEXT method on the response instance). Then you can fetch the next
batch of entities. Get the corresponding response instance by using the GET_NEXT method on the previous response instance.
Then get the business data from this new instance:

DATA: lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,


lt_employee TYPE STANDARD TABLE OF /iwbep/s_v4_tea_employee.

WHILE lo_read_list_response->has_next( ).
lo_read_response = lo_read_response->get_next( ).
lo_read_list_response->get_business_data( IMPORTING et_business_data = lt_employee ).
ENDWHILE.

Constraints
Next links are only supported for OData Version 4 requests.

Next links are only supported for remote consumption.

Related Information

This is custom documentation. For more information, please visit the SAP Help Portal 69
10/19/24, 11:40 AM
OData Request Terms
OData Request: Read Entity List

OData Request System Query Options


Learn how to use OData system query options. System query options include:

$expand Option
Use the $expand system query option to represent associated EntityType instance or EntitySet inline.

OData Specification

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

The $expand System Query Option indicates that entities associated with the EntityType instance or EntitySet (identified by the
Resource Path section of the URI) must be represented inline.

OData Version 4

See OData Version 4.01. Part 1: Protocol .

The $expand system query option indicates the related entities and stream values that MUST be represented inline. The service
MUST return the specified content and can choose to return additional information.

The value of the $expand query option is a comma-separated list of navigation property names, stream property names, or
$value that indicate the stream content of a media-entity.

Example Requests

Version 4

Get the team ‘TEAM_03’ and its manager with navigation property “Team2Manager”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams('TEAM_03')?$expand=Team2Manager

Version 2

Get the manager with id ‘0004’ and the information about his team with navigation property “My_Team”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Managers('0001')?$expand=My_Team

$expand System Query Option

Overview

 Note

This is custom documentation. For more information, please visit the SAP Help Portal 70
10/19/24, 11:40 AM
As the coding is independent of the OData version, we're presenting a general example on how to use the $expand option.

The starting point for a request with the $expand option is an entity list read request. On the entity list read request, you can set
the $expand option.

Example

Get all entities from the entity set “Teams”. For each term, fetch the corresponding manager using the navigation property
“Team2Manager”. You want to retrieve only the Id of each manager:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?$expand=Team2Manager($select=Id)

Steps

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_expand_node_root TYPE REF TO /iwbep/if_cp_expand_node,
lo_expand_node TYPE REF TO /iwbep/if_cp_expand_node.

lo_expand_node_root = lo_read_list_request->create_expand_node( ).
lo_expand_node = lo_expand_node_root->add_expand( ‘team_2_manager’ ).
lo_expand_node->set_select_properties( VALUE #( ( CONV #( ‘id’ ) ) ) ).

 Note
The SET_EXPAND method is obsolete. It's not necessary to explicitly set the expand node in the request.

Step 1: Create the root expand node on the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_expand_node_root TYPE REF TO /iwbep/if_cp_expand_node.

lo_expand_node_root = lo_read_list_request->create_expand_node( ).

Step 2: Add the expand path by using the internal name of the navigation property (“TEAM_2_MANAGER”). This step creates a
new expand node:

DATA: lo_expand_node_root TYPE REF TO /iwbep/if_cp_expand_node,


lo_expand_node TYPE REF TO /iwbep/if_cp_expand_node.

lo_expand_node = lo_expand_node_root->add_expand( ‘team_2_manager’ ).

Step 3: Set the selected properties (using internal names) on the select node. “ID” is the internal name of property “Id”:

DATA: lo_expand_node TYPE REF TO /iwbep/if_cp_expand_node.

lo_expand_node->set_select_properties( VALUE #( ( CONV #( ‘id’ ) ) ) ).

Related Information
OData Request Terms
OData Request: Read Entity
OData Request: Read Entity List

This is custom documentation. For more information, please visit the SAP Help Portal 71
10/19/24, 11:40 AM

$filter Option
Use the $filter system query option to restrict the returned set of items.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

A data service URI with a $filter System Query Option identifies a subset of the entities in the EntitySet (identified by the
Resource Path section of the URI) by only selecting the entities that meet the predicate expression the query option specifies.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

The $filter system query option restricts the set of items that are returned.

Example Requests

Version 4

Get the entities in entity set “Employees” that have the Id “0006” and the Postalcode “69190”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees?$filter=Location/City/Postalcod

Version 2

Get the entities in entity set “Employees” with the Id “0006” and the PostalCode “69190”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees?$filter=Location/City/PostalCode eq '69190

$filter System Query Option

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to use the $filter option.

The starting point for a request with the $filter option is an entity list read request.

Example

Get all entities from the entity set “Buildings” with the BuildingID “ROT05” and Cityname is not “Walldorf”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Buildings?$filter=Location/City/Cityname

Steps

This is custom documentation. For more information, please visit the SAP Help Portal 72
10/19/24, 11:40 AM

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lt_range TYPE RANGE OF string,
lo_filter_factory TYPE REF TO /iwbep/if_cp_filter_factory,
lo_filter_node_1 TYPE REF TO /iwbep/if_cp_filter_node,
lo_filter_node_2 TYPE REF TO /iwbep/if_cp_filter_node,
lo_filter_node_final TYPE REF TO /iwbep/if_cp_filter_node.

lo_filter_factory = lo_read_list_request->create_filter_factory( ).

lt_range = VALUE #( ( option = ‘ne’ sign = ‘i’ low = ‘Walldorf’ ) ).

lo_filter_node_1 = lo_filter_factory->create_by_range( iv_property_path = ‘location-city-cityname


it_range = lt_range ).

lt_range = VALUE #( ( option = ‘eq’ sign = ‘i’ low = ‘rot05’ ) ).

lo_filter_node_2 = lo_filter_factory->create_by_range( iv_property_path = ‘building_id‘


it_range = lt_range ).

lo_filter_node_final = lo_filter_node_1->and( lo_filter_node_2 ).


lo_read_list_request->set_filter( lo_filter_node_final ).
.

Step 1: Create an instance of the filter factory at the read list request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_filter_factory TYPE REF TO /iwbep/if_cp_filter_factory.

lo_filter_factory = lo_read_list_request->create_filter_factory( ).

Step 2: Create a filter node for the first filter expression (Location/City/Cityname ne 'Walldorf' ). We define the new
values and set the business data to the request:

Properties Internal Names

Cityname CITYNAME

Location LOCATION

City CITY

The filter expression must be expressed in a range:

DATA: lt_range TYPE RANGE OF string,


lo_filter_factory TYPE REF TO /iwbep/if_cp_filter_factory,
lo_filter_node_1 TYPE REF TO /iwbep/if_cp_filter_node.

lo_filter_factory = lo_read_list_request->create_filter_factory( ).

lt_range = VALUE #( ( option = ‘ne’ sign = ‘i’ low = ‘Walldorf’ ) ).

lo_filter_node_1 = lo_filter_factory->create_by_range( iv_property_path = ‘location-city-cityname


it_range = lt_range

Step 3: Create a filter node for the second filter expression BuildingID' ROT05'. The internal name of the primitive property
“BuildingID” is “BUILDING_ID”. The filter expression must be expressed in a range:

DATA: lt_range TYPE RANGE OF string,


lo_filter_factory TYPE REF TO /iwbep/if_cp_filter_factory,
lo_filter_node_2 TYPE REF TO /iwbep/if_cp_filter_node.

This is custom documentation. For more information, please visit the SAP Help Portal 73
10/19/24, 11:40 AM
lt_range = VALUE #( ( option = ‘eq’ sign = ‘i’ low = ‘rot05’ ) ).

lo_filter_node_2 = lo_filter_factory->create_by_range( iv_property_path = ‘building_id‘


it_range = lt_range ).

Step 4: Connect the two filter nodes with "and" in the final filter node:

DATA: lo_filter_node_1 TYPE REF TO /iwbep/if_cp_filter_node,


lo_filter_node_2 TYPE REF TO /iwbep/if_cp_filter_node,
lo_filter_node_final TYPE REF TO /iwbep/if_cp_filter_node.

lo_filter_node_final = lo_filter_node_1->and( lo_filter_node_2 ).

Step 5: Set the final filter node in the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_filter_node_final TYPE REF TO /iwbep/if_cp_filter_node.

lo_read_list_request->set_filter( lo_filter_node_final ).

Negation

To use negation call the NOT method on a filter node instance (for example, $filter=not(BuildingID is 'WDF03'). This
step creates a new filter node (the negated filter node):

DATA: lo_filter_node TYPE REF TO /iwbep/if_cp_filter_node,


lo_filter_node_not TYPE REF TO /iwbep/if_cp_filter_node.

lo_filter_node_not = lo_filter_node->not( ).

Constraints

$filter is only supported for primitive and complex properties.

Only these range options are allowed: EQ, NE, GT, GE, LT, and LE.

Only range signs “I” and “E” are allowed.

Conversions with range option “CP” are not allowed.

Only these functions can be used with CP: startswith, endswith, and substringof (for OData Version 2), contains
(for OData Version 4).

Not all filter expression are supported for local consumption.

The currency code must be provided when the addressed property has a reference to a currency property.

The unit of measurement must be provided when the addressed property has a reference to a unit property

You can't set a $filter for an $expand.

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/TEAMS?$expand=TEAM_2_EMPLOYEES($fil

Related Information
OData Request Terms

This is custom documentation. For more information, please visit the SAP Help Portal 74
10/19/24, 11:40 AM

$count Option
Use the $count or $inlinecount system query option to indicate a certain number or total count of entities in the EntitySet.

OData Specification

OData Version 2

See also: [MS-ODATA]: Open Data Protocol (OData) .

$inlinecount: For a value of "allpages", the $inlinecount option indicates the response to the request must include the
number of entities count in the EntitySet. The number of entities count is identified by the Resource Path section of the URI after
all $filter System Query Options are applied.

If the value is "none", this option indicates the response to the request MUST NOT include the count value.

OData Version 4

See also: OData Version 4.01. Part 1: Protocol .

The $count system query option with a value of true specifies that the total item count in a collection that matches the request
is returned with the result.

The $count system query option ignores $top, $skip, or $expand query options, and returns the total results count across all
pages (including only the results that match any specified $filter and $search). The count returned inline might not equal the
actual number of items returned. This happens due to latency between calculating the count and enumerating the last value or
due to inexact calculations on the service.

Example Requests
Version 4

Get the number of entities in entity set “TEAMS”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/TEAMS/$count

Get all Equipment entities associated with "Employee 1" and the total count of associated items:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES('1')/EMPLOYEE_2_EQUIPMENTS?$cou

Version 2

Get the number of entities in entity set “EquipmentSet”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/EquipmentSet/$count

Get all Team Member entities associated with Team “TEAM_01” and the total count of associated members:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Teams('TEAM_01')/Team_Members?$inlinecount=allpages

$count System Query Option


This is custom documentation. For more information, please visit the SAP Help Portal 75
10/19/24, 11:40 AM
Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to use the $count option.

The starting point for a request with the $count option is an entity list read request. You can set the $count on the entity list read
request.

You can fetch the $count result from the entity list read response instance.

 Note
The actual “flavor” of the $count that the Client Proxy sets depends on the request type:

$count if no business data is requested.

$count=true for OData Version 4 requests if business data is requested.

$inlinecount=allpages for OData Version 2 if business data is requested.

Example 1

Get the number of entities in entity set “TEAMS”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/TEAMS/$count

Steps

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,
lv_count TYPE REF TO int8.

lo_read_list_request-> request_no_business_data( ).
lo_read_list_request->request_count( ).
lo_read_list_response = lo_read_list_request->execute( ).
lv_count = lo_read_list_response->get_count( ).

Step 1: Set the request to NOT fetch the entity list (for example, request_no_business_data):

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request-> request_no_business_data( ).

Step 2: Request the $count at the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->request_count( ).

Step 3: Run the request and fetch the count value from the read list response instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,
lv_count TYPE REF TO int8.

This is custom documentation. For more information, please visit the SAP Help Portal 76
10/19/24, 11:40 AM
lo_read_list_response = lo_read_list_request->execute( ).
lv_count = lo_read_list_response->get_count( ).

Example 2

Get all Equipment entities associated with "Employee 1" and the total count of associated items:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES('1')/EMPLOYEE_2_EQUIPMENTS?$cou

Steps

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst,
lv_count TYPE REF TO int8.

lo_read_list_request->request_count( ).
lo_read_list_response = lo_read_list_request->execute( ).
lv_count = lo_read_list_response->get_count( ).

 Note
The steps for this example are identical to the first example, except that you do NOT request to not return any business data
(you skip step 1 in the first example).

See example one for a the steps.

Related Information
OData Request Terms
OData Request: Read Entity
OData Request: Read Entity List

$orderby Option
Use the $orderby system query option to determine what values are used to order the entities in the EntitySet.

OData Specification

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

A data service URI with the $orderby System Query Option specifies an expression for determining what values are used to order
the entities in the EntitySet (identified by the Resource Path section of the URI).

OData Version 4

See OData Version 4.01. Part 1: Protocol .

The $orderby System Query option specifies the order that items are returned from the service. The value of the $orderby
System Query option is a comma-separated list of expressions that use the primitive result values to sort the items. The
expression can include the suffix asc for ascending or desc for descending that you separate from the property name by one or
more spaces.

This is custom documentation. For more information, please visit the SAP Help Portal 77
10/19/24, 11:40 AM

Example Requests

Version 4

Get all entities of entity set “Employees” and sort the response descending to property “Cityname” and ascending to property
“Age”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees?$orderby=Location/City/Cityname

Version 2

Get all entities of entity set “Employees” and sort the response ascending to property “Id” and descending to property “Name”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees?$orderby=Id, Name asc

$orderby System Query Option

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to use the $orderby option.

The starting point for a request with the $orderby option is an entity list read request. You can set the $orderby on the entity
list read request.

Example

Get all entities of entity set “Employees” and sort the response descending to property “Cityname” (in complex property
“City”, which is part of complex property “Location”) and ascending to property “Age”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees?$orderby=Location/City/Cityname

Steps

Step 1: Set the $orderby values at the request instance:

Properties Internal Names

Age AGE

Location LOCATION

City CITY

Cityname CITYNAME

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.


lo_read_list_request-> set_orderby( value #(( property_path = ‘LOCATION-CITY-CITYNAME’

( property_path = ‘AGE’

This is custom documentation. For more information, please visit the SAP Help Portal 78
10/19/24, 11:40 AM

Related Information
OData Request Terms
OData Request: Read Entity
OData Request: Read Entity List

$select Option
Use the $select system query option to return a subset for the returned properties of the URI without a $select query option.

OData Specification

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

A data service URI with a $select System Query Option identifies the same set of entities as a URI without a $select query
option. If you have a $select query option, the data service response returns a subset (identified by the $select query option)
for the returned properties of the URI that didn't include a $select query option.

OData Version 4

See OData Version 4.01. Part 1: Protocol .

The $select system query option requests that the service return only the properties, dynamic properties, actions, and
functions explicitly requested by the client. The service returns the specified content (if available) and any available expanded
navigation or stream properties. It can also return additional information.

Example Requests

Version 4

Get the employee with Id ‘0002’ of entity set “Employees” and return only properties “Name” and “Age”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees('0002')?$select=Name,Age

Version 2

Get all entities of entity set “Managers” and return only properties “Name” and “Age”:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Managers?$select=Name,Age

$select System Query Option

Overview

 Note
As the coding is independent of the OData version, we're presenting a general example on how to use the $select option.

This is custom documentation. For more information, please visit the SAP Help Portal 79
10/19/24, 11:40 AM
The starting point for a request with $select is a read request on an entity list. You can set the selected properties on the entity
list read request.

Example

Set the properties “Age”, “Name” and “Cityname” for the employee with Id ‘0002’ for the entity set “Employees”. “Cityname” is
in the complex property “City”, which is of the complex property “Location”:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees('0002')?$select=Name,Age,Locati

Steps

Step 1: Set the properties you want to select at the read request instance:

Properties Internal Names

Age AGE

Location LOCATION

City CITY

Cityname CITYNAME

Name NAME

DATA: lo_read_request TYPE REF TO /iwbep/if_cp_request_read.

lo_read_request->set_select_properties( VALUE #( ( CONV #('AGE’) )

( CONV #(

( CONV #('NAME

Related Information
OData Request Terms
OData Request: Create Entity
OData Request: Read Entity

$skip and $top Options


Use the $skip or $top system query options to identify a subset of the entities in an entity collection.

OData Specification

OData Version 2

See [MS-ODATA]: Open Data Protocol (OData) .

A data service URI with:

This is custom documentation. For more information, please visit the SAP Help Portal 80
10/19/24, 11:40 AM

$skip System Query Option $top System Query Option

identifies a subset of the entities in an entity collection (identified by the identifies a subset of the entities in an entity collection
Resource Path section of the URI) (identified by the Resource Path section of the URI)

the subset is defined by searching N entities in an collection and the subset is formed by selecting only the first N items of the
selecting only the remaining entities (starting with entity N+1). set.

N is a positive integer specified by this query option. N is a positive integer specified by this query option.

OData Version 4

See OData Version 4.01. Part 1: Protocol .

A data service URI with:

$skip System Query Option $top System Query Option

specifies a non-negative integer n that excludes the first n items specifies a non-negative integer n that limits the number of items
of the queried collection. returned from a collection.

the service returns items starting at position n+1. the service returns the number of available items up to but not
greater than the specified value n.

Example Requests
Version 4

Skip the first entity in entity set “TEAMS” and get the following two ones:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?$skip=1&$top=2

Version 2

Skip the first entity in entity set “Managers” and get the following two ones:

GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Managers?$skip=1&$top=2

$skip and $top Query Options


Overview

 Note

As the coding is independent of the OData version, we're presenting a general example on how to use the $count option.

The starting point for a request with $skip or $top option is an entity list read request. You can set both the $skip and the $top
on the entity list read request.

Example

Skip the first entity in entity set “TEAMS” and get these entities:

This is custom documentation. For more information, please visit the SAP Help Portal 81
10/19/24, 11:40 AM

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?$skip=1&$top=2

Steps

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->set_skip( 1 ).
lo_read_list_request->set_top( 2 ).

Step 1: Set the $skip value at the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->set_skip( 1 ).

Step 2: Set the $top value at the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->set_top( 2 ).

Related Information
OData Request Terms

$search Option
Use the $search system query option to restrict results to include items you specify in the expression..

OData Specification

OData Version 4

See [MS-ODATA]: Open Data Protocol (OData) .

The $search system query option restricts the result to include only the items that match the specified search expression. The
type of match depends on your implementation.

Example Requests
Version 4

Get all entities of Entity Set “Employees” with “Peter” or “Smith” in their name:

GET/sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES?$search=Peter OR Smith

$search System Query Option

Overview

This is custom documentation. For more information, please visit the SAP Help Portal 82
10/19/24, 11:40 AM
The starting point for a request with the $search option is an entity list read request. You can set the $search expression on
the entity list read request.

 Note
Depending on your implementation, the result of the $search option on a property can vary. In our example, $search acts on
property “Name”.

Example

Search all entities of Entity Set “Employees” with “Peter” or “Smith” in their name:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES?$search=Peter OR Smith

Steps: Option 1

Step 1: Set the search expression at the request instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list.

lo_read_list_request->set_search( ‘Peter OR Smith’ ).

 Note
This approach is only supported for remote consumption, not for local consumption

Steps: Option 2

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_search_node TYPE REF TO /iwbep/if_cp_search_node.

lo_search_node = lo_read_list_request->create_search_node( ‘Peter’ ).


lo_search_node->or( ‘Smith’ ).
lo_read_list_request->set_search_node( lo_search_node ).

Step 1: Create the search node on the request instance. For this step, you already provided the first part of your $search
expression (“Peter” from “Peter OR Smith”):

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_search_node TYPE REF TO /iwbep/if_cp_search_node.

lo_search_node = lo_read_list_request->create_search_node( ‘Peter’ ).

Step 2: Insert the second expression (“Smith”) and connect it with “OR” to the first expression:

DATA: lo_search_node TYPE REF TO /iwbep/if_cp_search_node.

lo_search_node->or( ‘Smith’ ).

Step 3: Set the search node in the request:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_search_node TYPE REF TO /iwbep/if_cp_search_node.

lo_read_list_request->set_search_node( lo_search_node ).

This is custom documentation. For more information, please visit the SAP Help Portal 83
10/19/24, 11:40 AM
Negation

Negate the previous expression. For example, this request:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES?$search=NOT (Peter OR Smith)

Call the method "NOT" on the search node instance:

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_search_node TYPE REF TO /iwbep/if_cp_search_node.

lo_search_node = lo_read_list_request->create_search_node( ‘Peter’ ).


lo_search_node->or( ‘Smith’ ).
lo_search_node->not( ).
lo_read_list_request->set_search_node( lo_search_node ).

Connect Two Search Nodes

You can connect two search nodes. For example, this request:

GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/EMPLOYEES?$search=(Peter OR Smith) AND (J

DATA: lo_read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,


lo_search_node_1 TYPE REF TO /iwbep/if_cp_search_node,
lo_search_node_2 TYPE REF TO /iwbep/if_cp_search_node.

lo_search_node_1 = lo_read_list_request->create_search_node( ‘Peter’ ).


lo_search_node_1->or( ‘Smith’ ).
lo_search_node_2 = lo_read_list_request->create_search_node( ‘John’ ).
lo_search_node_2->and( ‘Mary’ ).
lo_search_node_1->and_node( lo_search_node_2 ).
lo_read_list_request->set_search_node( lo_search_node_1 ).

Constraints

$search is only available for OData Version 4 requests.

SET_SEARCH is not supported for local consumption.

Related Information
OData Request Terms

This is custom documentation. For more information, please visit the SAP Help Portal 84

You might also like