Showing posts with label XS Project. Show all posts
Showing posts with label XS Project. Show all posts

Thursday 21 September 2017

SAP HANA: ODATA Service

·         An OData service exposes data stored in database tables or views as OData collections for analysis and display by client applications.
·         The client can be web browser, or SAPUI5 application or HTML5 application or any other application which supports OData.
·         An OData service for SAP HANA XS is defined in a text file with the file suffix .xsodata, for example, OdataSrvDef.xsodata.
·         The XSODATA services are great because they provide a large amount of functionality with minimal amounts of development effort.

XSOData Examples:

An OData service for SAP HANA XS is defined in a text file with the file suffix  .xsodata
The file must contain at least the entry
service {
}

Example:

Step 1: Open HANA Studio and Select “SAP HANA DEVELOPMENT” Perspective.

Step 2: Select “Repositories” tab on the left side. Right-click and select “Create Repository Workspace”. In the popup window, provide Workspace name. You may keep everything as default.

Step 3: Click on “Project Explorer” tab. Right-click and select “XS Project”. Provide a name for your project and click Next.
Step 4: Select the Workspace. Click on the browse button and select the package where you want to create the XS project.
Step 5: Leave everything else blank and click Finish.
Step 6: An XS project will be created as shown below. Note that it automatically creates 2 mandatory files - .xsapp and .xsaccess.


SAP HANA XS Application Descriptor (.xsapp):

            Each application that you want to develop and deploy on SAP HANA XS must have an application descriptor file.
The application-descriptor file has no name and no content; it only has the file extension “xsapp”, for example, .xsapp. For backward compatibility, content is allowed in the .xsapp file but ignored.
The .xsapp file marks the root folder of an SAP HANA XS application. All files in that package (and any sub-packages) are available to be called via URL.
If you remove this .xsapp file from your HANA XS project, then you will not be able to call the project components via URL.

Example:

If the package sap.test contains the file .xsapp, the application will be available under the URL
http://<host>:<port>/sap.test/

SAP HANA XS Application Access File (.xsaccess):

The application-access (.xsaccess) file enables you to specify who or what is authorized to access the content exposed by the application package and what content they are allowed to see.

The application-access file does not have a name before the dot (.); it only has the file extension .xsaccess. The contents of the .xsaccess file must be formatted according to JavaScript Object Notation (JSON) rules.

Step 7: Create XSOData file by right-clicking the Project and select NEW and select XSOData file. And provide details and click Finish.
Step 8: And enter the following script in a workspace.
service {
"KABIL_PRACTICE"."TH_EMP_NAMES" as "EMPLOYEE";}



Step 9: And activate it, by right click the workspace and select Team and select Activate.

Step 10: Finally, Again Right click and select Run As an XS Service. This will open the XSOData service in the default browser.


Step 11: Enter user id and password of HANA system. You will see the result as shown as below:



Example 2: For getting as a odata file


Follow all  the above steps from Step 1 to Step 7 and in Step 8 you just change the script like as shown below.
Step 8: And enter the following script in workspace.

service  {


   "KABIL_HC::EMPLOYEE_DETAILS"                  // Table or View 
   as "MyView"
   key ("EMP_ID");            }

And again, follow all the steps from Step 9 to Step 11.

Note:

We can get the result in json format by doing following things:

For example: if your URL is :

http://<host>:80<instance_number>/KABIL_XS_PROJECT/EMPLOYEE_DETAILS_VIEW.xsodata

Just add your alias name like:/<alias_name>/?$format=json.



Result: