Professional Documents
Culture Documents
OData (Open Data Protocol) is an OASIS standard that defines the best practice for
building and consuming RESTful APIs. OData helps you focus on your business logic
while building RESTful APIs without having to worry about the approaches to define
request and response headers, status codes, HTTP methods, URL conventions, media
types, payload formats and query options etc. OData also guides you about tracking
changes, defining functions/actions for reusable procedures and sending
asynchronous/batch requests etc. Additionally, OData provides facility for extension to
fulfil any custom needs of your RESTful APIs.
OData RESTful APIs are easy to consume. The OData metadata, a machine-readable
description of the data model of the APIs, enables the creation of powerful generic client
proxies and tools. Some of them can help you interact with OData even without knowing
anything about the protocol. The following 6 steps demonstrate 6 interesting scenarios
of OData consumption across different programming platforms. But if you are a nondeveloper and would like to simply play with OData, XOData is the best start for you.
Now you all have a basic understanding of what Gateway is, youre ready to get on
with the fun bit!
Chose a project name, give your project a description and select Standard
generation strategy.
In my example I will be creating the service as a local object.
Enter the name of the ABAP Dictionary Structure you want to use, and hit enter. In
our example we are using SCARR.
Enter an Object Name, this will be the name of your entity. Select any fields to not
include (ignore) and ensure the correct key is selected.
example is Carriers.
It is best practice for the model provider class name to end in _MPC and the data
provider class to end in _DPC. The extension classes of these should be named the
same as their corresponding base class, with the additional suffix of _EXT.
Generating can take a few moments, so dont worry if it isnt instant. Once it is
complete you will see a detailed log of successes, warnings and errors. If you have
done everything right this should be all green.
Hit save and navigate back to the Activate and Maintain Services screen. Scroll
down the list of services to find your one.
We now want to see if our service is accessible from the web, to validate whether
we have set it up correctly.
Click the Call Browser button in the bottom left section of the screen.
If your call was successful you will see something like this:
Here we can see our Carrier entity, with its properties, and the fact that there is an
entity set associated with this entity.
If we change the URL again to end in /Carriers?sap-ds-debug=true we will see this
error message:
This is because we havent yet told our service how to read Carrier information from
the SCARR database table.
This then takes you into the ABAP Class where you will need to build your
implementation.
Click on display object list
Find the CARRIERS_GET)ENTITYSET method of the left hand side, right click on it,
and chose Redefine.
As you can see we now get a stream of information back, detailing all the Carriers
stored in the SCARR table in ERP.
One airline carrier has many flights, but each flight has only one airline carrier.
Generate.
Now we need to modify the ABAP so that when we ask for a list of flights for a
specific carrier we dont get back all the flights, we just get back those relevant to
us.
Navigate to the ABAP method FLIGHTS_GET_ENTITYSET.
Change the code to read:
data: ls_key like line of it_key_tab.
read table it_key_tab into ls_key with key name = 'Carrid'.
* If there is a carrier ID specified, use it to select only those for the specific
carrier
if sy-subrc eq 0.
select * from sflight into corresponding fields of table et_entityset
where carrid = ls_key-value.
* If there is no carrier specified, read all the flights
else.
select * from sflight into corresponding fields of table et_entityset.
endif.
IT_KEY_TAB is importing parameter of the method which will hold all keys which
have been passed in. In our example it will contain a carrier ID f the navigation is
from Carrier, because Carrid if the key of the Carrier entity.
10. Wrap up
Congratulations, youve just built your first, easy Gateway service. Obviously this
post does not go into the complexities of building a Gateway service, but I hope it
has given you an idea about where to begin.
For some interesting insights around, and beyond this topic its worth checking out
the following: