Вы находитесь на странице: 1из 62

PUBLIC

SAP River
Document Version: 1.0 - 2014-05-28

SAP River Developer Guide

Table of Contents
1

What is SAP River?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

1.1

Key Benefits of SAP River. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.2

SAP River Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Enabling River. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.1

Deploy the SAP River Delivery Unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

2.2

Configure SAP River. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.3

Set Up Permissions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13

3.1

Open the SAP HANA Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.2

Setting Up the Development Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.3

3.2.1

Add a System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.2.2

Create a Repository Workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Creating HelloWorld. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3.1

Create the HelloWorld Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.3.2

Code and Activate HelloWorld. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.3.3

Test HelloWorld in Application Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3.3.4

Test HelloWorld with OData. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26

Coding Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

4.1

Create an SAP River Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

4.2

Create an SAP River Source File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4.3

Edit Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32


4.3.1

4.4

Search for Tables and Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Activate Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36


4.4.1

Migrate Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Testing Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

5.1

Application Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

5.2

5.1.1

Create and Modify Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42

5.1.2

Generate Test Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42

5.1.3

Run Actions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Web Application Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45


5.2.1

Role-based Testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46

5.2.2

Create One Row of Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

5.2.3

Create Multiple Rows of Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48

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.

SAP River Developer Guide


Table of Contents

5.2.7

View History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

Debugging Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

6.1

Debug with the Application Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

6.2

Debug without the Application Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

6.3

View Trace Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57


6.3.1

Change the Log Level. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Viewing OData URLs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59

Important Disclaimers on Legal Aspects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

SAP River Developer Guide


Table of Contents

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

What is SAP River?

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

SAP River Documentation


The following lists the documentation that you might find helpful for developing SAP River applications.
Guide

Description

SAP River Developer Guide

The SAP River Developer Guide describes how to get started using the
SAP River tools and how to build a HelloWorld application.

SAP River Language Reference

The SAP River Language Reference describes:

SAP River Syntax Diagrams

The syntax for writing SAP River applications.

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.

SAP River Developer Guide


What is SAP River?

Guide

Description

SAP River Tutorial

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.

Enabling SAP River


To build applications, SAP River must be enabled on your server, which involves setting parameters and
importing the SAP River DU. You'll also need an SAP HANA user account that has developer permissions,
including access to a package for saving your code files and activating them.
These steps are generally done by an SAP HANA administrator.

Related Information
Enabling River [page 9]

1.1

Key Benefits of SAP River

SAP River includes features to improve the development process for SAP HANA applications.
Following are some of the key benefits of SAP River:

SAP River is intent-driven.


SAP River lets you focus on what the application should do, not how it will do it.

SAP River is simple and easy to understand.

SAP River embeds a SQL-like query language.


SAP River lets you leverage relationships defined in the data model and use them in queries, thus
dramatically simplifying queries both writing them and later reading them.

SAP River is a simple way to build SAP HANA applications.


You define your data and business logic with a simple definition language, describing what you want your
application to do but not how to do it. You then deploy it to SAP HANA, and the compiler makes sure to
create all the stored procedures, views, JavaScript code and other things you need so the application
works and takes advantage of the speed and power of SAP HANA.
For example, you can define an object, or entity, called Book:
entity Book {
element title : String;

SAP River Developer Guide


What is 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
}

SAP River utilizes the native SAP HANA runtime.

SAP River is naturally exposed via OData.

1.2

SAP River Applications

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.

Creating SAP River Applications


The development process for SAP River applications is as follows:
1.

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.

SAP River Developer Guide


What is SAP River?

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.

You test your application using the Application Explorer.

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:

SAP River Developer Guide


What is SAP River?

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

Option

Description

More Information

Search in SAP
HANA

A wizard for adding a reference to an existing SAP


HANA database object, such as a table.

Search for Tables and Views [page


35]

Data Migration

A tool for making it easier to migrate data when you


are trying to modify entities that contain data.

Migrate Data [page 37]

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

A tool for testing your application, including generat


ing test data, running actions. and debugging your
code.

Application Explorer [page 40]

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.

Running SAP River Applications


In your SAP River code, you can specify that you want to expose OData services for reading and updating your
entities, and for running actions. When activating your code, these services are created, and at runtime a
client, such as a Web page, can make OData calls.

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


What is SAP River?

Enabling River

To enable SAP River development in SAP HANA, an SAP HANA administrator must do the following:
1.

Import the SAP River delivery unit.

2.

Configure SAP HANA to enable SAP River.

3.

Create developer users and give them the required permissions.

2.1

Deploy the SAP River Delivery Unit

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

SAP River Developer Guide


Enabling River

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

2.2

Configure SAP River

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 .

SAP River Developer Guide


Enabling River

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.

DevUserName to the name of the new user.

initialPassword to the password for the 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.

SAP River Developer Guide


Enabling River

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.

SAP River Developer Guide


Enabling River

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

Open the SAP HANA Studio

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.

SAP River Developer Guide


Getting Started

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

13

2.

Open the SAP HANA Development perspective:

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

SAP HANA Development .

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.

SAP River Developer Guide


Getting Started

The perspective displays the following views (on the left):

Project Explorer: A list of projects you are working on.

Repositories: A list of repository workspaces that let you sync your local development files with a
particular SAP HANA system.

Systems: A list of SAP HANA systems you can connect to.

3.2

Setting Up the Development Environment

SAP HANA includes a repository for managing design-time objects, including SAP River code files.
The workflow for developing applications is as follows:
1.

You create design-time objects as files on your workstation.

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:

System: A connection to an SAP HANA server.

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.

SAP River Developer Guide


Getting Started

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

15

The System wizard opens.


3.

In the Specify System window, type the following:


a) Hostname: The name of your SAP HANA server.
b) Instance Number: The instance number of your SAP HANA server.
c) Description: Dev System
Choose Next.

4.

In the Connection Properties window, type the following:


a) User Name: The developer user account that was created for you.

16

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


Getting Started

b) Password: The password for your user name.


Choose Finish.

Note
You may be asked to change your initial password before you can proceed.

Results
The system is added to the Systems view:

SAP River Developer Guide


Getting Started

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

Create a Repository Workspace

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.

In the Create Workspace dialog box, do the following:

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.

SAP River Developer Guide


Getting Started

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:

Transport related content to other SAP HANA systems.

Set different permissions for different development files.

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 the HelloWorld Project

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:

Add a system to the SAP HANA studio.

Create a repository workspace in the SAP HANA studio.

Procedure
1.

In the SAP HANA Development perspective of the SAP HAHA studio, select the Project Explorer view.

2.

Create an SAP River project by choosing

SAP River Developer Guide


Getting Started

File

New

Project .

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

19

3.

Select

SAP HANA

River Application Development

River Project

4.

In the New River Project dialog box, specify the following:

, and choose Next.

a) In the Project Name field, type HelloWorld.


b) In the Application Name field, type DevPackage.HelloWorldApp.
c) Select the Include .xsapp and .xsaccess files checkbox.

20

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


Getting Started

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 .

SAP River Developer Guide


Getting Started

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.

SAP River Developer Guide


Getting Started

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.

SAP River Developer Guide


Getting Started

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 .

Code and Activate HelloWorld

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;

action greeting() : String {


return 'Hello ' + this.name + '. Welcome to SAP River!';

}
2.

Save the file.


This saves the file on your workstation and commits it to the repository on the server. But it is still not
compiled, you cannot run it, and nobody can see your changes.

3.

To compile your HelloWorld.rdlfile, right-click the project and choose

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.

SAP River Developer Guide


Getting Started

3.3.3

Test HelloWorld in Application Explorer

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.

To open the Application Explorer, choose

River

Application Explorer .

The Application Explorer has an object tree on the left with all the objects you defined in your code.

3.

Create an instance of your MyEntity entity as follows:


a) In the object tree, select MyEntity.
b) Choose New.
c) In the name field, enter a name.
d) Choose Save.
A new instance is saved and is displayed in the Application Explorer.

4.

Run the greeting action as follows:


a) In the object tree, select greeting.
b) In the Select Instance field, choose
c) Choose

and then select the instance you just created.

The action's return value, along with the execution time, is displayed.

SAP River Developer Guide


Getting Started

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

25

5.

Generate two more instances with the data generator as follows:


a) In the object tree, select MyEntity.
b) Choose Generate Data.
In Step 1, you can modify the rules for how the data is generated. For this project, you can use the
default of random string values.
c) In Step 1, choose Next.
In Step 2, you can review the data that will be generated. When you choose Next, the data is created.
d) In Step 2, choose Next.
e) In the Summary window, choose Finish.

Results
The data is added to the database and shown in the Application Explorer.

3.3.4

Test HelloWorld with OData

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.

SAP River Developer Guide


Getting Started

URL: http://myserver:8000/MyPackage/odata/HelloWorldApp/MyEntity

Method: GET

Request Body: None

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

The value returned in the previous OData call's


X-CSRF-TOKEN response header.

Response Body:
{

"d": {
"results": {
"__metadata": {
"uri": "/DevPackage/odata/DevPackage.HelloWorldApp/
MyEntity('Fred')",
"type": "DevPackage.HelloWorldApp.MyEntity_entityType",
"etag": "W/\"0\""
},

SAP River Developer Guide


Getting Started

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.

Finally, you can call the action to retrieve a greeting.

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

The value returned in the previous OData call's


X-CSRF-TOKEN response header.

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:
{
}

"d": "Hello Fred. Welcome to SAP River!"

The response shows the return value of the action.


4.

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.

SAP River Developer Guide


Getting Started

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.

SAP River Developer Guide


Getting Started

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

29

Coding Your Application

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

You can create one project in a package.

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

Create an SAP River Project

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.

In the New Project wizard, choose


then choose Next.

3.

In the Project Name field, type a name for the project.

4.

In the Application Name field, enter the fully qualified application name you are coding in the project.

SAP HANA

River Application Development

River Project , and

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.

SAP River Developer Guide


Coding Your Application

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

Create an SAP River Source File

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.

Highlight your project and choose

File

New

Other .

The New wizard opens.


2.

Select

SAP HANA

River Application Development

3.

In the File Name field, type a name for the file.

4.

Choose Finish.

River Source File , and choose Next.

Results
An .rdl file is added to the project.

SAP River Developer Guide


Coding Your Application

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.

SAP River Developer Guide


Coding Your Application

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.

SAP River Developer Guide


Coding Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

33

To view the quick outline, choose

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

code, and then right-clicking 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 + + + / ).

River Application Development

Editor

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

Windows

Preferences

SAP

Folding .

SAP River Developer Guide


Coding Your Application

4.3.1

Search for Tables and Views

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

Search in SAP HANA

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

Search in SAP HANA

Tables / Views

(or press Ctrl + Shift + V ).

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.

Table name or description.

View name or description.

Column name or description.

Select a table or view.

SAP River Developer Guide


Coding Your Application

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

Activate Your Code

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:

You change an element type from String(20) to String(10).

You remove an element.

You change which elements are key elements.

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.

SAP River Developer Guide


Coding Your Application

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.

Move the data from the entity's table to a temporary table.

2.

Delete the data from the original entity.

3.

Change the structure of the entity, and activate the change (which changes the structure of the underlying
table).

4.

Restore the data to your entity from the temporary table.

The SAP HANA studio contains tools that create SQL and SAP River code to make the process easier.

SAP River Developer Guide


Coding Your Application

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

Create Backup Script

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.

Run the SQL as follows:


a) Double-click the SQL file.
A SQL console opens with the SQL code from the file loaded.
b) Choose the Connection icon,
c) Choose the Run icon

and select your SAP HANA system.

The tables are renamed.

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.

Change your entity and activate the code.

4.

With your SAP River file selected, choose

River

Data Migration

Create Migration Script

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

Activate the migration .rdl file.

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


Coding Your Application

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.

SAP River Developer Guide


Coding Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

39

Testing Your Application

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:

Add, modify, and delete instances for an entity.

Quickly generate many instances for testing your application.

Run actions (both actions defined in an entity and global actions).

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.

SAP River Developer Guide


Testing Your Application

OData and the Console


All the data manipulation and execution of actions within the Application Explorer occurs withOData calls. You
can view information about the OData calls in the Console view. To open the Console, choose

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.

SAP River Developer Guide


Testing Your Application

in the Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

41

5.1.1

Create and Modify Data

You can create, modify, and delete instances of an entity with the Application Explorer view.

Procedure
1.

In the Application Explorer view, select an entity in the object tree.

2.

Do one of the following:

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:

You choose Save.

You choose New.

You start editing another instance.

You click an object in the object tree.

5.1.2

Generate Test Data

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

Dates: Generate random dates, or dates within a specified range.

Integers: Generate random integer values, or integers within a specified range.

Decimals: Generate random decimal values.

String: Generate random strings, based on one of the following rules:

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).

Each string is a randomly selected name of a person.

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


Testing Your Application

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.

In the Application Explorer view, select an entity in the object tree.

2.

Choose Generate Data.


The Generate Test Data wizard opens, showing the rules for generating data for each of the elements of
the entity.

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.

SAP River Developer Guide


Testing Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

43

3.

(Optional) If you want to change the rule for an element, choose


and choose OK.

4.

In Records to Generate, enter the number of records to create.

5.

When you are done changing the rules, choose Next.

for that element, change the rule,

A set of data is generated and displayed so that you can review it before it is added to the database.
6.

If you are happy with the sample data, choose Next.


The data is generated and added to the database. If you want to change the rules, choose Back.

7.

In the Summary window, choose Finish.

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.

Enter the parameters for the action, if needed.


If the action is part of an entity, you must select an entity instance on which to run the action.

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.

SAP River Developer Guide


Testing Your Application

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

Web Application Explorer

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

Application Explorer Web .

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.

Workspace pane: Provides tools to generate data and run 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.

SAP River Developer Guide


Testing Your Application

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.

The Web Application Explorer lets you do the following:

Generate up to 10 rows of test data, or manually create one row at a time.

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.

SAP River Developer Guide


Testing Your Application

Procedure
1.

Open an .rdlfile.

2.

Choose

3.

Log on with the approppriate credentials.

4.

Test your application.

5.2.2

River

Application Explorer Web .

Create One Row of Data

In the Web Application Explorer, you can create a row of data to test your application.

Procedure
1.

In the outline pane, select an entity or updatable view.

2.

In the workspace pane, choose

The Create New window opens, displaying options for each element in the entity.
3.

4.

Enter data for the elements.

For primitive type fields, enter the required data.

For enumaration type fields, select the desired values.

For association type fields, click


entity in the New Row window.

, select a row, and choose Create. The association is added to the

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.

SAP River Developer Guide


Testing Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

47

5.2.3

Create Multiple Rows of Data

In the Web Application Explorer, you can create multiple rows of data (up to 10) for testing actions or views.

Procedure
1.

In the outline pane, select an entity or updatable view.

2.

In the workspace pane, click Generate Data.


The Generate Data window opens, displaying options for each element in the entity.

3.

For each element, specify one of the following rules:

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:

Dates: Generate random dates or dates within a specified range.

Integers: Generate random integer values or integers within a specified range.

Decimals: Generate random decimal values.

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.

In the Number of Rows field, enter a number from 1 to 10.

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.

SAP River Developer Guide


Testing Your Application

5.2.4

Edit Data

You can edit data in the Web Application Explorer.

Procedure
1.

In the outline pane, select an entity or updatable view.

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.

Edit the fields.

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

You can delete data in the Web Application Explorer.

Procedure
1.

In the outline pane, select an entity or updatable view.

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:

Select the row you want to delete and choose

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

SAP River Developer Guide


Testing Your Application

. Choose OK in the confirmation box.


. Choose OK in the

, and then choose OK in the confirmation box.

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.

In the outline pane, do one of the following:

Select an entity action or global action.

Select an entity, and in the workspace pane choose Actions, and select the action you want to run.

2.

Enter the action parameters, if needed.

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.

Response: Shows the response JSON.

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.

Perform actions in the workspace pane if you haven't already.

2.

In the History pane, select one of the recorded actions.


The action appears in the workspace pane.

3.

Change parameter values, if needed.

4.

Choose Run.

50

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


Testing Your Application

Debugging Your Application

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

You must have the role sap.hana.xs.debugger::Debugger.

The SAP HANA XS JavaScript debugger must be enabled.

Context
The SAP River debugger is integrated into the standard SAP HANA Eclipse-based debugging tools, which
include:

Debug perspective

The following views:

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

Perspectives , and set

Procedure
1.

In the Systems view, right-click your system and choose Administration.

2.

On the Configuration tab, add a section called


(or set) the following parameter:

xsengine.ini

debugger

(if it does not exist), and add

a) enabled (true)
b) listenport (debugging port, default is 8000)

SAP River Developer Guide


Debugging Your Application

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

Debug with the Application Explorer

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

You must have the role sap.hana.xs.debugger::Debugger.

The SAP HANA XS JavaScript debugger must be enabled.

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.

Open the Debug perspective.

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.

SAP River Developer Guide


Debugging Your Application

3.

To open the Application Explorer view, choose

4.

In the Application Explorer view, select the action you want to run.

5.

In the Application Explorer view, choose

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.

SAP River Developer Guide


Debugging Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

53

6.2

Debug without the Application Explorer

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

You must have the role sap.hana.xs.debugger::Debugger.

The SAP HANA XS JavaScript debugger must be enabled.

Procedure
1.

Open a REST client.

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.

Take note of the value of the xsSessionId cookie.


You will need the cookie to choose the name of the session that you want to debug.

4.

In the SAP HANA studio, choose Debug Configurations.

5.

Right-click River, and choose New.

54

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

SAP River Developer Guide


Debugging Your Application

A new debug configuration is created for SAP River debugging.


6.

Set the following in the debug configuration:


a) Name: Give a name to the debug configuration.
b) Application: Choose Select and choose the application you want to debug.

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.

SAP River Developer Guide


Debugging Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

55

9.

Open the Debug perspective.

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.

11. Execute the OData call to run your action.


You must define the following header for all calls that you want to debug:

Header Name: DEBUG_MODE

Header Value: true

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.

SAP River Developer Guide


Debugging Your Application

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

View Trace Files

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.

Choose the Diagnosis Files tab.


Here you can see all trace files. SAP River logs are located in the xsengine trace file

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.

To view a file, double-click it.

SAP River Developer Guide


Debugging Your Application

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

57

6.3.1

Change the Log Level

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.

Select the Trace Configuration tab.

3.

Under Database Trace, select

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.

SAP River Developer Guide


Debugging Your Application

Viewing OData URLs

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.

Your browser must support HTML5.

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.

SAP River Developer Guide


Viewing OData URLs

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

59

Important Disclaimers on Legal Aspects

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.

SAP River Developer Guide


Important Disclaimers on Legal Aspects

SAP River Developer Guide


Important Disclaimers on Legal Aspects

PUBLIC
2014 SAP AG or an SAP affiliate company. All rights reserved.

61

www.sap.com/contactsap

2014 SAP AG or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any


form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior
notice.
Some software products marketed by SAP AG and its distributors
contain proprietary software components of other software
vendors. National product specifications may vary.
These materials are provided by SAP AG and its affiliated
companies ("SAP Group") for informational purposes only, without
representation or warranty of any kind, and SAP Group shall not be
liable for errors or omissions with respect to the materials. The only
warranties for SAP Group products and services are those that are
set forth in the express warranty statements accompanying such
products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
SAP and other SAP products and services mentioned herein as well
as their respective logos are trademarks or registered trademarks
of SAP AG in Germany and other countries.
Please see http://www.sap.com/corporate-en/legal/copyright/
index.epx for additional trademark information and notices.

Вам также может понравиться