OData is a REST- based protocol for querying and updating the data .
It’s built on standardised technologies such as HTTP,XML,JSON.
It provides an entire language directly in the URL so that you can focus on the business logic.
They are four different types of creation of ODATA services.They are :-
1. ABAP Code based Implementation.
2. Mapping Editor.
3. Referenced DataSource.
4. Using Annotation.
- ABAP Code based Implementation:- This is the regular approach
- Mapping Editor :- In SEGW transaction you can map cds view as a data source. You can map multiple cds views in 1 single OData service
- ReferencedDataSource :-In SEGW gateway builder, you can reference an ABAP CDS Views as a data source. Each entity type in OData service model corresponds to 1 ABAP CDS view.
- Using Annotation
In this approach we can create OData service directly on ABAP CDS View in Eclipse ABAP Development Tools using annotation @OData.publish: true.
Using SEGW Transaction :-Go to T-Code SEGW Hit the Create Icon and provide the name of the Project, description and package (or local) and save it.
Press on create button and you will be able to open the screen show in the below and save as local object(practicing) otherwise you can give the specified package as well and click on Ok.
The project gets created with four folders, namely Data Model, Service Implementation, Runtime Artifacts and Service Maintenance. Please take note that Data Model further has three sub-folders viz Entity Types, Associations and Entity Sets. All the folders are empty by default.
Research:- If you want to add single field also you can add but the company’s mostly use structure and adding the single field is tire some work so if you are interested so please explore it.
Right click on the DAtaModel->Import->ddicStructure.
You will get the popup displayed as shown below.Fill the required fields as shown below and check the Entity type, Default Entity Set
Right click on the Data Model folder and Import the DDIC Structure. Give the Entity Type name and ABAP structure whose fields you want to import to your Entity Type. Do not forget to click the checkbox for Entity Set (unless you are sure you will not need an internal table).
Next, choose the Key for your structure/entity type and entity set.
After you hit finish hit the save button and check the Properties and Service Implementation folder. They would have the structure and operations respectively.
Entity Types will have its own Properties and Navigation Properties Folder. And every Service Implementation Entity Set will have its own Operations (Create, GetEntity, Update, Delete etc).
Implement register Service:-
Hit the Generate icon and hit ok. Provide the package and transport number or save it as local. You should get the success message as shown below.
Technical service is actual service which we need to call.And along with that you can able to see the DPC, MPC (DAta Provider Class,Model Provider Class) respectively. They are connected by Configurations in the systems and not by codings
- DPC Provides the GateWay Service Functionalities.
- MPC Provides the Gateway Service Interface.
Using Annotation Approach:-
Activation of the OData Service :-
GATEWAY HUB Def :- SAP NetWeaver version installed on the other system is called as the gateway hub.
GatewayHub :- It would be a window for the outer world to SAP.And it exposes the OData service but the development would still happen in the backend system of SAP.
Go to your Gateway Hub (Front-end system) Execute t-code /n/IWFND/MAINT_SERVICE. Save this t-code in your favorite list or remember it by heart. You will need it for all your OData services.
You will be navigated to a screen like this and in this screen you will click the add service button and you will get a pop-up(Service Catalog) displayed like the below image and you should fill the required fields as shown in the image.
In that ServiceCatalog if you add the service than it will be visible to the outerworld to access.
- Fill the SystemAlias
- Fill the EXternal Service name
- And click on the Get Services you will be able to see the service
- Press the addSelectedServices button
Now you will navigate to another screen and there you should fill the package Assignment field
Just click on the local object if your practicing (or) if you have any specified package then you can use it.
Now you will go back to the service catalogs and then press the button loadMetadata and then now you can able to see the selected service.It would show up in System Aliases window at the lower right corner.
Let us test it using SAP Gateway Client. Or use t-code /IWFND/GW_CLIENT (remember this t-code as well). You can also test by Call Browser option. For now, we will use SAP Gateway Client option.
Now press the select gate way client button now you will be moved to the another screen as shown below
Here now click on the execute button an now you will be able to see the data. And the staus as 200 this means your call is in the success state.
In the above screen you can press the add UriOption and then you can get the output in the desired state.
Here in the example we can get the data in the metadata format so press the metadata option and click on the execute button
If you get an error like the screen shown in the below then we can go and check the odata service .
The command is /n/IWFND/ERROR_LOG to find the issue.
Just place the ? in the url before the formatting then the error will resolve. /sap/opu/odata/sap/ZRA_SETTLEMENT_CDS/?$format=xml
The MPC and DPC were generated. But the DPC methods were not re-defined. We need to write our ABAP code and logic to pull data from the backend system and populate the Entity Set (internal table). Once the entity set is populated, we can see the output in our OData service call.
Put the cursor the method you want to re-define. Hit the re-define method icon and hit enter. Some auto generated code would show up. Here i am redefining the get_entityset method
Activate the classCheck the folder Redefinition has the method ‘POHEADERSET_GET_ENTITYSET’ listed. This means our method is successfully re-defined.
Now, let us write one small statement to pull 10 entries from Purchase Order table in the method and activate it. so remove the unnecessary code.
After that execute the method and you will able to get the data in the sap gateway client check. And press the button response in the browser so that you can get the data to your particular extension browser(chrome,explorer, etc.,).
Research :- If you are interested then go with the crudx operations also.
Hope this blog will be useful to you .