Odata
Odata
Odata
Ans. OData is abbreviation form of “Open Database Protocol”. OData is open source
interface that can be consumed by any program, platform, application, software and device
of the Non-SAP world that can connect with SAP using the HTTP(s) protocol.
4. What is ODBC ?
Ans. ODBC stands for Open Database Connectivity. ODBC is a standard API to access the
Data Base. OData acts like middleware between producers and consumers to communicate
data. It’s a uniform way to consume data.
Decouples the data provisioning from the UI designer by providing a bridge between SAP
developers and UI designer(non-SAP developers) • It supports multichannel access to SAP
data as it is supported by multiple platforms • The standard address representation or
resource is the URI (Uniform Resource Identifier) and all players can easily access it.
• XML-based Atom Pub format and the JSON format is popular industry-wide used formats
which OData supports. This makes it easy to learn, understand, connect and consume.
• OData messages are self-describing and hence all non-SAP developers are able to understand
the content of the OData message without the need to have any knowledge of how SAP ERP
system works.
• There is no expense associated with the use of OData. It is open and anyone can use it with
no cost or license agreement.
• OData is extensible.
Ans - OData is used to define best practices that are required to build and consume RESTful
APIs. It helps you to find out changes, defining functions for reusable procedures and sending
batch requests etc. OData provides facility for extension to fulfill any custom needs of your
RESTful APIs.
The OASIS OData Technical Committee has published the latest OData 4.01 draft as a
Committee Specification.
14. What is Entity type and Entityset? What is the difference betweenthem?
Ans : Entity type is the category of a particular entity in the table of an RDBMS; in contrast,
entity set refers to the collection of all entities of the same entity type in RDBMS.
The main difference between Entity Type and Entity Set is that Entity Type refers to the
category an entity belongs to while Entity Set refers to all the entities of an entity type.
Ans : Complex types define the structure of the messages and elements in the message
model. By combining elements, attributes, groups and wildcards, almost any message structure
can be modeled.
Entity types
Entity types are named structured types with a key. They define the named properties and
relationships of an entity. Entity types may derive by single inheritance from other entity types.
The key of an entity type is formed from a subset of the primitive properties (e.g. CustomerId,
OrderId, LineId, etc.) of the entity type.
Complex types
Complex types are keyless named structured types consisting of a set of properties. These are
value types whose instances cannot be referenced outside of their containing entity. Complex
types are commonly used as property values in an entity or as parameters to operations.
17. What is Function import? When should we opt for function import?
Ans :Function Imports are the actions like the release of a sales order/purchase order
executed in the back-end system. They can be used whenever the given requirement does
not fit into the CRUD-Q operations.They are defined at the service level and you can have N
number of function imports functions.
a. Go to Gateway Service Builder SEGW and choose the project in which you want to create
Function Import.
c. Specify the name of the function import and click on green tick mark button.
d. In the next screen you will find different options for the Function Imports lets have a look
at each of them.
If you want the function import to return data you can set this field. We have 3 possible options
available
Complex Type – if the return data is of complex entity type, select this option
Entity Type – if the return data is of entity type, select this option and
Return Type:
This field depends on the option you have choose above. You need to specify the name of the
type in this field. Use the input help to choose from existing types or create a new type.
If you choose Complex Type in the above step, specify the name of the complex
entity type in this field.
If you choose Entity Type option in the above step, specify the name of entity type.
If you choose No return, this field will be empty.
Why should we opt this :This is actually a reasonable reason if your module only requires the
user to have a certain module installed if they use specific functions of yours... If that's not he
reason you're doing this, it's almost certainly a yucky idea. It imports once when the function is
called for the first time.
Ans - An association is defined between entity types, Designer creates and displays the OData
navigation elements under the corresponding entity types.
An association set is a logical container for association instances of the same type. An
association set is not a data modeling construct; that is, it does not describe the structure of
data or relationships.
Navigation properties in OData are the reference attributes of an entity that points to another
entity. By default, navigation properties are not available on an entity representation when it is
accessed by an OData client.
19. How do I create an OData navigation in SAP?
Ans - Association and Navigation in OData Service
Ans : Association and Navigation are two important properties available in SAP OData Service
to associate two entity types. Let us understand this with an example, in our earlier tutorials we
retrieved sales order header data and item data in two different entity types “ SalesOrderSet ”
and “ OrderItemsSet”.
Principal Entity- Scarr and the target/dependent entity- Spfli. And also provide the Navigation
Property Name. The below screen appears, now we have to maintain the match up fields. For
dependent entity, from F4 provide dependent property as Carrid. Create association set, than
links the entity sets. Choose Finish.
If the navigation source or part of binding path is in the path, we need it passed to the
constructor of ODataQueryOptionParser. So there are 2 overloaded constructor added to
accept ODataPath as parameter. Note: Parameter IServiceProvider is related to Dependency
Injection.
Association and Navigation are two important properties available in SAP OData Service to
associate two entity types. Let us understand this with an example, in our earlier tutorials we
retrieved sales order header data and item data in two different entity types “ SalesOrderSet ”
and “ OrderItemsSet”.
Ans : Referential constraints are optional and can be defined in CREATE TABLE statements and
ALTER TABLE statements. Referential constraints are enforced by the database manager during
the execution of INSERT, UPDATE, and DELETE statements. The enforcement is effectively
performed at the completion of the statement except for delete and update rules of RESTRICT
which are enforced as rows are processed.
Referential constraints with a delete or update rule of RESTRICT are always enforced before
any other referential constraints. Other referential constraints are enforced in an order
independent manner. That is, the order does not affect the result of the operation. Within an
SQL statement:
A row can be marked for deletion by any number of referential constraints with a delete
rule of CASCADE.
A row can only be updated by one referential constraint with a delete rule of SET NULL
or SET DEFAULT.
A row that was updated by a referential constraint cannot also be marked for deletion
by another referential constraint with a delete rule of CASCADE.
Ans : Function Imports are the actions like the release of a sales order/purchase order executed
in the back-end system. They can be used whenever the given requirement does not fit into the
CRUD-Q operations.
They are defined at the service level and you can have N number of function imports functions.
a. Go to Gateway Service Builder SEGW and choose the project in which you want to create
Function Import.
b.Expand the project, right click on Data Model and choose Create and the Function Import.
c. Specify the name of the function import and click on green tick mark button.
d.In the next screen you will find different options for the Function Imports lets have a look at
each of them.
Model Provider class registers the metadata used in a service. Data provider class provides the
methods to Data provider Extension class, so developer can implement the functionalities for
database interaction.
35. What is the difference between model provider and data provider class?
Ans : Model Provider class registers the metadata used in a service, it is nothing but
base class and model provider extension class is nothing but derived class. Data provider
class provides the methods to Data provider Extension class, so developer can implement the
functionalities for database interaction.
36. What is Metadata? How to download Metadata?
Ans : The metadata document is a static resource that describes the data model and type
system understood by that particular OData service. You can use the metadata document to
learn how to query and navigate between the entities in the system.
==> Specify the link to the OData service in the next pop-up. In this case I am using the
publically availaible Northwind OData Service. You can also take up your own OData service by
providing necessary authentication details in the same popup. Then click Next
==> The wizard will fetch all the Entity Sets contained in the OData service. Select the one
which you want to download to Excel. I selected PersonDetails here.
==> Click Finish and you will be asked for how you want the data to be displayed in Excel.
==> Select table and click OK. Wait for some time while your data is downloaded.
The data from the OData service is now availaible in Excel 🙂
This functionality also works fine for HANA Exposed OData services (xsodata).
An HTTP response object typically represents the HTTP packet (response packet) sent back by
Web Service Server in response to a client request. An HTTP Response contains:
1. A status.
2. Collection of Headers.
3. A Body.
the validation of an HTTP response status will be dealt with in three parts as follows:
Ans : The Open Data Protocol (OData) includes standard CRUD (Create, Retrieve, Update, and
Delete) operations that map to the HTTP methods POST, GET, PUT/MERGE, and DELETE.
Ans : The OData service interface has a fixed number of operations that have uniform meaning
across all the resources it can act on. These operations are retrieve, create, update and
delete and they map to the GET, POST, PUT/MERGE and DELETE HTTP methods. Each of them
acts on a resource that is indicated using a URI.
44. Which method used to trigger a request to the function import OData service?
Ans : OData query option $expand is used to read multiple entities or entity sets in a single
service call instead of two different calls. Prerequisite, entity sets which are used should be
associated. To know about Association in OData service click here.
Ans : OData requires asynchronous data retrieval: Synchronous data access requires that data
has already been loaded from the server. This means there is no way of knowing whether this
already happened, meaning the result of a synchronous access method is quite often
unpredictable.
47. What is REST API in OData?
Ans : REST stands for REpresentational State Transfer which is a resource based architectural
style. Resource based means that data and functionalities are considered as resources. OData is
a web based protocol that defines a set of best practices for building and consuming RESTful
web services.
Ans : An OData Metadata Document is a representation of a service's data model exposed for
client consumption. The central concepts in the EDM are entities, relationships, entity sets,
actions, and functions.
Ans : There are 5 methods associated with each entity set. As a whole, there are 5
operations(CRUD-Q) in OData that are as shown below and mapped to HTTP methods. But for
now, we will check the GET Operation which is also known as single read operation. Read
operation is used for Reading a single record.
Ans : Go to Tcode '/IWFND/ERROR_LOG' to see all the errors that occurred in your Gateway
system. Click on a particular error. In the below pane you see a button called Replay, and select
'Gateway Client' there.
Whenever the given requirement does not fit into the crud operations, that time we will go for
Function import in OData. function imports are used to do the GET and POST operations for the
requirements , which are not possible by the standard operations available in OData
52. Mention different status codes you have came across in OData?
53. What are the status codes for Create, Update, Delete and Getoperations?
Ans : For a PUT request: HTTP 200 or HTTP 204 should imply "resource updated successfully".
For a DELETE request: HTTP 200 or HTTP 204 should imply "resource deleted successfully".
CREATE
The create action is usually implemented via HTTPs POST method. In RESTful APIs, these
endpoints are used to create new resources or access tokens.
Status Codes
200 OK - It’s the basic status code to tell the client everything went good. Since we don’t create
endpoint accessible resource when creating an access token, we can use 200 as a status for
that action.
201 Created - The most fitting for Create operations. This code should signal backend-side
resource creation and come along with a Location header that defines the most specific URL for
that newly created resource. It’s also a good idea to include appropriate representation of the
resource or at least one or more URLs to that resource in the response body.
202 Accepted - Often used for asynchronous processing. This code tells the client that the
request was valid, but its processing will finish sometime in the future. The response body
should include an URL to the finished resource with some information about when it will be
available, or an URL to some monitoring endpoint that tells the client when the resource is
available.
303 See Other - Like the 202 code but using a Location header field in response to informing
the client about the location of the created resource or an endpoint that lets the client check
for the status of the creation process. Some clients follow the status codes of the Redirect-class
automatically. This code is usually only used for POST requests.
READ
The read action gets implemented via HTTPs GET method and used to fetch resource
representations. Asynchronous responses aren’t much of a thing here, because the reason for
asynchronous processing is often that the resource doesn’t exist yet and has to be created, so
it’s a create action anyway.
Status Codes
200 OK - Most of the read actions will be answered with a 200 OK status.
206 Partial Content - This code is useful for lists of content that are too big to be delivered in
one response. It has to be used with a Range header field in the request. Usually, this header
field defines the byte-range the backend should send to the client, but the unit can be freely
assigned as long as both sides understand it.
300 Multiple Choices - This redirect is used if there are multiple representations for one
resource and the client (or its user) has to choose one of them.
308 Permanent Redirect - This tells the client to use another URL to access the resource and
not use the current URL anymore. It’s helpful when we have multiple endpoints for one
resource, but don’t want to implement reading from all of them.
304 Not Modified - Is used like 200 but without a body, so the client will be redirected to its
locally cached representation from a previous read.
307 Temporary Redirect - When the URL to a resource could change in the future, and the
client should always ask the current URL before accessing the real one.
UPDATE
An update can be implemented with an HTTP PUT or PATCH method. The difference lies in the
amount of data the client has to send to the backend.
PUT requires the client to send an entire representation of a resource to update it. (Replace the
old one with the new one)
PATCH requires the client only send parts of the representation of the resource to update it.
(Add, update or delete these parts in the old version)
Status Codes
200 OK - This is the most appropriate code for most use-cases.
204 No Content - A proper code for updates that don’t return data to the client, for example
when just saving a currently edited document.
202 Accepted - If the update is done asynchronous, this code can be used. It should include an
URL to access the updated resource or an URL to check if the update has been succeeded. It
can also include an estimation of how long the update will take.
DELETE
The delete action can be implemented with the HTTP DELETE method.
Status Codes
200 OK - Some people think a delete function of any kind should return the deleted element, so
a representation of the deleted element can be included in the response body.
204 No Content - The most fitting status code for this case. It’s better to reduce traffic and
simply tell the client the deletion is complete and return no response body (as the resource has
been deleted).
202 Accepted - If the deletion is asynchronous and takes some time, which is the case in
distributed systems, it can be appropriate to return this code with some information or URL to
tell the client when it will be deleted.
API Changes
If our API lives long enough, sooner or later it will change its structure. It’s best practice to
avoid breaking changes and the redirection class of status codes can help with this because
some clients follow their Location header automatically.
Status Codes
307 Temporary Redirect - This is the right code if the resource could be available on a different
URL in the future, but we want the current endpoint to control where the client is redirected
to. This status code will let the client come back to the current URL for every request.
308 Permanent Redirect - This is the right code if the resource will now be available at a new
URL and the client should directly access it via the new URL in the future. The current endpoint
can’t control the clients’ behavior after the request and a subsequent redirect if the resource
URL changes again have to be issued from the new URL.
Multiple Endpoints for One Resource
If we opt-in to use nested or sub-resources in our API it can help to only deliver representations
from root (non-nested) resources to keep the implementation DRY. Redirect status codes help
with this.
Status Codes
308 Permanent Redirect - If we have nested
resources /user/kay/comments/456 and /posts/123/comments/456; and a root
resource /comments/456 it can make things easier to simply issue 308 redirects at the nested
resources with the Location header field pointed to the root resource so not every endpoint
needs a delivery implementation. This should only be done for GET requests.
Errors
The next important part of an API is its errors. Many API frameworks use 500 and 404 status
codes by default when something went wrong, but depending on the situation, often there are
more descriptive ones.
500 means Internal Server Error, which can be anything from a missing header field the
backend accessed without checking its existence to an unreachable third party service the
backend wanted to call.
So it can be that the client did something wrong and we would expect a 400-499 status code,
but the backend never tried to validate the request and tried to process it even if it was invalid
and we end up with a server error.
404 means Not Found. This can be because of a wrong URL used by the client to some endpoint
not being set up right on the backend.
As we see the 404 is a client error status code, but it could very well be that we did something
wrong on the backend.
Wrong URL
When a client sends a URL, we don’t know. This can have multiple different reasons, so we have
to check which of them applies here.
Status Codes
404 Not Found - This is the most natural of responses and should be used in the case
that the client URL was wrong.
405 Method Not Allowed - In many frameworks we define the URL alongside the HTTP
method, so removing one of these definitions could leave all but one methods to one
URL intact. The response has to include an Allow header field that lists what is allowed
to do.
501 Not Implemented - Like 405, but the method is missing for all resources on the
backend.
406 Not Acceptable - The URL exists, but the backend can’t send a representation the
client will accept. So for that specific client, the URL behaves like a 404, but they now
know that they need to update the client.
410 Gone - This is like 404 but we know that the resource existed in the past, but it got
deleted or somehow moved, and we don’t know where.
414 Request-URI Too Long - This is sometimes the case when the endpoint is right, and
the resource exists, but the query makes the URL too long to be interpreted.
308 Permanent Redirect - This would be the right code if we know that a resource has
moved to a different URL and we can tell the client about it.
307 Temporary Redirect - Same as 308, but we don’t know if the resource will be back
on the original URL or another different URL in the future.
No Permissions
Often clients can’t access every resource on the backend, so we need a way to tell them about
it.
Status Codes
401 Unauthorized - The client hasn’t authorized itself to the backend yet and the server
may give it access after that has happened.
403 Forbidden - The client has authorized or doesn’t need to authorize itself, but still has
no permissions to access the resource.
404 Not Found - If 401 or 403 is the case, but the backend doesn’t want to tell the client
that the resource exists for security reasons.
The query options part of an OData URL specifies three types of information: System query
options, Custom query options, and Parameter aliases.
Expand
The $expand system query option specifies the related resources or media streams to be
included in line with retrieved resources. Each expandItem is evaluated relative to the entity
containing the navigation or stream property being expanded.
Select
The $select system query option allows clients to request a specific set of properties for each
entity or complex type.
The $select query option is often used in conjunction with the $expand system query option, to
define the extent of the resource graph to return ($expand) and then specify a subset of
properties for each resource in the graph ($select).
OrderBy
The $orderby system query option allows clients to request resources in a particular order.
The $top system query option requests the number of items in the queried collection to be
included in the result. The $skip query option requests the number of items in the queried
collection that are to be skipped and not included in the result. A client can request a particular
page of items by combining $top and $skip.
Count
The $count system query option allows clients to request a count of the matching resources
included with the resources in the response. The $count query option has a Boolean value of
true or false.
Search
The $search system query option allows clients to request items within a collection matching a
free-text search expression.
The $search query option can be applied to a URL representing a collection of entity, complex,
or primitive typed instances, to return all matching items within the collection. Applying the
$search query option to the $all resource requests all matching entities in the service.
If both $search and $filter are applied to the same request, the results include only those items
that match both criteria.
Custom query options
Custom query options provide an extensible mechanism for service-specific information to be
placed in a URL query string. Custom query options MUST NOT begin with a $ or @ character.
Parameter aliases
Parameter aliases can be used in place of literal values in entity keys, function parameters, or
within a $filter or $orderby expression. Parameter aliases MUST start with an @ character.
Conventions
A request to a resource using Http verbs GET, PATCH or PUT follow these conventions:
Resource paths identifying a single entity, a complex type instance, a collection of
entities, or a collection of complex type instances allow $compute, $expand and
$select.
Resource paths identifying a collection allow $filter, $search, $count, $orderby,
$skip, and $top.
Resource paths ending in /$count allow $filter and $search.
Resource paths not ending in /$count or /$batch allow $format.
Query options for a POST operations may differ due to the type of object being
returned in the response. If a POST returns a single entity vs collection of entities,
it will impact the query options that are applicable to the request.
An OData server consists of OData Producers and an HTTP server. In SQL Anywhere, an OData
Producer is a Java Servlet that uses the JDBC API to connect to a database server. An OData
Producer processes OData requests and interfaces with the database.
The $expand query option is very powerful and allows us to provide multiple entities and/or
entity sets in one single service call, instead of performing several calls subsequently.
111. What all folders contains Data Model in SAP Gateway hub system ?
Ans. A. Entity Types
B. Associations
C. Entity Sets
112. What is Embedded deployment ?
Ans. Embedded deployment means that the services are registered and published in the SAP
Business Suite backend system.
113. What is HUB Deployment ?
Ans. HUB Deployment (Development on Backend System) means Services are deployed on the
backend systems and only registered on the server.
126. What is transaction code to check if your system has SAP Netweaver Gateway ?
Ans. SAP_GWFND