Skip to Content
Technical Articles
Author's profile photo Chiranjeevi Appapogu

Converting OData V4 Service to OData V2


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

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Gregor Wolf
      Gregor Wolf

      Dear Chiranjeevi,

      are you limited to a specific SAPUI5 version in your environment? I think the OData V4 support made a lot of progress in the recent UI5 version. Hope that Christoph Gollmick can provide some input about the currently supported floorplans.

      Best Regards

      Author's profile photo Stefan Engelhardt
      Stefan Engelhardt

      Hi Chiranjeevi, Gregor,

      Gregor is right, when you are forced to use an older SAPUI5 version you might miss features in SAP Fiori elements for OData V4 which you are familiar with in the OData V2 version.

      As Gregor also stated, Fiori elements for OData V4 has caught up very well. All floorplans you know from Fiori elements for OData V2 are supported in the version for OData V4. There is not yet full feature parity of each and every feature within the floorplans, but hard work is being done to achieve it and there aren't many things left. We also see, that new apps predominantly get created using OData V4, which also shows maturity. You can see this for example also in our samples: In some parts the version for OData V4 even already outperforms the version for OData V2, e.g. in terms of flexibility and extensibility.

      Best regards,

      Author's profile photo Attila Berencsi
      Attila Berencsi

      Dear Stefan Engelhardt ,

      can You please help if we can use V4 with edit capabilities for non-draft scenarios already ?

      We are working on a CAPM application consuming external services, but it is not possible to generate a UI based on v2 inside the project due restrictions. Since this is a SaaS solution, it is self encapsulated with an embedded Fiori Launchpad module, so we can't generate UIs outside of the project.

      There are several discussion about this problem area including tooling, extensibility and support:

      As I understood

      • to provide edit capabilities on Fiori +
      • keep Fiori toolkit working in BAS +
      • consuming external services +
      • to provide a SaaS solution

      the only option is to implement V4 with manual request / draft management as mentioned here.

      Can You please confirm this ?

      Thank You very much in advance.

      Best regards, Attila

      Author's profile photo Attila Berencsi
      Attila Berencsi

      Dear Community,

      I've got the information that V4 edit capabilities will be not supported for non-draft scenarios in CAP - Fiori Elements context.

      BR, Attila