Skip to content

Example of ODATA service (full package) which can be added by `abapGit` to your local or cloud SAP instance. ODATA service has name `ZML_TRAVELLING_ODT` and demonstrates full CRUD and `deep insert` methods by SEGW project.

License

Notifications You must be signed in to change notification settings

lukcad/ZMLODATA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ZMLODATA

Overview

Demo project from Lukyanau Mikhail to let you understand how you can create OData service from scratch upon of your data model without using additional frameworks as CDS+RAP or CDS+BOPF.

Also this project has a good documentation in SAP community where author is explaided full path of creating OData service from scratch by using Eclipse + ADT + adjusted SAP GUI accessible from Eclipse by Alt+F8.

How to use

clone this project to your SAP instance by using abapGIT to previously created package ZMLODATA

image

After activating your package should look like this one:

image

Double press on GW Service Builder Project ZML_TRAVELLING_ODT to open project by SEGW transaction:

image

In project ZML_TRAVELLING_ODT open the node Service maintenance and choose accessible SAP Gateway and press button +Register to make registration of service:

image

Once service is registerd you can use button SAP Gateway Client to open HTTP client and do requests to this service.

To work with JSON format adjust request Header by adding these parameters:

Header parameter value when to use:
accept applicaiton/json GET, POST
content-type applicaiton/json GET, POST
if-match * PUT,PATCH,DELETE

Example of executing method GET by URI: /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet?$expand=TO_BOOKING

image

Example of executing method POST with structure for deep insert:

URI: /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet

Screenshot 2024-04-27 200628

Table of all possible for this service CRUD operations:

Name operation Method Header parameters Body of request URI
Read Travels GET accept:applicaiton/json content-type:applicaiton/json - /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet
Read Travels with Bookings GET accept:applicaiton/json content-type:applicaiton/json - /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet?$expand=BOOKING_TO
Read Bookings GET accept:applicaiton/json content-type:applicaiton/json - /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_IBOOKINGSet
Create Travel and Bookings POST accept:applicaiton/json content-type:applicaiton/json { "Name": "Test travel 1", TO_BOOKING: [ { "Hotel": "Test Hotel", "Dayfrom" : "/Date(1481760000000)/", "Dayto" : "/Date(1481760000000)/" } ] } /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet
Create Booking ( you should know TravelId ) POST accept:applicaiton/json content-type:applicaiton/json { "TravelId" : "0242ac11-0002-1eef-80aa-0315685dd657", "Hotel": "Test Hotel", "Dayfrom" : "/Date(1481760000000)/", "Dayto" : "/Date(1481760000000)/" } /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_IBOOKINGSet
Replace Travel record (you should know TravelId) PUT accept:applicaiton/json content-type:applicaiton/json if-match:* { "Client": "001", "Name": "Test travel 1"} /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet(guid('"0242ac11-0002-1eef-80aa-0315685dd657"'))
Change Travel record (you should know TravelId) PATCH accept:applicaiton/json content-type:applicaiton/json if-match:* { "Client": "001", "Name": "Test travel 1"} /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet(guid('"0242ac11-0002-1eef-80aa-0315685dd657"')
Replace Booking record (you should know BookingId) PUT accept:applicaiton/json content-type:applicaiton/json if-match:* { "TravelId" : "0242ac11-0002-1eef-80aa-0315685dd657", "Hotel": "Test Hotel", "Dayfrom" : "/Date(1481760000000)/", "Dayto" : "/Date(1481760000000)/" } /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_IBOOKINGSet(guid('"0242ac11-0002-1eef-80aa-0315685dd657"'))
Change Booking record (you should know BookingId) PATCH accept:applicaiton/json content-type:applicaiton/json if-match:* { "Hotel": "Test Hotel" } /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_IBOOKINGSet(guid('"0242ac11-0002-1eef-80aa-0315685dd657"')
Delete Travel record (you should know TravelId) DELETE accept:applicaiton/json content-type:applicaiton/json if-match:* - /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_ITRAVELSet(guid('"0242ac11-0002-1eef-80aa-0315685dd657"')
Delete Booking record (you should know BookingId) DELETE accept:applicaiton/json content-type:applicaiton/json if-match:* - /sap/opu/odata/sap/ZML_TRAVELLING_ODT_SRV/ZML_IBOOKINGSet(guid('"0242ac11-0002-1eef-80aa-0315685dd657"')

Understanding code

Please read documentation about this on my blog in SAP community here (I recommend to copy this link and paste in browser, because redirecting from github can give you 403 forbidden error): https://community.sap.com/t5/application-development-blog-posts/creation-of-odata-service-with-implementation-of-crud-methods-and-deep/ba-p/13685666

Happy studding code and programming!

Thank you!

Yours sincirely,

Mikhail.

About

Example of ODATA service (full package) which can be added by `abapGit` to your local or cloud SAP instance. ODATA service has name `ZML_TRAVELLING_ODT` and demonstrates full CRUD and `deep insert` methods by SEGW project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages