首页 > SAP > HANA > How to expose Attribute Views as XS OData Service in HANA
2019
08-27

How to expose Attribute Views as XS OData Service in HANA

Hello everyone, in this SAP HANA tutorial, we will learn how to expose Attribute Views as XS OData service in HANA. Lets get started.

1.Prerequisites

You should have installed SAP HANA Studio in your local machine.
You should have connected to HANA system with your HANA DB Credentials.
You should have Attribute View created in HANA Repository.Please read our previous tutorial on how to create Attribute View.

2.Step-By-Step Procedure

1. You need to change the Eclipse IDE perspective to SAP HANA Development. Navigate to Window → Open Perspective → Other to change the perspective of your HANA Studio to SAP HANA Development   (OR)   Select the SAP HANA Development perspective in the perspective shortcut which is at the top right corner of your SAP HANA Studio.

SAP HANA Development Perspective

2. In the Open Perspective window, select SAP HANA Development Perspective and hit OK,

How to expose Attribute Views as XS OData Service in HANA - 第2张  | 优通SAP
Open Perspective

3. In the left section, you will see three new tabs Project Explorer, Repositories and Systems.Select Repositories tab.

[adsenseyu1]

4. Right click to create a new repository workspace for the HANA System you have already logged in.

How to expose Attribute Views as XS OData Service in HANA - 第3张  | 优通SAP
Create Repository Workspace

5. In the Create New Repository Workspace window, select the HANA system for which you want to create workspace, enter Workspace name and hit Finish.

How to expose Attribute Views as XS OData Service in HANA - 第4张  | 优通SAP
Create New Repository Workspace

6. Your new workspace will be created.

How to expose Attribute Views as XS OData Service in HANA - 第5张  | 优通SAP
HANA Repositories

7. Expand the created workspace and identify your repository package , right click on it and choose Check Out.

Tip : Checked out package will have tick mark like this How to expose Attribute Views as XS OData Service in HANA - 第6张  | 优通SAP

How to expose Attribute Views as XS OData Service in HANA - 第7张  | 优通SAP
Check Out Repository Package

8. After checking out, select your package and press Cntrl+N (or) Right click → New → Other.

9. In the New window search with XS OData and select XS OData File How to expose Attribute Views as XS OData Service in HANA - 第8张  | 优通SAPand hit Next.

How to expose Attribute Views as XS OData Service in HANA - 第9张  | 优通SAP
HANA XS OData Service File

10. In the New XS OData Service window, enter File name, choose Template as “Basic” and hit Finish.

How to expose Attribute Views as XS OData Service in HANA - 第10张  | 优通SAP
New HANA XS OData Service

11. A new HANA XS OData service will be created with predefined syntax like below.

How to expose Attribute Views as XS OData Service in HANA - 第11张  | 优通SAP
HANA XS OData Service Basic Syntax

12. We are not going to use the predefined syntax as it, remove that and copy and paste the below code.

13. Lets see what the HANA XS OData service file contains

Service definition starts with syntax – service {  }.
you have to provide the full path of attribute view where it is stored and its name.
as  –  you have to provide the Entity Type name.
with – columns of attribute view you want to expose.
key – key of the attribute view.

14. Activate the service by clicking on Active Button  How to expose Attribute Views as XS OData Service in HANA - 第12张  | 优通SAP on the tool bar.  You can also right click on the package and choose Activate / Activate All.

How to expose Attribute Views as XS OData Service in HANA - 第13张  | 优通SAP
Activate HANA XS OData Service

15. Before testing the service we need to first expose our package to do so we need to create two files in our package they are .xsaccess and .xsapp. Right click on your package → New → File.

How to expose Attribute Views as XS OData Service in HANA - 第14张  | 优通SAP
New HANA .xsaccess File

16. Copy and paste below code into newly created .xsaccess file.

17. Again repeat the Step-17 to create .xsapp file. This file will be a blank file.

18. Activate all objects in the package. Now we are ready for testing.HANA XS OData services are accessed by URL.Open your chrome browser and enter URL of your XS OData service in the below format.

http://hostname:port/package/file.xsodata

For example in our case the URL would be

http://saplearners.com:8005/demopackage/services/EmployeeInfo.xsodata

18. You will see the XS OData service metadata output like below in the browser.

How to expose Attribute Views as XS OData Service in HANA - 第15张  | 优通SAP
HANA XS OData Service metadata

19. Now append the entity name “EmployeeCollection” to the above URL and you will see the data of the attribute view like below.

URL – http://saplearners.com:8005/demopackage/services/EmployeeInfo.xsodata/EmployeeCollection

How to expose Attribute Views as XS OData Service in HANA - 第16张  | 优通SAP
HANA XS OData Service data

20. Congrats you have successfully exposed HANA attribute view as XS OData service.Now we can use this XS OData service in SAPUI5/SAP Fiori applications to display the data in UI.

Please stay tuned to us for more SAP HANA/HANA XS OData tutorials.Please feel free to comment and let us know your feedback. You feedback will keep us alive. Thank you. 

最后编辑:
作者:yangsen
本站为个人博客网站,全由我个人维护,我从事SAP开发13年,其它ERP开发7年,基本都是零售行业。本站记录工作学习的过程, 有SAP相关询问专、兼职工作可随时联系我。 有网站相关的问题可直接在文章下方留言,或者联系我。 邮件:yan252@163.com给我。 QQ:415402519

留下一个回复

你的email不会被公开。