Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member524141
Participant
61,838
There are plenty of articles on the internet about the creation of Odata Services.

But when I started learning to create Odata services I faced a lot of challenges,

so I decided to start this blog post so that I can pass on the information which I collected through my experiment.

In this series of Odata and UI5 blog posts I will be sharing my development experiences, challenges and different tips and tricks which I learned through a lot of internet searches.

My only motto will be to save time and efforts of many developers who are searching for a solution for their problem, which has either already appeared/solved by someone else.

If you have any question/query regarding this blog post or anything related to Odata, ABAP, JAVA, Android or any other technology, post a comment I will try to answer it.

 

Let's start Odata creation now -

Steps to create first Odata Service –

1. Open T-Code SEGW Click on create a new project.



Provide the name of your project and a project with the following structure gets created.



Data Model: It contains three subfolders.

Entity types: Entity types are like ABAP structures. We add all fields which are required in Entity Types.

Associations:  We will come to this later.

Entity Sets: This is similar to ABAP internal tables, used to hold data for our Odata services. Now we will create a new entity type and add fields to this entity.

Right-click on entity type folder and choose to create. Provide the name of the entity type in the popup.

Select checkbox “Create Related Entity Set”, this will create a related entity set (internal table).

Unselect this checkbox only when you are sure that we won’t be requiring an entity set (internal table) in our Odata.

Two new subfolders are created under our entity type. Properties and Navigation.



Double click on properties, here we add the fields to our entity type. Click on below button and create, add and delete new fields as per requirement.



Now you must be wondering when we are developing any OData service in our project, are we going to add fields in entity types one by one. The answer is NO.

We have the option to import structures from DDIC, File, RFC or search help. Instead of having to add fields one by one we will import the required structure from DDIC for the scope of this blog.

Let’s create our Entity type again, this time we will choose the import option.

Now we have a pop-up with 3 steps as below.

Step1:

Provide name of the entity type and the structure from which we are importing fields.

Click on Next.

Step 2: In this pop up we can see EKKO structure and all of its fields.

We can now select fields which are required in our service and click next.

Step 3:

In the 3rd screen of the wizard all the selected fields are displayed.

Now we have to choose the key fields for this structure. This is same as choosing the primary key for our table.



I choose EBELN as key and click Finish.

Now our entity type POHeader has been created.

Now have a look at our project structure.

We have our entity structure under Properties of the entity type.

And under the service maintenance folder, we have all our CRUD operations.

Now let’s create one more entity type following the same procedure, this time we will create POItem from EKPO.

Now if you will go through the project structure you will find that each entity type has separate Properties folder and each entity set has its own CRUD operation under service maintenance.

Now, we have Purchase Order header and Purchase Order Item entity type i.e, structure and entity set i.e, internal table ready.

So let's generate and register our service. Click on generate button and below pop up comes.



These are our generated classes, in which we will write our custom code to fetch data according to our requirement.

Let's skip that for now and click OK.

Check for successful generation of service and model.

Now our Odata Service has been created successfully.

Now we need to register this service so that other application can use this service.

For this first, we will have to check our system configuration for embedded or hub deployment.

In case of embedded deployment, front end server (ex: FIORI server) and backend ABAP server are on the same system.

And in the hub system, they are on a different system.

We register our Odata in the system where it will be used, so in embedded it will the same system and in the hub, there will be another system.

In embedded system Go to your Gateway Hub (Front-end system) and execute t-code /n/IWFND/MAINT_SERVICE. Click on Add services:



Provide system alias name (if you do not know the system alias name please check from SPRO) and click on Get Services

Now all the services which are available in the given system will be displayed here.

You can provide the service name in External Service Name to directly go to your service.

Now select your service and click on Add selected Services

Provide package name or choose local on next screen based on your transport requirement and click OK



Your service has now been created.

Now if you will go back to service catalog screen you will find your service has been added there.



Now click on SAP Gateway Client after selecting your service to go to gateway client and actually test your service.

Click on execute button and you can see your first created Odata in action.



Note: If you do not get status 200, check status number
403 – Forbidden
500 – Internal Server Error
Let me know in comments and we will try to resolve them.

If you want to see your output in JSON, just $format=xml to $format=json.



PS: How to check if you get any errors while executing Odata.

Go to /IWFND/ERROR_LOG and here you will find a detailed description of the error, google them and try to resolve. Or post them in the comment below and we will have a look together.

Now the last part: We only got the structure of our Odata, you must be thinking about how do we fetch data from our database tables.

Now, let’s go to the part which we skipped earlier, to our auto-generated MPC and DPC classes. Now go to Service Implementation folder on created service.

Right-click on GetEntitySet and Goto ABAP Workbench. We will only edit classes which have _EXT at the end, not the base classes, this is because base classes get overwritten whenever you regenerate the service.

 



Now click on Entity type Get EntitySet Method and redefine it.

Write below code in your method and activate.
  SELECT *  from ekko into CORRESPONDING FIELDS OF TABLE et_entityset up to 5 rows. 



Now again run your service from now you should have the data.

We have our first Odata created and we fetched data from the database table.

We have much more to learn Odata and UI5, stay tuned I will bring in more content for you.
11 Comments
Former Member
Thank you Ravi for keeping it easily understandable and simple.

Chill,

Jakes
Jelena_Perfiljeva
Active Contributor
It's nice of you to share your experience but it's not clear what does this blog add to this subject. As you've mentioned, there are already many posts on this, so what compelled you to write another one?

Our team just started working with Gateway this year and I did a lot of online research on this subject. There is at least a dozen of SCN blogs already (Exhibit A and Exhibit B just from the top of the list) that explain the same steps with the same screenshots and level of detail. I'm guessing your next post would cover adding more code? Well, that's already been covered in many other blogs too (Exhibit C and Exhibit D).

For someone searching for information finding many blogs with almost the same text on the same subject is, unfortunately, not helpful at all. It's actually very frustrating and you feel like you're going in circles.

Of course, even if there are already 100 blogs written about something it doesn't mean that no one is allowed to write the 101st one. The problem starts when the writer does not take the 100 previous blogs into consideration and doesn't offer anything different to the readers.

For example, you've mentioned "I faced a lot of challenges" but what were they? Why did you start this and what were you trying to achieve? Then you're promising to share your experience, "tips and tricks" etc. but the blog is just a collection of "do this" steps and screenshots. There is no overview of what this service will achieve, no explanation why these steps and no actual tips, from what I see.

Also, such material is clearly meant for the beginners but then it just skirts some topics. The description of service registration process could've been more clear and concise. It includes some confusing statements and vague instructions ("check alias in SPRO" - where exactly? SPRO is huge!). There is no explanation of the Gateway client, what URI is/does or why did you decide to redefine "Get EntitySet" method and not some other, etc.

You might want to review this from the reader perspective and add more details as well as your personal experience. E.g. if you read something in another blog and that was difficult to understand then share that with the readers. Don't just repeat the same "step by step with screenshots", add something.

Thank you.
former_member524141
Participant
Thanks jelena.perfiljeva2 for the suggestions, they are really helpful.

As mentioned, this blog series is aimed for beginners only so I have tried to keep it simple. I am a very slow leaner, so just helping learners like me.

Stay tuned, for more basic and simple posts.
former_member524141
Participant
0 Kudos
Thank you Former Member.

Stay tuned for more content.
former_member719298
Discoverer
0 Kudos
Very Nice Blog
Freeter
Product and Topic Expert
Product and Topic Expert
Nice blog! Thanks.

Nice blog..I really appreciate..Thank you so much..

ZenonK
Active Participant
Thanks..  Keeping it simple 🙂
Mandeep_Rait
Newcomer
I found it really helpful to understand the basic in one go!
Vatsalsaxena
Explorer
0 Kudos

Very well Explained...

SunilGupta
Explorer
0 Kudos

This approach shouldn’t be used as this uses obsolete way of creating ODATA (SEGW Based). ODATA should be created based on CDS views (RAP Approach). 

Labels in this area