Documente Academic
Documente Profesional
Documente Cultură
This tutorial explains how to create a simple SAP HANA XS application that is written in server-side JavaScript
and displays the "Hello World!" message together with a string extracted from a table in the SAP HANA
database.
Prerequisites
You have installed the tools as described in Installing SAP HANA Tools for Eclipse.
Context
1. Trial SAP HANA instance only: Create an SAP HANA development package.
3. Create a subpackage.
5. Create an XS project.
o Application descriptor (.xsapp): Marks the root point in the package hierarchy from which content
can be served. It is a prerequisite to develop and deploy an application on SAP HANA Extended
o Application access file (.xsaccess): Determines whether or not package content can be exposed
o Application privileges file (.xsprivileges): Defines the privileges required to access an application.
Account: p1234567890trial
User: p1234567890
Replace the above with your own account and user names. If you have a productive SAP HANA instance,
replace hanatrial.ondemand.com with the appropriate landscape host, for example, hana.ondemand.com.
Context
You can create one trial SAP HANA instance per account. A trial instance is equivalent to a database schema
with the database property HANA XS. Trial instances are also listed under Databases & Schemas in the
cockpit.
Note This section explains working with trial SAP HANA instances that provide you with a shared database
instance, enabling you to work with SAP HANA in a managed environment, using schemas instead of tenant
databases.
For more information about working with trial SAP HANA databases with multitenant database container
support enabled, see Databases and Creating SAP HANA MDC Databases.
Procedure
select an account.
All databases available in the selected account are listed with their ID, type, version, and related
database system.
Tip To view the details of a database, for example, its state and the number of existing bindings,
select a database in the list and click the link on its name. On the overview of the database, you can
3. To create a trial instance, choose New on the Databases & Schemas page.
o Schema ID. A schema ID is freely definable but must start with a letter and contain only uppercase
and lowercase letters ('a' - 'z', 'A' - 'Z'), numbers ('0' - '9'), and the special characters '.' and '-'. Note
that the actual schema ID assigned in the database will be different to this version.
o Database System: Select an available database ('MaxDB' or 'HANA') from the dropdown box.
To create schemas on your productive HANA instances, you have to use the HANA-specific tools.
Context
See the following links, depending on your use case (productive or trial):
(For the productive landscape) Connecting to SAP HANA Databases via the Eclipse IDE
(For the trial landscape) Connecting to SAP HANA Schemas via the Eclipse IDE
3. Create a Subpackage
Procedure
5. Click in the Description field to automatically copy across the package name.
6. Choose OK to confirm.
The new subpackage hello is added to the package hierarchy below the myhanaxs package.
Procedure
2. If your SAP HANA system is not listed in the SAP HANA System list, choose the Add System button
and add it to the list. If you have more than one SAP HANA system, make sure that the applicable
package name.
4. In the Workspace Root field, browse to select the folder that will contain the workspace you create in
5. Choose Finish.
The workspace now appears in the Repositories view. A folder has also been added to your local file
5. Create an XS Project
Procedure
1. In the Project Explorer view, choose File New Project SAP HANA Application
Note
After installing the SAP HANA tools for SAP HANA Cloud Platform, you may not see the XS Project
c. Start the Eclipse IDE again. The XS project wizard will now show up.
d. Remove the -clean option again.
2. Enter hello as project name, and choose Next (keeping all default settings).
3. Select the repository workspace you created. As Repository Package, choose Browse and navigate to
Restriction
You cannot use the root repository package here. You need to use the correct subpackage instead
4. Deselect the default file creation options (XS Application Access (.xsaccess) and XS Application
Results
Note
If you experience project errors due to unsupported encoding, use one of the following options to fix the
problem:
Quick fix that automatically changes the encoding of individual files to UTF-8
Project settings that change the default encoding of the entire XS project to UTF-8 ( context
Procedure
Application descriptor
1. In the Project Explorer view, select the hello project and choose File New File .
2. Enter the file name .xsapp and choose Finish.
Note that the file name is just a file extension and that the file does not have any content.
1. In the Project Explorer view, select the hello project and choose File New File .
2. Enter the file name .xsaccess and choose Finish.
3. Copy the following code into the .xsaccess file and save:
4. {
5. "exposed" : true,
6. "default_file": "hello.xsjs"
}
This configuration determines that the application will be exposed in the Internet via HTTPS.
Although no authentication is specified, all SAP HANA XS applications on a trial SAP HANA
instance use SAML2. For the productive SAP HANA instance, SAML will be enabled in a later
1. In the Project Explorer view, select the hello project and choose File New File .
2. Enter the file name .xsprivileges and choose Finish.
3. Copy the following code into the .xsprivileges file and save:
4. { "privileges" :
[ { "name" : "Basic", "description" : "Basic usage privilege"
} ]}
Role
1. In the Project Explorer view, select the hello project and choose File New File .
2. Enter the file name model_access.hdbrole and choose Finish.
SAP HANA instance, it should look something like this: p1234567890trial.myhanaxs.hello. Then
Procedure
1. In the Project Explorer view, select the hello project and choose File New File .
2. Enter the file name hello.xsjs and choose Finish.
3. Copy the following JavaScript code into the file and save:
4. $.response.contentType = "text/html";
5. var output = "Hello, " + $.session.getUsername() + " <br><br>";
6. var conn = $.db.getConnection();
7. var pstmt = conn.prepareStatement( "SELECT CURRENT_USER FROM DUMMY" );
8. var rs = pstmt.executeQuery();
9. if (!rs.next()) {
10. $.response.setBody( "Failed to retrieve data" );
11. $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
12. }
13. else {
14. output = output + "This is the response from my SQL. The
current user is: " + rs.getString(1);
15. }
16. rs.close();
17. pstmt.close();
18. conn.close();
$.response.setBody(output);
o Adds the results to the response so that it can be displayed in the Web browser
19. To activate the files in the SAP HANA repository, select the files and from the context menu choose
Team Activate .
created in section 6.
Procedure
1. In the Systems view, select your system and from the context menu choose SQL Console.
2. In the SQL console, enter the following, replacing <SAP HANA Cloud user> with your user:
call
"HCP"."HCP_GRANT_ROLE_TO_USER"('p1234567890trial.myhanaxs.hello::mod
el_access', '<SAP HANA Cloud user>')
3. Execute the procedure. You should see a confirmation that the statement was successfully
executed.
1. In the Systems view, expand Security Users and then double-click your user ID.
3. Select the model_access role in the list and choose OK. The role is now listed on the Granted
Roles tab.
4. Choose Deploy in the upper right corner of screen. A message confirms that your user has been
modified.
Note (Relevant for Trial landscape only) If you refactor existing SAP HANA database views or create
new ones on your Trial account, you need to refactor/recreate them in the "_SYS_BIC" schema
Procedure
Open the cockpit and proceed as described in: Launching SAP HANA XS Applications
You will be authenticated by SAML and should then see a text similar to the following:
Hello, p1234567890,
This is the response from my SQL. The current user is: p1234567890