Creating an OData Service with SAP

Creating an OData service with SAP is not complicated. The first step is to determine what data you want to work with. That is based on your application. For our purposes, we will use the sample data that is included with SAP.  This is the airport related data. If you do not have this data in your system, then please follow the tutorial located at  The main way to get this data into your system is to run t-code SAPBC_DATA_GENERATOR.  It may be useful to you as well to review the Flight data model while you are designing your application. You can find the data model at

In short, here are a list of the main tables in the Flight data model:

T000 – Client table
SCURX –  Currencies (key: currency key)
SBUSPART – Business partner (key: client, partner number)
STRAVELAG – Travel agencies (key: client, travel agency number)
SCUSTOM – Customers (key: client, customer number)
SCARR – Carriers (key: client, carrier ID)
SCOUNTER – Sales counters (key: client, carrier ID, sales counter number)
SPFLI – Flight schedule (key: client, carrier ID, connection number)
SFLIGHT – Flights (key: client, carrier ID, connection number, date of flight)
SBOOK – Flight bookings (key: client, carrier ID, connection number, date of flight, booking number, customer number)

Let’s consider the customers table (SCUSTOM).


In this table we have basic data such as customer id, name, title and address information. This is a simple and straightforward set of data.

We then need to model this data. This is done through using t-code – SEGW. If you run it for the first time, it will take a moment to compile. You are then presented with the SAP NetWeaver Gateway Service Builder.


Click the new button to create a new project. Before creating this I created a package called ‘ZODATA’ that I could use to assign this project to. You can create a new package using SE80. Then you should see a screen like this when you are done creating your package.


Here is where we will model our data using different modeling types. Next, click on Data Model > Import from DDIC structure.  Once you go through the setup, you will see this screen. That was super easy, wasn’t it.


Next, then you have to create an entity set representing your customers object. You do this under the EntitySet area below. Your screen should look like this:


Next, we are going to generate runtime objcts for our application. This action creates the code that runs behind the scenes. Right click on the project at the top and choose “Generate Runtime”.


After generating the runtime you will see this screen:


Hopefully this is all starting to make sense at this point. The system is modeling the data and then also generating the classes to handle the mapping of the data and updating as well. This is similar to what .Net does through some of its wizards. If all goes well after you pick your package, you will see the following:


That will provide the basic architecture for the underlying service. However, in order to tie it all together, we need to update the generated classes that were created. We need to modify the ZCL_ZODATADEMO_DCP_EXT class. Using the runtime generator saves a lot of coding time but it doesn’t completely eliminate it in all circumstances. Just take a look at all of the methods that were generated in this class:


There were a ton more that I did not list. It makes it a bit easier if we just look at the methods on the object through this navigation:


So now looking into these methods, if we pick the first one, CUSTOMERSET_CREATE_ENTITY, we can see it doesn’t have an implementation yet.



We now have to implement the code to handle this. We do that with the following code:

Then let’s change the get entity method:

We won’t be able to see this service until we register the service. We do this with the t-code /IWFND/MAINT_SERVICE. When you run this, choose the system alias of ‘LOCAL’. I had to do that to get my service to show. Once you do, you will see this screen:


Next, click on the service and then you will see the following screen:


You will see the following screen:


Then we are pretty much done. Then if we go back to /IWFND/MAINT_SERVICE we can see our service listed at the bottom:


And now we are ready to test the service. We can do that by going to this url: http://<server>:<port>/sap/opu/odata/sap/ZODATADEMO_SRV/?sap-client=001&$format=json.