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

Converting OData V4 Service to OData V2

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.

1

Fig.1

“Choose CAP project from the template”.

2

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

34

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.

5

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

6

Fig.6

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

7

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

8

Fig.8

Then select Entity Selection as “Books”.

9

Fig.9

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

10

Fig.10

11

Fig.11

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

12

Fig.12

Now Application for CAP project is created.

13

Fig.13

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

14

Fig.14

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

Fig.15

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

16

Fig.16

17

Fig.17

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

18

Fig.18

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

19

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

20

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.

21

Fig.21

22

Fig.22

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

23

Fig.23

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

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

24

Fig.24

25

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

26

Fig.26

27

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.

28

Fig.28

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

29

Fig.29

30

Fig.30

31

Fig.31

32

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

Assigned Tags

      4 Comments
      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
      Gregor

      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: https://ui5.sap.com/#/topic/521405cc719e4e699a25366461a516cb. 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,
      Stefan

      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:

      https://answers.sap.com/questions/13738806/sapui5-support-for-odata-v2-cap-service.html

      https://answers.sap.com/questions/13743835/basvsc-fiori-tools-and-cap-odata-v2-proxy.html

      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