Monday, 6 March 2017

HANA XS: Javascript - Outbound API's ($.net)

SAP HANA XS outbound API($..net) provides tools that you can use to perform the below action.

  1. $.net.SMTPConnection.
    for sending $.net.Mail objects by means of an SMTP Connection.
  2. $.net.Mail
    For constructing and sending multipart of emails.
  3. $.net.http
    HTTP(s) client classes for outbound connectivity and an HTTP(s) destination class that hold metadata.
Example of $.net.http  API.
  1.  Create Hana destination file - myDestination.xshttpdest file.
    An HTTP destination defines connection details for services running on specific hosts whose     details  you want to define and distribute.The definition can be referenced by an application.


  2. Create JavaScript file - OutboundAPI.xsjs.


  3. Run you .xsjs file via Run As XS service and you should get below output.






Monday, 27 February 2017

HANA XS: Javascript -Database API's ($.db)

SAP HANA XS Database API($.db) provides tools that enable simple and convenient access to database.
  1.  $.db.getConnection().
    It returns $.internal.api.Connection object which has below method.
    1. close()
      closes the connection.
    2. commit()
      commits the connection.
    3. isClosed()
      Checks if connection is closed or not.
    4. prepareCall()
      Prepares a stored procedure for execution.
      Returns $.internal.api.CallableStatement object.
    5. prepareStatement(statement)
      Prepares a statement fro execution.
      Returns $.internal.api.PreparedStatement object and following methods.
      1. executeQuery()
        Executes an SQL statement and returns $.internal.api.ResultSet object and has below methods.
        1. getString(column Index).
          Return String for a specified columns.
        2. next()
          Iterates to next row of result set.
      2. executeUpdate()
        execute the update statement and returns the number of changed rows.
    6. rollback()
      Rolls back the changes.
    7. setAutoCommit()
      Changes the auto commit flag of the connection.
  2. Example:

    1. Create below table by writing below SQL on console.
    2. Write following code in javascript file to access the table's data by using database API.
    3. Run the .xsjs file as HANA XS service.




Wednesday, 22 February 2017

HANA XS: Write Server Side Java Script

How to Write Java Script Libraries?
  1. Click here to learn more about libraries.
  2. Open SAP HANA Development Perspective -->Project Explorer tab.
  3. Server Side Java Script libraries have an extension .xsjslib.
  4. To create a new file, select
    New-->Other-->SAP HANA-->Application Development-->XS JavaScript Library File.

  5. Select the parent folder and Name of file (eg. Custom_library.xsjslib).
    Note: Please create this file in other package apart from your project's package to test it out the $import function.

  6. Enter the following content in custom_library.xsjslib file.

  7. Import this library into your javascript file (hello.xsjs).
    Use $.import to reference library file to .xsjs file

  8. Activate it and Run that application as Run AS --> XS Service.




HANA XS: All About Java Script Libraries.

HANA Server side libraries are special type of Java Script program that can be imported and called in JavaScript program to perform simple and repetitive tasks.
Basic points about Server side libraries.

  1. The libraries exist in the context of package, which is referenced when you import a package.
  2. The libraries are imported by using function import of XS Java Script API.
    Syntax: import(path,library).
  3. The Import operation generates a hierarchy of objects below $ that resembles the libraries location in the repository.
    for example- if library name is Test located at path new/testpackage having function sum(),minus()
    Then it will generate following object.
    $new.testpackage.Test
    Additional properties for newly generated libraries object.
    $new.testpackage.Test.sum()
    $new.testpackage.Test.minus()
  4. Do not import the referenced libraries if it is already defined in the package.
    For example:
    Pre-defined libraries which gets included when create a project.
  5. How to write Custom Server side libraries.





HANA XS : Write Server Side Java Script.

SAP HANA XS supports server side application programming in JavaScript. The server-side application you develop used JavaScript API's to expose authorized data to client request.

In order to write server-side Java Script application, you must perform the following below steps:
  1. Setup a new project for application.
    Click here to set up a new project
  2. Create application descriptor file.
    Click here to create (.xsapp) file
  3. Create application access file.
    Click here to create (.xsaccess) file
  4. Create server-side JavaScript files that contains application logic.
    1. Select Project Explorer tab.
    2. Select New ---> Other--> SAP HANA--> Application development--> XS Java Script File.
    3. Write below Code in XS Java Script file and activate it.


    4. Right click on Java Script file and select Run As --XS application to preview output in Browser.
    5. Data preview on browser.



Sunday, 19 February 2017

HANA XS : Why JavaScript.

Why we need JavaScript for XS application?

  1. Its a language that can be used by application developer to create native SAP HANA applications that expose data to UI clients on request.
  2. Its is used for writing business logic that is used for exposing data to clients requests via HTTP.
  3. Prerequisites for using JavaScript.
    1. You must have access to SAP HANA system.
    2. You must have already created a development workspace and project.
      Click here to setup a project:
    3. You must have shared a project for the XS JavaScript artifacts so that the newly created files can be committed to the repository.
      Click here to learn how to share project:
Basic HANA XS application requires three people:
  1. Database developers.
    1. Language require:
      1. SQL Script.
      2. CDS
  2. Application developer.
    1. Language require:
      1. XS Java Script.
      2. OData.
      3. SQL Script.
  3. UI/Client developer.
    1. Language require:
      1. SAP UI5
      2. Java Script.

Saturday, 18 February 2017

SAP HANA XS: Application Privileges file (.xsprivileges)

Application Privileges file (.xsprivileges)
  1. This file enables you to define the authorization levels required for access to an application.
  2. This privileges can be assigned to individual role or users.
  3. The .xsprivileges file must reside in the same application package that you want to define access privileges for.
  4. And you must also add a corresponding entry in the same application’s .xsaccess file.
    For example: Using the authorization keyword.
  5. The application privileges file does not have a name; it has only file extension .xsprivileges.
    The content of the .xsprivileges file must be formatted according to the JavaScript Object Notion (JSON) rule.
  6. Multiple .xsprivileges files are allowed but only at different levels in the package hierarchy.
    You can’t define two .xsprivileges files in the same application package.
  7. The privilege name is unique to the package to which it belongs and, as a result, can be used in multiple .xsprivileges files in different packages.
  8. After activation of .xsprivileges object, the only user who by default has the application privileges specified in the .xsprivileges file is the _SYS_REPO user.
    1. To grant application privileges to other user, use the procedure or _SYS_REPO.
      GRANT_APPLICAITON_PRIVILEGES.
      REVOKE_APPLICATION_PRIVILEGES.

  9. How to create it ?
    1. Open SAP HANA Studio.
    2. Open SAP HANA development Perspective.
    3. In the Project Explorer tab, right click on the folder where you want to create it.
    4. In context menu,
      NewàOtheràSAP HANAàApplication DevelopmentàXS Application Privileges file.
    5. Finish it.
    6. Now open the .xsprivileges file from project and edit it and activate it.


  10. Example:


        Suppose this file is located in package com.test then the following privileges will be created.
        com.test::Execute
        com.test::Admin
  11. After activation of .xsprivileges object, the only user who by default has the application privileges specified in the .xsprivileges file is the _SYS_REPO user.

    To grant application privileges to other user, use the procedure or _SYS_REPO.
    GRANT_APPLICAITON_PRIVILEGES.
    REVOKE_APPLICATION_PRIVILEGES.

  12. Also,You need to create an entry of these privileges in .xsaccess file also by using keyword authorization.