Odata
Odata
PUBLIC
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.
This is custom documentation. For more information, please visit the SAP Help Portal 1
10/19/24, 11:40 AM
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:
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:
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.
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.
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.
d. Optional: Go to your outbound service and enter the URL in the field Default Path Prefix.
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:
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>' ).
" 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
This is custom documentation. For more information, please visit the SAP Help Portal 4
10/19/24, 11:40 AM
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.
Context
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.
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
Consumption Types
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.
Use this Client Proxy for the consumption of an OData service that is offered on a remote server.
OData Versions
Use this Client Proxy for the consumption of an OData Version 2 service.
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
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
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.
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:
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.
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:
The mapping from EDM to ABAP names (most importantly for properties)
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.
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
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.
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
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
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
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
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
/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
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
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
Sample Code
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_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).
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.
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
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.
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
/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]).
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:
TRY.
Steps
Step 1: Catch the remote exception and fetch the information on the exception (in addition to your own exception handling):
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.
Step 2: Catch the gateway exception and fetch the corresponding error text (in addition to your own exception handling):
This is custom documentation. For more information, please visit the SAP Help Portal 18
10/19/24, 11:40 AM
Related Information
OData Request Terms
Overview
For information about the Client Proxy Instance, see Client Proxy Instance Types.
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_
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:
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
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.
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
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
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
OData Version 2
Function
Primitive type
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
GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/GetEmployeeByManagerID(ManagerID='0001')
V4 Bound Action
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
{
"TeamID" : "TEAM_02"
}
Version 2 Function
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.
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.
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.
Steps
Step 1: Create the function resource “PROMOTE_EMPLOYEE” with the internal name of function “PromoteEmployee”:
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.
lo_function_resource->set_parameter( ls_parameter ).
This is custom documentation. For more information, please visit the SAP Help Portal 24
10/19/24, 11:40 AM
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:
“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 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):
Step 8: Fetch the business data from the response object (if the corresponding function does return business 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.
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”:
This is custom documentation. For more information, please visit the SAP Help Portal 26
10/19/24, 11:40 AM
{
"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.
lo_action_request->set_parameter( ls_parameter ).
lo_action_request->set_if_match( '1234' ).
lo_action_response = lo_action_request->execute( ).
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.
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’:
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' ).
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,
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:
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):
Step 8: Fetch the business data from the response object (if the corresponding action does return business data):
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.
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.
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
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 Specification
OData Version 2
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
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
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
--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
--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
Version 2
POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/$batch
--batch
Content-Type: multipart/mixed; boundary=changeset
{
"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
{
"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--
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
--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
--batch
Content-Type: multipart/mixed;boundary=change_set_1
--change_set_1
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1
{
"Id" : "TEAM_04",
"Name" : "Test Team"
}
--change_set_1--
--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
lo_batch_request = lo_client_proxy->create_request_for_batch( ).
Step 2: Create the changeset request using the $batch request instance:
lo_changeset_request = lo_batch_request->create_request_for_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:
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( ).
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:
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:
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
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
Each request in a batch request can have an assigned request identifier. The request identifier:
is case-sensitive.
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
POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/$batch
--batch
content-type: multipart/mixed; boundary=changeset
--changeset
content-type: application/http
content-id: 111
{
"Name":"Unit Test Task Force",
"MANAGER_ID":"3",
"BudgetCurrency":"JPY",
"Budget":111100
}
--changeset
content-type: application/http
content-id: 222
{
"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
POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/$batch
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
{
"Id" : 1,
"Name" : "Decimal 10",
"Decimal1" : "1.1000000000"
}
--changeset---
--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json
--batch--
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
--batch
content-type: multipart/mixed; boundary=changeset
--changeset
content-type: application/http
content-id: 111
{
"Name":"Unit Test Task Force"
}
--changeset
content-type: application/http
content-id: 222
{
"MemberCount":42
}
--changeset--
--batch--
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
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:
Step 2: Create the update request instance at the entity resource instance:
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
Step 4: Add the CREATE and UPDATE requests into the changeset request. Then add the changeset request into the $batch
request:
lo_changeset_request->add_request( lo_create_request ).
lo_changeset_request->add_request( lo_update_request ).
lo_batch_request->add_request( lo_changeset_request ).
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 Specification
OData Version 2
The InsertEntity request enables a new EntityType instance with new related entities you add to an EntitySet.
OData Version 4
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
POST /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees
{
"Id" : "007",
"Name" : "James Bond",
"Gun" : "Walther PPK",
"Car" : "Aston Martin DB5"
}
Version 2
POST /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees
{
"Id" : "007",
"Name" : "James Bond",
"Gun" : "Walther PPK",
"Car" : "Aston Martin DB5"
}
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"
}
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’'):
This is custom documentation. For more information, please visit the SAP Help Portal 41
10/19/24, 11:40 AM
Step 2: Run the create request instance on the entity list resource.
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:
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:
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:
lo_create_response = lo_create_request->execute( ).
Step 5: You fetch the business data from the response object:
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 Specification
OData Version 2
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
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
PATCH /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)
{
"Car" : "Aston Martin DB5"
}
Version 2
PUT /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees(‘007’)
{ "Id" : "007",
"Name" : "James Bond",
"Gun" : "Walther PPK",
"Car" : "Aston Martin DB5"
}
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’)
{
"Age" : 38,
"IsManager" : true,
"Status" : "Available"
}
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:
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:
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:
Age AGE
Status STATUS
IsManager IS_MANAGER
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’:
lo_update_request->set_if_match( ‘1234’ ).
Step 5: Run the update request and get the update response instance:
lo_update_response = lo_update_request->execute( ).
This is custom documentation. For more information, please visit the SAP Help Portal 46
10/19/24, 11:40 AM
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 Specification
OData Version 2
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
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’)
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’)
Steps
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:
lo_read_request = lo_entity_resource->create_request( ).
Step 3: Execute the read request and get the read response instance:
lo_read_response = lo_read_request->execute( ).
This is custom documentation. For more information, please visit the SAP Help Portal 48
10/19/24, 11:40 AM
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
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
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
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
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
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:
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:
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
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 Specification
OData Version 2
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
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 /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees(‘007’)
Version 2
DELETE /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Employees(‘007’)
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’:
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”:
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’:
lo_delete_request->set_if_match( ‘mi6’ ).
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.
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 Specification
OData Version 2
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
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 /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
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
GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Employees
Steps
Step 1: Create the entity list resource for entity set ‘Employees’ (with internal name ‘EMPLOYEES’):
Step 2: Create the read list request instance on the entity resource:
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
lo_read_list_response = lo_read_list_request->execute( ).
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
You want
OData Specification
OData Version 2
OData Version 4
You can update entity collections by submitting a PATCH request to the collection's resource path. The body of the request:
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
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
{
"@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"
}
]
}
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
PATCH /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams
{
"@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
Steps
Step 1: Create the entity list resource for entity set ‘Teams’ (with internal name ‘TEAMS’):
Step 2: Create the update list request instance on the entity list resource:
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:
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:
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:
lo_update_list_response = lo_update_list_request->execute( ).
Step 6: Fetch the business data from the response list object:
Constraints
Related Information
OData Request Terms
OData Specification
OData Version 2
Custom Query Options enable you to include data service-specific information in a data service URI query string.
OData Version 4
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
GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?sap-statistics=true
Version 2
GET /sap/opu/odata/IWBEP/TEA_TEST_APPLICATION/Prices?sap-statistics=true
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
GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0003/Teams?sap-statistics=true
Steps
Step 1: Set the custom query option directly at the request instance:
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
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 Specification
OData Version 2
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
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
{
"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"
}
}
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
{
"Id" : "TEAM_04",
"MemberCount" : 2,
"Team2Manager" : {
"Id" : "0009"
}
}
lo_data_desc_node_root = lo_create_request->create_data_description_node( ).
lo_data_desc_node_root->set_properties( VALUE #( ( |ID| ) ( |MEMBER_COUNT| ) ) ).
Steps
Step 1: Creation of the data description node for the root entity (here: “Teams”) on the create request instance:
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”):
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”:
Step 4: Set the properties for the child entity (in this example, “Managers”). Only property “Id” (with internal name “ID” ) is
included:
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):
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:
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 Specification
OData Version 4
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
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).
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’):
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:
Steps
can be used to create a delta request. If the stored delta link was manually changed, the delta link can't be used).
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:
Step 3: Run the delta link request and fetch the corresponding response instance:
lo_read_list_response = lo_delta_read_request->execute( ).
You have an existing request and want to use it in combination with an existing delta link:
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
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.
Note
You can only find and use delta links that you created.
Step 2: Insert the delta link into the existing read list request:
lo_read_list_request->use_delta_link( ‘delta_link_name’ ).
Step 3: Get the read list response instance using the read list request
lo_read_list_response = lo_read_list_request->execute( ).
Related Information
OData Request Terms
OData Request: Read Entity List
Client Proxy Instance Types
OData Specification
OData Version 2
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
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
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
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”):
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
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”):
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”):
Note
You can use the target resource to create an optional READ request.
Related Information
OData Request: Read Entity
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:
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:
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:
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.
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
$expand Option
Use the $expand system query option to represent associated EntityType instance or EntitySet inline.
OData Specification
OData Version 2
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
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
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
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.
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:
Step 3: Set the selected properties (using internal names) on the select node. “ID” is the internal name of property “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
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
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”:
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
lo_filter_factory = lo_read_list_request->create_filter_factory( ).
Step 1: Create an instance of the filter factory at the read list request instance:
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:
Cityname CITYNAME
Location LOCATION
City CITY
lo_filter_factory = lo_read_list_request->create_filter_factory( ).
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:
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’ ) ).
Step 4: Connect the two filter nodes with "and" in the final 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):
lo_filter_node_not = lo_filter_node->not( ).
Constraints
Only these range options are allowed: EQ, NE, GT, GE, LT, and LE.
Only these functions can be used with CP: startswith, endswith, and substringof (for OData Version 2), contains
(for OData Version 4).
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
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
$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
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 /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 /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
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:
Example 1
GET /sap/opu/odata4/iwbep/tea/default/iwbep/tea_busi/0001/TEAMS/$count
Steps
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):
lo_read_list_request-> request_no_business_data( ).
lo_read_list_request->request_count( ).
Step 3: Run the request and fetch the count value from the read list response instance:
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
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).
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
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
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”:
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
Age AGE
Location LOCATION
City CITY
Cityname 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
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
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
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:
Age AGE
Location LOCATION
City CITY
Cityname CITYNAME
Name NAME
( CONV #(
( CONV #('NAME
Related Information
OData Request Terms
OData Request: Create Entity
OData Request: Read Entity
OData Specification
OData Version 2
This is custom documentation. For more information, please visit the SAP Help Portal 80
10/19/24, 11:40 AM
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
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
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
lo_read_list_request->set_skip( 1 ).
lo_read_list_request->set_top( 2 ).
lo_read_list_request->set_skip( 1 ).
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
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
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:
Steps: Option 1
Note
This approach is only supported for remote consumption, not for local consumption
Steps: Option 2
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”):
Step 2: Insert the second expression (“Smith”) and connect it with “OR” to the first expression:
lo_search_node->or( ‘Smith’ ).
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
You can connect two search nodes. For example, this request:
Constraints
Related Information
OData Request Terms
This is custom documentation. For more information, please visit the SAP Help Portal 84