OData Concepts
OData Concepts
SAP Netweaver Gateway (blue box within Application Layer in the below
picture) is a technology platform that seamlessly connects devices,
platforms and environments to SAP Enterprise Data using the OData
services.
What is RESTful?
Ans: OData is REST-inspired technology for reading, writing, and modifying
information on the Web (not just
SAP). REST = REpresenational State Transfer. REST is an architectural
style that uses simple and lightweight mechanism for inter-machine
communication. It is an alternative to the RPC (Remote Procedure Calls) and
Web Services. REST is Resource-based, unlike RPC or SOAP which are Action-
based.
Here are roughly summarized the key differences between RESTful and
RESTless web services (it does not have to be strictly valid):
1. Protocol
RESTful supports various data formats such as HTML, JSON, text, etc,
RESTless supports XML format.
5. Flexibility
REST services are called as REST services because the Services are really
working with Resources instead of Operations. Any communication between
client and services are using URI (Unified Resource Identifier) over HTTP
protocol using HTTP method. The URI is really the representation of the
Resources (like POHeader, POItem, Customer, Vendor etc). Also, in RESTful
service, once you identified the Resource, you will be working with a uniform
interface, because it uses HTTP methods (GET, PUT, POST and DELETE) to work
with the resource. So, the client does not need to know what the exact operation
name defined in the service contract to call that method. GET method is used
whenever we need to get the representation of an existing resource. POST is
used to add new resource into the system. PUT is to modify the existing
resource and DELETE is to remove the resource from the system. No matter
what is the Service in whatever Platform, GET, PUT, POST, DELETE remains the
same.
/sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$filter=ProductId eq ‘HT-
1000’.
IW Stands for "Information Worker". Name for the team within SAP which developed Gateway.
Service Builder
once you create a project, you will get the details of the project
Let’s create a data model first – there are a couple of ways to create
an entity type and entity set, You can create an entity type and
entity set manually by adding individual fields and its
properties/attributes
Upon generation -> it will ask for names for the Runtime artifacts
Apart from these four classes, there is a technical service
name(ending with SRV) and model(MDL) name generated which is
used for service registration purposes.
Unit Conversion in ODATA
Unit conversion in OData services can be achieved by using the $filter query option to convert units
within the service. For example, to convert miles to kilometers, you can use the following query:
Alternatively, you can also use the $expand query option to retrieve related units
and their values. For example:
GET /odata/service/Entities?$expand=RelatedUnits
This will return the entities with their related units and their values. With the help
of these query options, unit conversion can be achieved within the OData service.
- `$skip`: Specifies the number of items to be skipped in the response before returning the requested
subset of data.
For example, a client can request the first 50 items by setting the `$top` parameter to 50, and then
request the next 50 items by setting the `$skip` parameter to 50 and `$top` to 50.
The OData service then processes these parameters and returns the requested subset of data to the
client, allowing for efficient retrieval and processing of large datasets.
$batch request is useful to group multiple requests and sends a batch to the data service in
a single HTTP request.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM and
lv_filename = <fs_key>-value.
ls_stream-value = ls_upld-value.
ls_stream-mime_type = ls_upld-mimetype.
copy_data_to_ref( EXPORTING is_data = ls_stream
ENDIF.
lw_file-filename = <fs_key>-value.
lw_file-value = is_media_resource-value.
lw_file-mimetype = is_media_resource-mime_type.
lw_file-sydate = sy-datum.
lw_file-sytime = sy-uzeit.
/sap/opu/odata/sap/ZDEMO_FILE_SRV/FileSet(lor.jpg)/$value
Browse your local file system and select your file. Once you upload the file SAP with automatically
change the HTTP method as PUT . Execute the method. lor.jpg file got uploaded with ~status_code =
204.
File got updated in Z table
9) To download the file, just change the HTTP method to GET and execute. Program will read the
Here we are passing lor.jpg so GET operation will download the file we uploaded in Z table.
Similarly you can upload any file type to the Z table and can download them. In my next blog I will