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: 
ChiruSAP
Explorer
Overview:

Hi all, here I'm going to discuss about converting OData V4 service to OData V2 with step by step procedure (I will take screenshots from my PC for the reference and few pics from npm.js site). You will get to know the purpose of converting V4 service to V2.

Here we have a discussion about to convert OData V4 service response to OData v2 including metadata on SAP Business Technology Platform with Cloud Application Programming Model (CAPM). By for we would have seen that by default CAPM application gives us OData V4 service, but a time you would want this response to be converted to OData V2 service, we need to understand the main reason behind that.

Let’s say we are working with a CAPM application on top of a database, by default it will gives us OData V4 service, but still the framework which are using are not mature enough to consume OData V4 service.

For example Fiori Elements, there are fiori elements which are not mature enough to consume OData V4 service and there is only limited support for Over View Pages(OVP) and only supported for List Report(LR). But V2 OData service been there for long time and it is fully supporting all the fiori elements including Over View Page(OVP), List Report Page(LRP), Analytical List Report (ALP) and Work List (WL).  That’s where we are getting advantage of V2 services over V4 service.

Now, we need to follow a process to convert OData V4 to V2. For that we need a middleware (engine) to convert which is coming out of CAPM. This is nothing but a  dependency which is given by SAP. We have to add this OData-proxy module which converts V4 OData to V2.

And the steps to do this as below, here I'm adding few screenshots for the reference from my PC.

Step-1: We have to create a CAPM application with Business Application Studio. Start with the template to create CAPM application.


Fig.1


“Choose CAP project from the template”.


Fig.2


After selecting the “CAP project” and Target Location, fill the CAP project details as Project Name and select runtime as “Node.js”. Along with that add some features to the project by selecting check boxes as,

Configuration for SAP HANA Deployment-for Hana configuration, MTA based SAP Business Technology Platform Deployment- for deploying application to BTP.

Cloud Foundry Native Environment and we need to add sample content to our project, for that choose “Basic Sample Files”.


Fig.4


And Click on “Finish”.  Our CAP project will be created with CAP application structure which includes APP, DB, and SRV folders and OData V4 service and basic data.


Fig.5


Step-2: Now we need to create UI application for CAP project. For that we need to go to “CAP DATA MODELS AND SERVICES” select “Services” folder Choose “CatelogService” and right click on it and choose “Create UI”.


Fig.6


Step-3: Now select generator as “SAP Fiori Application”.


Fig.7


Now we have to select Data Source and Service Location as “Use a Local CAP Project” and Folder Path, OData service as “CatelogService(Node.js)”.


Fig.8


Then select Entity Selection as “Books”.


Fig.9


Then fill the Project Attributes as module name and deployment configurations.


Fig.10



Fig.11


And Finally add deployment configurations and click on “Finish”.


Fig.12


Now Application for CAP project is created.


Fig.13


Step-4: Now we need to connect with database “SQLite”, for that first open our application with “Integrated Terminal”.


Fig.14


Now in the terminal we need to give a command (cds deploy –to sqlite) to connect with database.


Fig.15


Now can see our application preview which consist of OData V4 service including metadata and data(Books).


Fig.16



Fig.17


If we click on “metadata” we can see OData V4 service.


Fig.18


If we click “Web application URL”, we will get the preview of our CAP application.


Fig.19


Step-5: Now we have to convert this V4 service to V2 by following step by step process.

To convert V4 service to V2 service 2 things we have to do,

5.I. Add dependency to the “Package.json” file.

5.II.  Add “server.js” file to the “SRV” folder.

 

ADD Dependency to the “Package.json” file



Fig.20


This is our Package.json file here we have to add dependency “@sap/cds-odata-v2-adapter-proxy” which is responsible to convert our V4 service to V2.

To implement this dependency in our Package.json file we have to go and search for this dependency and description in “npmjs.com” in the browser. There we will find the complete description of the dependency.


Fig.21



Fig.22


Now we have to add this dependency to our Package.json file.


Fig.23


Add “server.js” file to the “SRV” folder


Now we need to create “server.js” file in “SRV” folder.


Fig.24



Fig.25


In the server.js file we have to give the description of the dependency from npmjs.com. We need to copy that description and past it here in the server,js file. And also we can run the command “npm install @Sap/cds-odata-v2-adpater-proxy -s” in terminal.

For more information about dependency (https://www.npmjs.com/package/@sap/cds-odata-v2-adapter-proxy/v/1.9.5).


Fig.26



Fig.27


Now we will preview our application one more time, this time we will get two metadata and two entity sets which represents OData V4 and V2 services respectively.


Fig.28


If we click on metadata and entity sets we can see the difference with versions V4 and V2 respectively.


Fig.29



Fig.30



Fig.31



Fig.32


 

Conclusion:

The SAPUI5 framework can consume OData V2 Services in a non-intrusive way as if working directly with OData V4. With SAPUI5 the OData V4 Model supports the consumption of OData V2 services. The framework takes care to convert the metadata and the data in a way that the application developer writes its application as he would do with an OData V4 model with a corresponding OData V4 service. As OData V4 supports various features that are not covered by OData V2, some features of the OData V4 model cannot be used. So by converting OData V4 service to V2 we can provide flexibility to the UI5 applications development.

 

Kind regards,

Chiranjeevi. A
4 Comments
Labels in this area