Академический Документы
Профессиональный Документы
Культура Документы
SAP River
Document Version: 1.0 - 2014-05-28
Table of Contents
1
1.1
1.2
Enabling River. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1
2.2
2.3
Set Up Permissions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1
3.2
3.3
3.2.1
Add a System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.2
Creating HelloWorld. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3.1
3.3.2
3.3.3
3.3.4
4.1
4.2
4.3
4.4
Migrate Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.1
Application Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.2
5.1.1
5.1.2
5.1.3
Run Actions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.2.2
5.2.3
5.2.4
Edit Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2.5
Delete Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2.6
Run Actions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
5.2.7
View History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
6.1
6.2
6.3
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
SAP River is a development model for building SAP HANA native applications It includes a language for
defining your data model and business logic, as well as a set of development tools.
The SAP River development environment is fully integrated in the SAP HANA studio development experience,
and follows the SAP HANA native development paradigm, using the SAP HANA repository as a central designtime store, and activation workflow for turning design-time objects into executable objects. Therefore, it is
easy to integrate objects from other domains, for instance, HTML/UI5 or XS files, into the same project.
SAP River is fully compatible with existing SAP HANA objects, like tables, views, stored procedures and XS
JavaScript procedures, and supports embedded "breakout" code written in other SAP HANA languages like
SQLScript or XS JavaScript.
SAP River applications can be automatically exposed via OData, without the need for describing these
services.
Note
SAP River is available as part of SAP HANA SPS 08 under an Early Adoption program. For details about
joining this program, contact your SAP sales account executive/relationship manager, or apply at http://
bit.ly/SAPRiverEA
Note
For the latest information about SAP River, see SAP Note 1910234
Description
The SAP River Developer Guide describes how to get started using the
SAP River tools and how to build a HelloWorld application.
The OData APIs for calling SAP River objects from an application
front end.
The XS JavaScript APIs for calling SAP River objects from an appli
cation front end written in XS JavaScript.
The SAP River Syntax Diagrams provides a compact but complete view
of the SAP River syntax, displayed in HTML pages that let you navigate
through the syntax.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Guide
Description
The SAP River Tutorials provide a step-by-step guide for building exam
ple applications. They include code examples and full solutions.
SAP River XS JavaScript Reference The SAP River XS JavaScript Reference describes the complete SAP
River APIs for accessing SAP River objects from XS JavaScript code.
SAP River Python Examples
The SAP River Python examples help you understand how to make
OData calls to your SAP River backend objects, using the Python pro
gramming language.
Related Information
Enabling River [page 9]
1.1
SAP River includes features to improve the development process for SAP HANA applications.
Following are some of the key benefits of SAP River:
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
element copiesAvailable = 0;
element price : DecimalFloat = 0.00;
When you deploy the code, corresponding tables are automatically created in the database. You can then
write a SELECT statement to query the object, which returns the appropriate data from the database. You
can treat the result set as an object (or array of objects).
let items = SELECT * FROM Book; // items holds result set from query
foreach (item in items) {
// Some code for each item
}
1.2
SAP River applications are built using the development infrastructure that is integrated into SAP HANA,
including the SAP HANA studio installed on a local workstation and the repository on the SAP HANA server.
The SAP HANA studio comes with tools to help you create SAP River applications. With the tools, you can
define SAP River applications in code files, generate test data, test your business code (actions), and debug
the code. The tools are available from the SAP HANA Development perspective.
You create an SAP River project in the Project Explorer view of the Eclipse-based SAP HANA studio.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
2.
You add SAP River code files (with the extension .rdl) to the project, and edit them with the SAP River
editor.
Note
Each file contains code for one application only, but the code for one application can be divided into
several files.
3.
You commit the code files to the the application's home package in the repository. No one else can see the
file.
4.
You activate your files. The SAP River compiler creates the corresponding runtime objects to be run in the
various engines and components of SAP HANA.
Index Server: Whenever possible, the SAP River compiler creates tables, stored procedures, views
and other objects that can run in the SAP HANA database (index server), to maximize performance.
XS JavaScript: The SAP River compiler may also generate server-side JavaScript code that runs in
SAP HANA extended application services (XS).
Any OData services that are specified in the SAP River code are also generated.
5.
Note
An application's home package must contain an .xsapp and .xsaccess, meaning the package is home to
an XS application. However, that XS application can contain many SAP River applications.
The SAP HANA studio includes an SAP River new project wizard, and an SAP River editor for code files.
Whenever you are editing an SAP River code file, the River menu is displayed, with the following additional
options:
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Option
Description
More Information
Search in SAP
HANA
Data Migration
Sync with Repo A tool for syncing your application with other applica
sitory
tions in the repository. Syncing is necessary when
you reference other applications, and the definition of
the entities or actions in those applications change.
Application Ex
plorer
Application Ex
plorer Web
A web-based tool for testing your application, includ Web Application Explorer [page
ing generating test data and running actions. You can 45]
also perform role-based testing.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Enabling River
To enable SAP River development in SAP HANA, an SAP HANA administrator must do the following:
1.
2.
3.
2.1
Much of the functionality on the server including the ability to make OData calls against your SAP River code
is handled by a delivery unit that you must deploy to your SAP HANA system.
Procedure
1.
Download the SAP River delivery unit SAR file (SAP HANA RIVER) from SAP Service Marketplace.
The filename of the SAR starts with HANARDL.
2.
Deploy the delivery unit with the SAP HANA Lifecycle Manager. For more information about using this tool,
see the SAP HANA Administration Guide.
Results
After deploying the delivery unit, you can see the sap.hana.rdl package in the repository content.
Related Information
SAP HANA Administration Guide
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
2.2
The SAP HANA server must be configured to enable SAP River development.
Context
The configuration steps here will make the SAP HANA server a development machine for SAP River
development, which has the following effect:
When developers activate SAP River code in a package, the compiler checks whether they have been
assigned the DevRole role for the package. Developers with this role can run the applications from this
package.
If developers have the DevRole role for the package, they are granted access to the schema with the
same name as the package, which is where all the database objects for the application are created. This
means these developers can run their code, even if their code restricts access to users with specific roles.
Procedure
Run the following SQL statement, for example, in the SQL Console of the SAP HANA studio.
ALTER SYSTEM ALTER CONFIGURATION('indexserver.ini', 'system' ) SET
('rdl','developerrole') = 'DevRole' WITH RECONFIGURE;
Results
You can check the results by opening the Administration editor in the SAP HANA studio and choosing the
Configuration tag. The new parameter is at
10
indexserver.ini
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
rdl
developerrole .
2.3
Set Up Permissions
An SAP HANA administrator must set up permissions so a developer can create SAP River applications.
Context
Developers must be given design-time privileges to the repository packages where they create their designtime objects, as well as runtime permissions to the schema that holds the runtime objects created when
activating an SAP River file.
A developer with runtime permissions to the schema is able to run the application regardless of the
permissions defined for SAP River objects by the accessible by keywords. If you want to test the
application's permissions, set up additional users with only the roles defined in your SAP River application.
To help you set up permissions, SAP River provides several procedures.
Procedure
Modify the following example SQL for your needs (changing the user, password and package), and then
run it in the SQL Console of the SAP HANA studio:
call "_SYS_BIC"."sap.hana.rdl.setup::create_river_environment"
('DevPackage', ?);
call "_SYS_BIC"."sap.hana.rdl.setup::add_user_to_river_dt_role"
('DevUserName','initialPassword', 'DevPackage');
call "_SYS_BIC"."sap.hana.rdl.setup::add_user_to_river_rt_role"
('DevUserName','initialPassword', 'DevPackage');
Make sure to make the following changes:
DevPackage to the name of the package that you want to create or for which you want to create a
new user.
Note
The question mark (?) in the first call indicates a placeholder for a return value, which is displayed in the
SQL Console after running the script. You don't have to replace the question mark.
If the package exists, no package is created, though the user is created and given permission to the
package. And if the user exists, no user account is created and the password is ignored, though the user is
given permission to the package.
Note
The name of the package cannot be the same as the user, and the password must adhere to standard
SAP HANA password rules.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
11
Next Steps
If your package is actually a subpackage, you also need to run the procedures on the top-level package. For
example, if you assign the package A.B.C to a developer, you need to run the procedures for the package
A.B.C, and then run the procedures again for package A.
Additional privileges are required for enabling migration of data.
Related Information
Migrate Data [page 37]
You may need to migrate data when making changes in the structure of your entity.
SAP HANA Security Guide
12
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Getting Started
A developer needs to set up the SAP River environment in the SAP HANA studio, and then can create a
HelloWorld application to quickly understand the process of developing with SAP River.
Prerequisites
To get started using SAP River, you must do the following:
Install the SAP HANA studio with the Application Development feature.
Note
The version of the SAP HANA studio must be equal to or earlier than the version of the SAP HANA
server you are working with.Still, they should both be from the same SPS.
Get a developer username (for example, DEVUSER) and password, and be assigned an SAP HANA
repository package (for example, DevPackage). Both of these tasks must be done by an SAP HANA
administrator. For more information, see Enabling River [page 9].
Related Information
SAP HANA Studio Installation Guide
3.1
SAP HANA studio is the Eclipse-based development environment for building SAP HANA applications,
including those using the SAP River language and tools.
Context
To build SAP River applications, use the SAP HANA Development perspective.
Procedure
1.
Close all instances of Eclipse, and then open the SAP HANA studio.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
13
2.
If this is your first time opening SAP HANA studio, the Welcome screen is displayed. Select Open
Development.
If you have previously opened SAP HANA studio, open the SAP HANA Development perspective by
choosing
Window
Open Perspective
Other
Results
The developer workbench opens with the SAP HANA Development perspective (selected in the upper-right of
the screen).
14
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Repositories: A list of repository workspaces that let you sync your local development files with a
particular SAP HANA system.
3.2
SAP HANA includes a repository for managing design-time objects, including SAP River code files.
The workflow for developing applications is as follows:
1.
2.
You commit the files to the repository. Committed files are saved in the repository but are not visible to
other developers at this point. By default, whenever you save your development files locally, they are
automatically committed to the repository.
3.
You activate the files, which creates runtime objects, and the development objects are now visible to other
developers.
To manage the development process, you create the following within the SAP HANA studio:
Repository Workspace: A place on your local workstation for holding development files to be activated on
a specific system.
Project: A collection of related development files. Every project is associated with a repository workspace
so that you can activate the development files in the project on the associated SAP HANA server. The
project is also associated with a specific package on the server.
3.2.1
Add a System
The system you add makes a connection from the SAP HANA studio to the SAP HANA server that you want to
work with.
Procedure
1.
In the SAP HANA Development perspective of the SAP HAHA studio, select the Systems view.
2.
In the white space of the view, right-click and choose Add System.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
15
4.
16
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Note
You may be asked to change your initial password before you can proceed.
Results
The system is added to the Systems view:
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
17
The Catalog node includes all the existing schemas for which you have permissions, For each schema you
can see all its tables, views, procedures, sequences, and other database objects.
The Content node includes all the existing packages for which you have permissions. Packages contain
design-time files for your development project.
The Security node includes all the existing users and roles in the system. As a developer user, you may not
be able to see all users and roles.
3.2.2
After connecting to an SAP HANA system, you need to create a folder on your local workstation to hold your
development files, and then create a repository workspace, which associates the folder with the repository for
a specific SAP HANA system.
Procedure
1.
In the \ perspective of the SAP HAHA studio, choose the Repositories view.
2.
Choose
3.
a) Under SAP HANA System, select the system you just created.
b) In Workspace Name, type DevWorkspace.
c) In Workspace Root, type C:\SAPHANAworkspaces.
d) Choose Finish.
Note
You can set the workspace root to any location on your workstation, and set the workspace name to
any name that you like.
Results
In the Repositories view, you can now see an entry for this workspace, and you can browse the existing
packages in the repository for which you have permission.
18
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
All design-time development files are contained in packages in the repository. Packages let you group your
files by project or by type of file. Packages let you:
Now you are ready to create an SAP River project in an SAP HANA system.
3.3
Creating HelloWorld
Lets create a HelloWorld application to make sure that the SAP River tools are installed and working properly,
and that you can activate an SAP River file to your SAP HANA system.
This section assumes that you create your application in package DevPackage.
3.3.1
Create an SAP River project, which automatically includes an .rdl file that holds your code.
Prerequisites
Before creating an SAP River project, you need to do the following:
Procedure
1.
In the SAP HANA Development perspective of the SAP HAHA studio, select the Project Explorer view.
2.
File
New
Project .
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
19
3.
Select
SAP HANA
River Project
4.
20
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
5.
Choose Finish.
A new SAP River project is added to the Project Explorer view. An .rdl file is created with the same name
as the project, and is opened in the code editor on the right.
Note
The project also contains an .xsapp file and .xsaccess file, which enable the runtime objects that are
created when SAP River is compiled to be run. You do not need to modify these files.
6.
To share the project with the repository of your SAP HANA system, right-click the project and choose
Team
Share Project .
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
21
7.
In the Share Project dialog box, specify where you want to place the project in the repository, as follows:
a) Under Repository workspaces, select DevWorkspace (the repository workspace that you created
earlier).
b) In Repository package, browse to and select the package that was created for your development
(DevPackage).
c) Clear the Add project folder as sub-package checkbox.
d) Choose Finish.
22
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Results
Your project is now associated with a specific SAP HANA system, which enables you to commit and activate
your files to the repository on that system. You will commit and activate your files in the next step.
Once your project is shared with a repository workspace, the icon for each file indicates the status of the file,
as follows:
Indicates that the version of the file on your workstation has been modified but not committed
to the repository.
Indicates that the version of the file on your workstation has been committed to the reposi
tory, but has not been activated (and, therefore, cannot be run by anyone or viewed by other
developers).
Indicates that the version of the file on your workstation has been activated in the repository
and can be run.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
23
By default, all changes to your files are automatically committed to the repository. You can change this
behavior in the settings by choosing
3.3.2
Window
Preferences
SAP HANA
Repository .
To create an SAP River application, you add code to the .rdl file and activate the file in the SAP HANA
system.
Context
The code below creates an entity called MyEntity with one data element (name), and an action (greeting)
that returns a greeting using the contents of name from the current instance of the entity.
Procedure
1.
In the HelloWorld.rdl file, delete all text and copy and paste the following code into the file:
@OData
application DevPackage.HelloWorldApp
export entity MyEntity {
key element name: String;
}
2.
3.
Team
Activate
(or press
Ctrl + F3 ).
This compiles the SAP River code into runtime objects, and you can now test it in the Application Explorer
and make OData calls to retrieve data and run actions.
24
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
3.3.3
Lets make sure everything activated OK. You can check that you can make OData calls based on the SAP
River code that you just activated, and you can check that tables were created for your entity.
Procedure
1.
In the Project Explorer view, select your .rdl file (or click in your code in the SAP River editor).
This enables the River menu.
2.
River
Application Explorer .
The Application Explorer has an object tree on the left with all the objects you defined in your code.
3.
4.
The action's return value, along with the execution time, is displayed.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
25
5.
Results
The data is added to the database and shown in the Application Explorer.
3.3.4
The Application Explorer works by making background OData calls . You can instead test your application by
manually making OData calls.
Prerequisites
You have already created an instance with the Application Explorer.
Procedure
1.
26
Make an OData call to retrieve the instances in your new entity as follows (make sure to change the server
name and XS port for your installation, and provide the credentials for your new developer user):
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
URL: http://myserver:8000/MyPackage/odata/HelloWorldApp/MyEntity
Method: GET
Request Headers:
Header
Value
X-CSRF-TOKEN
Fetch
The header is sent to retrieve the security token, which is needed to add and update instances, and to
run actions.
Response Body:
{
"d": {
"results": [
{
"__metadata": {
"uri": "/DevPackage/odata/DevPackage.HelloWorldApp/
MyEntity('Wilma')",
"type": "DevPackage.HelloWorldApp.MyEntity_entityType"
},
"name": "Wilma"
}
]
}
}
You should also receive a response header X-CSRF-TOKEN, which you must send along with its value with
every non-GET request during the current session. Keep this value available for the following calls.
2.
Now make another OData call to add another instance to the entity MyEntity (again, make sure to
change the server name and XS port for your installation, and provide the credentials for your new
developer user):
URL: http://myserver:8000/MyPackage/odata/HelloWorldApp/MyEntity
Method: POST
Request Body:
{
}
"name": "Fred"
Request Headers:
Header
Value
X-CSRF-TOKEN
Response Body:
{
"d": {
"results": {
"__metadata": {
"uri": "/DevPackage/odata/DevPackage.HelloWorldApp/
MyEntity('Fred')",
"type": "DevPackage.HelloWorldApp.MyEntity_entityType",
"etag": "W/\"0\""
},
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
27
"name": "Fred"
The response shows details about the record that was just created.
3.
URL: http://myserver:8000/MyPackage/odata/HelloWorldApp/MyEntity('Fred')/
greeting
Method: POST
Request Body: None (Make sure to delete the request body from the previous call.)
Request Headers:
Header
Value
X-CSRF-TOKEN
Enabled-ETag
false
SAP River supports ETags, which is a mechanism for avoiding collisions with other users who are
updating data or running actions on data. The Enabled-ETag header turns off this mechanism for
this OData call.
Response Body:
{
}
After deploying your SAP River file, in the Systems view you can check in the SAP HANA studio to see that
a table was created for your entity . The table that holds the data for your entity is called
DevPackage::HelloWorldApp.MyEntity.
The tables are created in a schema with the same name as your package. The name of each table is the
name of the package (DevPackage), followed by a double-colon (::), followed by the fully qualified name
of the entity (HelloWorldApp.MyEntity).
28
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
To view the new data, you can right-click the table DevPackage::HelloWorldApp.MyEntity and select
Open Data Preview.
Related Information
Test HelloWorld in Application Explorer [page 25]
Lets make sure everything activated OK. You can check that you can make OData calls based on the SAP
River code that you just activated, and you can check that tables were created for your entity.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
29
The SAP HANA studio includes tools for making it easy to code in SAP River.
The following are among the tools that help you to code in SAP River:
New project wizard, which lets you create new SAP River projects
SAP River editor, which includes features to help you navigate and format the code
Search wizard, which lets you make references to existing SAP HANA tables and views
Note
Only one SAP River application can be defined along a package hierarchy. That is, you cannot define an
application in a package and then define another application in a subpackage.
For example, say you had the following package hierarchy:
You could define SAP River applications in packages A.B1 and A.B2 at the same time, but you could
not define SAP River applications in A.B1 and A.B1.C1 at the same time.
4.1
To create applications with SAP River, you create an SAP River project and write your code in an .rdl file in
the project.
Procedure
1.
Choose
File
New
Project .
2.
3.
4.
In the Application Name field, enter the fully qualified application name you are coding in the project.
SAP HANA
The application name must be fully qualified, that is, preceded by the name of the package where the
application is located.
The application name is used as the application in the sample .rdl file that's created in every new project,
but you can change it later by editing the code file. The application name you enter has no other effect.
30
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Note
You can instead choose Select and select from a list of existing SAP River applications. The list includes
applications that you have already worked on within your SAP HANA studio.
5.
Choose Finish.
Results
An .rdl file with the same name is added to the project and contains some sample code. You can write your
SAP River code in this file.
4.2
You can add additional .rdl source files to your SAP River project, to either divide your application code into
several files or to write several applications in the same project.
Context
You can have a project with several applications, and each application can be written in several .rdl source
files. However, code cannot be combined from different applications in a single code file.
Procedure
1.
File
New
Other .
Select
SAP HANA
3.
4.
Choose Finish.
Results
An .rdl file is added to the project.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
31
4.3
Edit Code
SAP River code files are opened by default in the SAP River code editor, which provides many features to help
you edit the code.
Context
Note
You can only open SAP River code files from the Project Explorer view of the SAP HANA studio.
Procedure
Syntax Highlighting: The editor highlights different parts of the code with different colors and fonts. For
example, by default, keywords are shown in bold and purple.
You can change the default settings by choosing
Application Development
Editor
Windows
Preferences
SAP HANA
River
Syntax Coloring .
Error Checking: The editor checks for syntax mistakes, and shows them with a red mark in the margin.
Hover over the red error mark to display a tooltip that describes the error.
32
Code Completion: The editor suggests ways to automatically complete the code you are typing. For
example, whenever a type is needed in the code, a list of valid types is displayed.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
In addition, you can type part of a keyword or identifier, press Control + Space , and the editor will try to
complete the code.
Navigation Links: You can navigate from any reference to an entity, type, element, or other SAP River
object by hovering over the reference, then holding down the Control key and clicking.
For example, press and hold the Control key, put the cursor over name, and click. The editor moves to the
definition for the element and highlights it.
If you press and hold the Control key, and then click the name of an SAP River object where it is defined,
the entire definition is selected.
Outlining: The SAP River editor comes with an outline of the code, so that you can navigate within the
code. You can view the outline in the following ways:
Quick Outline: A pop-up dialog box within the code editor that shows an outline of the major parts of
your code--for example, namespaces, entities, views, and elements.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
33
Navigate
Quick Outline .
Outline View: Open the Outline view to keep the outline open at all times.
Indenting: The editor automatically indents your code, skipping four spaces when a new indent is needed.
For example, if you type in namespace myNamespace { and then press Enter , the editor will
automatically format the code as follows:
The editor inserts the closing brace, and indents the cursor.
If you typed code and deleted code, and as a result the indenting is no longer correct, you can fix the
indentation by right-clicking in the editor and choosing
Source
Correct Indentation .
Toggling comments: You can comment and uncomment a line of code by selecting one or more lines of
Source
Toggle Comments
Expanding/collapsing: You can expand and collapse sections of your code. For example, collapse the
definition of an entity, so you see only the name of the entity and not all its elements.
You can select which sections of your code can be collapsed by choosing
HANA
34
(or Ctrl + + + / ).
Editor
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Windows
Preferences
SAP
Folding .
4.3.1
You can search for existing SAP HANA tables and views and add a reference to them in your SAP River code.
For example, you can create an SAP River view that returns data from an existing SAP HANA table, and then
use that data in your application.
Prerequisites
To search for tables and views, you must be assigned the Modeling role. To view the data of the selected
tables and views, you need to have the appropriate permissions to the schema that contains the tables
and views.
Periodically, when tables and views are added or removed, you need to re-index by choosing
As with any SAP HANA table that you want to use in your SAP River code, the _SYS_REPO user must have
River
Re-index .
select, execute, delete, insert, and update privileges for the schema that contains the table.
Procedure
1.
In the SAP River editor, right-click where you want to add the name of a table or view in your code and
choose
2.
River
Tables / Views
In the Table/View Search dialog box, enter a search term, and choose Search.
The search tries to match the search term with one or more of the following:
3.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
35
4.
Choose OK.
Results
The name of the table or view is inserted into the code at the position of the cursor.
4.4
Activating your code is the act of compiling your code, which creates all the corresponding SAP HANA objects,
including tables, procedures, and OData services.
Context
After making changes to your code, you need to activate it if you want the changes applied. Although you can
activate individual files within your project, it is best to activate your entire project.
Note
Whenever you make a change to an entity, it is reflected in changes to the underlying database tables. And if
there is data in the table, a change in the data structure could result in loss of data or create an incompatibility.
In those cases, the SAP HANA studio won't allow your code to be activated. Some examples of when activation
is prevented:
To get around this issue, you must remove the data from the underlying table. For example, run the following
SAP River code:
let myEntity : MyEntity[] = select * from MyEntity;
apply delete() to myEntity
Another way to delete the data is to run a truncate table SQL statement on the table. The name of the
underlying table is <schema>::<fully qualified name of entity>. The schema name is the same as
the package name, and the fully qualified name is the path from the top-level application through any
namespaces to the entity.
However, if you need to keep your data, you can temporarily migrate it. Move the data to a temporary table,
and then move it back after you have changed the structure of your entity. SAP River provides tools for
migrating data.
36
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Procedure
Select the project in the Project Explorer, and from the toolbar choose
Related Information
Migrate Data [page 37]
You may need to migrate data when making changes in the structure of your entity.
4.4.1
Migrate Data
You may need to migrate data when making changes in the structure of your entity.
Prerequisites
The developer runtime role for your package (for example, DevPackage$DevRole) must have the ALTER
privilege for the schema with the same name as your package, which is where the tables, views, and other
runtime objects for your application are created.
Context
If you have data in an entity, and you make a change that is incompatible to the entity's structure, the code will
not activate. For example, if you change a String element to Integer, some of your existing data may not be
legal Integer values. So, as a preventitive measure, the code will not activate..
To make such changes, you must first remove the data from your entity. But if you want to preserve the data,
you need to do the following:
1.
2.
3.
Change the structure of the entity, and activate the change (which changes the structure of the underlying
table).
4.
The SAP HANA studio contains tools that create SQL and SAP River code to make the process easier.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
37
Procedure
1.
In the SAP HANA Development perspective of the SAP HAHA studio, select your .rdl file, and choose
River
Data Migration
This creates an .sql file that, when run, renames the tables for your entities by adding _RENAMED to the
end of the table names. This disassociates the tables with your entities and enables you to make changes
to your entities and activate the changes.
Note
The SQL script always has the same name. If you previously created a SQL migration script in the
current project, the previous script is overwritten.
Note
The SQL script moves the data for all entities in all applications within the application namespace of the
file you selected.
2.
Caution
Each time the SQL is run, the tables are renamed, so run the script only once. If you run the script,
activate your changed entities, and then run the script again, the previously saved data is lost.
3.
4.
River
Data Migration
This creates an .rdl file that adds a migrate action for each application. The action contains code for
copying the data for most of the elements from the temporary tables to your modified entities.
For elements whose types have changed, there may be no automatic way to restore the data--for example,
when an element changes from String to Integer.
Note
The SAP River migration file always has the same name. If you previously created a migration file in the
current project, the previous file is overwritten.
5.
Modify the SAP River migrate actions as needed, to modify how the data is restored from the temporary
tables to the modified entities, especially for elements whose type has changed..
6.
38
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
7.
Run the migrate actions, either in the Application Explorer or with an OData call.
Related Information
Set Up Permissions [page 11]
An SAP HANA administrator must set up permissions so a developer can create SAP River applications.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
39
SAP River provides several tools within the SAP HANA studio for testing your application without having to
build your own client.
To access the tools, use the Application Explorer, which lets you do the following:
Open the Console view to learn how OData calls are constructed for accessing SAP River objects. The
Application Explorer uses OData calls, and these are displayed in the Console view.
Note
You must activate your code, and expose your SAP River objects through OData.
Tip
You may also want to use the Web Application Explorer, which is similar to the Application Explorer. While
the Web-based tool enables role-based testing, it does not include debugging capabilities.
5.1
Application Explorer
The Application Explorer view enables you to view and modify the data for your entities and views. It also lets
you quickly test your actions.
To open the Application Explorer, in the SAP HANA Development perspective of the SAP HANA studio, choose
River
Application Explorer .
To use the Application Explorer, you select an SAP River object (entity, view, or action) from the object tree:
For entities and updateable views: To add, modify, and delete instances, use the buttons immediately
above the data .
For actions and views with parameters: To run the actions and views, use the buttons at the top of the
view .
40
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Navigation
You can synchronize the navigation in the editor and the Application Explorer, so that whenever you select an
object in the object tree, the editor moves to the definition of the object in the code. The synchronization works
the other way, too -- when you select a definition in the editor, the object is highlighted in the object tree of the
Application Explorer.
To synchronize the editor and Application Explorer, in the Application Explorer choose
Explorer.
in the Application
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
41
5.1.1
You can create, modify, and delete instances of an entity with the Application Explorer view.
Procedure
1.
2.
To create an instance, choose New. In the new row, enter the data for your instance, and choose Save.
To modify an instance, select the instance in the table, edit the fields you want to change, and choose
Save.
To delete an instance, select the instance in the table, and choose Delete.
When editing an instance, the instance is automatically saved when one of the following occurs:
5.1.2
You can generate a large amount of test data for your entities to make it easier to perform tests and see the
effects of the actions that you developed.
Context
Test data for each element is created in one of the following ways:
Fixed: You specify a value for the element, and have all instances for the entity contain that value for that
element.
Random: The data is generated randomly, based on one of the following rules:
42
Each string begins with the name of the field, followed by a random number.
Each string is a name made up of randomly selected common words (for example, Orange
Doorknob).
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Each string is randomly selected from a text file that contains all possible values, separated by
commas.
Enumerations: Generate random values from the list of valid enumeration values.
Associations: Generate random values from the existing instances of the associated entity. You must
first create instances for the associated entity.
You also specify how many instances to create for the entity.
Procedure
1.
2.
Note
If the entity has an element that is a custom type, there is a row for each element of the custom type.
For example, say you define a type:
type PersonName {
element FirstName: String;
element LastName: String;
}
And you define an entity based on this type:
entity Person {
element Name : PersonName;
}
There's a row for defining a rule for Person.FirstName and Person.Lastname.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
43
3.
4.
5.
A set of data is generated and displayed so that you can review it before it is added to the database.
6.
7.
5.1.3
Run Actions
You can test actions, either entity actions or global actions, by running them and checking the results. You can
also check the changes in the data caused by the actions.
Procedure
1.
In the Application Explorer view, select your action in the object tree.
2.
3.
Choose
You can also run the action with the debugger, by choosing
Results
The return value is displayed, if any, as well as the execution time of the action.
44
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Related Information
Debugging Your Application [page 51]
The SAP River debugger lets you view the execution of your action code in the Application Explorer (it is not
available from the Web Application Explorer). You can run the code line-by-line, and examine entities,
variables, and expressions.
Debug with the Application Explorer [page 52]
The easiest way to debug is by using the Application Explorer view, which lets you debug your code even
before you have created a UI that sends OData calls.
5.2
The Web Application Explorer lets you to test your SAP River applications without having to write any
dedicated test code.
To access the Web Application Explorer, choose
River
Note
You can also access the Web Application Explorer online at http://<Server>:<XS Port>/sap/
hana/rdl/applicationexplorer/?AppName=<ApplicationName>.
<ApplicationName> is the fully qualified name of the application.
The Web Application Explorer window contains the following panes:
Outline pane: Provides an object tree view of the namespaces, entities, views, and actions.
History pane: Provides a list of the actions that have been run. You can reload any action, change its
parameter values if needed, and run the action again.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
45
To use the Web Application Explorer, you select an SAP River object, such as an entity, view or action, from the
outline pane:
For entities and updatable views: To add, edit, and delete rows use the buttons immediately above the
data.
For actions and views with parameters: To run the actions and views use the buttons at the top of the view.
Run actions on the test data that you have created. If you have created global actions, you can test them
too.
Search for an entity, view, or action, and have all of its instances displayed in the outline pane.
5.2.1
Role-based Testing
The Web Application Explorer lets you test how an application performs for different users with different
permissions that are defined in your application.
Prerequisites
Before you can role-base test your application, the SAP HANA administrator must give the test user
REPO.READ package privileges on the package to be tested.
Context
Log on to the Web Application Explorer with different permissions, and test how your application performs for
different roles:
46
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Procedure
1.
Open an .rdlfile.
2.
Choose
3.
4.
5.2.2
River
In the Web Application Explorer, you can create a row of data to test your application.
Procedure
1.
2.
The Create New window opens, displaying options for each element in the entity.
3.
4.
Choose Create.
Results
The row you created is added to the database and appears under the entity toolbar. Each cell in the row
represents an element in the entity.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
47
5.2.3
In the Web Application Explorer, you can create multiple rows of data (up to 10) for testing actions or views.
Procedure
1.
2.
3.
Fixed
Specify a value for the element to have all instances of the entity contain that value for that element.
Random
The data is generated randomly, but based on one of the following rules:
String: Generate random strings where each string begins with the name of the field, followed by a
random number.
Enumerations: Generate random values from the list of valid enumeration values.
Associations: Generate random values from the existing instances of the associated entity. You
must first create instances for the associated entity.
No Value
Generates null value in all the column cells.
Note
In an entity where one or more elements are defined as key, at least one must be set to Random.
4.
5.
Choose Generate.
Results
The rows you created are added to the database, and a table containing the specified data appears in the
workspace pane. Each column in the table represents an element in the entity.
48
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
5.2.4
Edit Data
Procedure
1.
2.
In the workspace pane, select the row you want to edit and choose
.
The Update window opens, displaying options for each element in the entity.
3.
4.
Choose Update.
Results
The row is updated in the database, and the new data appears under the entity toolbar.
5.2.5
Delete Data
Procedure
1.
2.
In the workspace pane, do one of the following actions, depending on whether you want to delete one row,
all rows, or a selection of rows:
Choose
to select all the rows for this entity, and then choose
confirmation box.
Select one row you want to delete, and then press and hold the Ctrl key, and continue selecting rows
you want to delete. Choose
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
49
5.2.6
Run Actions
You can run entity actions and global actions on data in the Web Application Explorer.
Procedure
1.
Select an entity, and in the workspace pane choose Actions, and select the action you want to run.
2.
3.
Choose Run.
Results
The output of the action is displayed in the Result pane on the bottom of the workspace pane.
Request: Shows the request URL, request method, and request body.
5.2.7
View History
The History pane in the Web Application Explorer displays the recorded actions that you have executed, and
lets you execute them again with or without changing parameter values.
Procedure
1.
2.
3.
4.
Choose Run.
50
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
The SAP River debugger lets you view the execution of your action code in the Application Explorer (it is not
available from the Web Application Explorer). You can run the code line-by-line, and examine entities,
variables, and expressions.
Prerequisites
Context
The SAP River debugger is integrated into the standard SAP HANA Eclipse-based debugging tools, which
include:
Debug perspective
Debug
Variables
Breakpoints
Note
In the SAP HANA studio, the Debug perspective does not automatically open when debugging begins. If you
want it to open automatically, choose Window Preferences
Open the associated perspective when launching to Prompt.
Run/Debug
Procedure
1.
2.
xsengine.ini
debugger
a) enabled (true)
b) listenport (debugging port, default is 8000)
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
51
Related Information
Debug with the Application Explorer [page 52]
The easiest way to debug is by using the Application Explorer view, which lets you debug your code even
before you have created a UI that sends OData calls.
Debug without the Application Explorer [page 54]
You can also run the SAP River debugger without the Application Explorer. You may want to do this because
you already created a UI and would like to start the debugging process by making your own OData calls.
SAP HANA Developer Guide
6.1
The easiest way to debug is by using the Application Explorer view, which lets you debug your code even before
you have created a UI that sends OData calls.
Prerequisites
Context
The Application Explorer view lets you see the data of your entities and run actions to check how the data is
affected. The view also lets you run the actions with the debugger, essentially creating a debug session for you
when you do not have a UI or REST client to make OData calls. The Application Explorer view automatically
creates the debug configuration and starts a debug session.
Procedure
1.
2.
Add breakpoints in the SAP River actions that you want to debug.
To add a breakpoint, double-click in the left vertical ruler where you want to add a breakpoint.
52
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
3.
4.
In the Application Explorer view, select the action you want to run.
5.
River
Application Explorer .
Results
The debugger should now stop at the breakpoint that you set.
Related Information
Application Explorer [page 40]
The Application Explorer view enables you to view and modify the data for your entities and views. It also lets
you quickly test your actions.
Debug without the Application Explorer [page 54]
You can also run the SAP River debugger without the Application Explorer. You may want to do this because
you already created a UI and would like to start the debugging process by making your own OData calls.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
53
6.2
You can also run the SAP River debugger without the Application Explorer. You may want to do this because
you already created a UI and would like to start the debugging process by making your own OData calls.
Prerequisites
Procedure
1.
2.
Execute any OData call (for example, a call that retrieves an entitys instances):
a) Specify the URL.
b) Add the username and password as a header.
3.
4.
5.
54
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
7.
Choose Debug.
8.
In the Select Session dialog box, select the session to debug, and choose Select.
The session name is the same as the xsSessionId cookie that appeared in your REST client. You can
filter the sessions by user.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
55
9.
10. Add breakpoints in the SAP River actions that you want to debug.
To add a breakpoint, double-click in the left vertical ruler where you want to add a breakpoint.
Note
Make sure to include the X-CSRF-Token and ETag headers, if needed, because you are making a POST
call.
56
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
Results
The debugger should now stop at the breakpoint that you set.
Related Information
Debug without the Application Explorer [page 54]
You can also run the SAP River debugger without the Application Explorer. You may want to do this because
you already created a UI and would like to start the debugging process by making your own OData calls.
6.3
SAP River writes diagnostic messages to the SAP HANA XS trace file, which you can view in the SAP HANA
studio. You can also write from your applications to this file using the SAP River built-in logging library.
Procedure
1.
To open the Administration editor, double-click your system in the SAP HANA Systems view.
2.
3.
To filter for the xsengine trace files, type xsengine in the Filter field. Look for the xsengine trace file
with the most recent date.
4.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
57
6.3.1
By default, only error messages are logged for each SAP River application. If you want to log additional
messages, you can change the log level.
Procedure
1.
To open the Administration editor, double-click your system in the SAP HANA Systems view.
2.
3.
4.
In the Trace Configuration window, choose Show All Components, and then filter by xsa:. A list of all XS
applications are shown, including one for each SAP River application namespace.
Note
The log level affects all applications with the namespace.
5.
58
Change the System Trace Level for your application namespace, and choose Finish.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
The SAP HANA studio provides a tool for displaying the URLs and other information of the OData services that
you create when you activate SAP River code.
Prerequisites
You must expose your SAP River code with the @OData keyword, and activate your code.
Procedure
1.
Select an entity in the code, right-click within the entity, and choose
River
OData Calls .
Note
You can also access the list of OData calls with the following URL:
http://<server>:<XS port>/<application namespace>/odatadocs/<service>
The OData Calls view is displayed, showing the URLs for all the OData calls that are exposed for your SAP
River code.
2.
Find the URL that you want to use, and choose Select Text.
You can now copy and paste the URL into a REST client.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
59
This document is for informational purposes only. Its content is subject to change without notice, and SAP
does not warrant that it is error-free. SAP MAKES NO WARRANTIES, EXPRESS OR IMPLIED, OR OF
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
Coding Samples
Any software coding and/or code lines / strings ("Code") included in this documentation are only examples
and are not intended to be used in a productive system environment. The Code is only intended to better
explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness
and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the
usage of the Code, unless damages were caused by SAP intentionally or by SAP's gross negligence.
Accessibility
The information contained in the SAP documentation represents SAP's current view of accessibility criteria as
of the date of publication; it is in no way intended to be a binding guideline on how to ensure accessibility of
software products. SAP specifically disclaims any liability with respect to this document and no contractual
obligations or commitments are formed either directly or indirectly by this document.
Gender-Neutral Language
As far as possible, SAP documentation is gender neutral. Depending on the context, the reader is addressed
directly with "you", or a gender-neutral noun (such as "sales person" or "working days") is used. If when
referring to members of both sexes, however, the third-person singular cannot be avoided or a gender-neutral
noun does not exist, SAP reserves the right to use the masculine form of the noun and pronoun. This is to
ensure that the documentation remains comprehensible.
Internet Hyperlinks
The SAP documentation may contain hyperlinks to the Internet. These hyperlinks are intended to serve as a
hint about where to find related information. SAP does not warrant the availability and correctness of this
related information or the ability of this information to serve a particular purpose. SAP shall not be liable for
any damages caused by the use of related information unless damages have been caused by SAP's gross
negligence or willful misconduct. Regarding link classification, see: http://help.sap.com/disclaimer
60
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.
61
www.sap.com/contactsap