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!
Showing results for 
Search instead for 
Did you mean: 

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.


“Choose CAP project from the template”.


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”.


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.


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”.


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


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)”.


Then select Entity Selection as “Books”.


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



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


Now Application for CAP project is created.


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


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


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



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


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


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


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 “” in the browser. There we will find the complete description of the dependency.



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


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

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



In the server.js file we have to give the description of the dependency from 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 (



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.


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







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
Labels in this area