SAP River Developer Guide En

Embed Size (px)

Citation preview

  • 8/10/2019 SAP River Developer Guide En

    1/62

    Developer Guide PUBLIC

    SAP River

    Document Version: 1.0 - 2014-08-21

    SAP River Developer GuideSAP HANA SPS 08, revision 82

  • 8/10/2019 SAP River Developer Guide En

    2/62

    Table of Contents

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

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

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

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

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

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

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

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

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

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

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

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

    3.3 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

    4 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 Search for Tables and Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

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

    4.4.1 MigrateData. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

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

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

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

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

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

    5.2 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

    2P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Table of Contents

  • 8/10/2019 SAP River Developer Guide En

    3/62

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

    6 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

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

    SAP River Developer Guide

    Table of Contents

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 3

  • 8/10/2019 SAP River Developer Guide En

    4/62

    1 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 design-

    time 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 Note1910234 .

    SAP River Documentation

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

    Guide escription

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

    SAP River Language Reference The SAP River Language Reference describes:

    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.

    SAP River Syntax Diagrams 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.

    4P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    What is SAP River?

    http://help.sap.com/download/River/riverdoc/index.htmlhttp://help.sap.com/saphelp_river/helpdata/en/e1/a0d8a50aa240c388bb894f51e33a30/frameset.htmhttp://help.sap.com/disclaimer?site=http://bit.ly/SAPRiverEAhttp://help.sap.com/download/River/riverdoc/index.htmlhttp://help.sap.com/saphelp_river/helpdata/en/b9/d3168b0a914ec89147403a66155cb4/frameset.htmhttp://help.sap.com/saphelp_river/helpdata/en/e1/a0d8a50aa240c388bb894f51e33a30/frameset.htmhttp://help.sap.com/disclaimer?site=https://service.sap.com/sap/support/notes/1910234http://help.sap.com/disclaimer?site=http://bit.ly/SAPRiverEAhttp://help.sap.com/disclaimer?site=http://bit.ly/SAPRiverEA
  • 8/10/2019 SAP River Developer Guide En

    5/62

    Guide escription

    SAP River TutorialThe 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 ExamplesThe 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?

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 5

    http://help.sap.com/disclaimer?site=http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/905a88d6-ebc0-3110-a786-db8368c13086http://help.sap.com/disclaimer?site=http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/905a88d6-ebc0-3110-a786-db8368c13086http://help.sap.com/disclaimer?site=http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/905a88d6-ebc0-3110-a786-db8368c13086http://help.sap.com/download/River/SAP_River_XS_JavaScript_Reference_en/index.htmlhttp://help.sap.com/disclaimer?site=http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c03b9892-ebc0-3110-e68d-f22ab7a4fb1e
  • 8/10/2019 SAP River Developer Guide En

    6/62

    element copiesAvailable = 0;element price : DecimalFloat = 0.00;

    }

    When you deploy the code, corresponding tables are automatically created in the database. You can thenwrite a SELECTstatement 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 Developmentperspective.

    Note

    The Rivermenu is displayed only when the editor for an .rdlfile is selected.

    6P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    What is SAP River?

  • 8/10/2019 SAP River Developer Guide En

    7/62

    Creating SAP River Applications

    The development process for SAP River applications is as follows:

    1 You create an SAP River project in the Project Explorerview of the Eclipse-based SAP HANA studio.

    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 theApplication Explorer.

    Note

    An application's home package must contain an .xsappand .xsaccess, meaning the package is

    home to an XS application. However, that XS application can contain many SAP River applications.

    It is best practice that the location of your code files be in the home package, but this is not required.

    You can share your SAP River project to any package, and specify a different package as the home

    package (via the application namespace).

    SAP River Developer Guide

    What is SAP River?

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 7

  • 8/10/2019 SAP River Developer Guide En

    8/62

    By default, all the artifacts that are generated for your SAP River application are located in the schema

    with the same name as your home package. But you can change this by using the @Schemaannotation.

    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 Rivermenu is displayed, with the following additional

    options:

    Option escription 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

    sitory

    A tool for syncing your application with other applica

    tions in the repository. Syncing is necessary whenyou 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

    ing generating test data and running actions. You can

    also perform role-based testing.

    Web Application Explorer[page

    45]

    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.

    8P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    What is SAP River?

  • 8/10/2019 SAP River Developer Guide En

    9/62

    2 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.rdlpackage in the repository content.

    Related Information

    SAP HANA Administration Guide

    SAP River Developer Guide

    Enabling River

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 9

    http://help.sap.com/hana/SAP_HANA_Administration_Guide_en.pdfhttp://help.sap.com/hana/SAP_HANA_Administration_Guide_en.pdf
  • 8/10/2019 SAP River Developer Guide En

    10/62

    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 DevRolerole for the package. Developers with this role can run the applications from this

    package.

    If developers have the DevRolerole 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 theAdministrationeditor in the SAP HANA studio and choosing the

    Configurationtag. The new parameter is at indexserver.ini rdl developerrole .

    10P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Enabling River

  • 8/10/2019 SAP River Developer Guide En

    11/62

    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 design-

    time 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 bykeywords. 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:

    DevPackageto the name of the package that you want to create or for which you want to create a

    new user.

    DevUserNameto the name of the new user.

    initialPasswordto 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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 11

  • 8/10/2019 SAP River Developer Guide En

    12/62

    Next Steps

    If your package is actually a subpackage, you also need to run the procedures on the top-level package. Forexample, if you assign the package A.B.Cto 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

    12P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Enabling River

    http://help.sap.com/hana/SAP_HANA_Security_Guide_en.pdf
  • 8/10/2019 SAP River Developer Guide En

    13/62

    3 Getting Started

    A developer needs to set up the SAP River environment in the SAP HANA studio, and then can create aHelloWorldapplication 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 Developmentfeature.

    NoteThe 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 buildingSAP HANA applications,

    including those using the SAP River language and tools.

    Context

    To build SAP River applications, use the SAP HANA Developmentperspective.

    Procedure

    1 Close all instances of Eclipse, and then open the SAP HANA studio.

    SAP River Developer Guide

    Getting Started

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 13

    http://help.sap.com/hana/SAP_HANA_Studio_Installation_Update_Guide_en.pdf
  • 8/10/2019 SAP River Developer Guide En

    14/62

    2 Open the SAP HANA Developmentperspective:

    If this is your first time opening SAP HANA studio, the Welcomescreen is displayed. Select Open

    Development.

    If you have previously opened SAP HANA studio, open the SAP HANA Developmentperspective by

    choosing Window Open Perspective Other SAP HANA Development .

    Results

    The developer workbench opens with the SAP HANA Developmentperspective (selected in the upper-right of

    the screen).

    14P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    15/62

    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 towork with.

    Procedure

    1 In the SAP HANA Development perspective of the SAP HANA studio, select the Systemsview.

    2 In the white space of the view, right-click and chooseAdd System.

    SAP River Developer Guide

    Getting Started

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 15

  • 8/10/2019 SAP River Developer Guide En

    16/62

    The Systemwizard opens.

    3 In the Specify Systemwindow, 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 Propertieswindow, type the following:

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

    16P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    17/62

  • 8/10/2019 SAP River Developer Guide En

    18/62

    The Catalognode 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 Contentnode includes all the existing packages for which you have permissions. Packages contain

    design-time files for your development project.

    The Securitynode 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 fora specific SAP HANA system.

    Procedure

    1 In the \perspective of the SAP HANA studio, choose the Repositoriesview.

    2 Choose .

    3 In the Create Workspacedialog 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 Repositoriesview, you can now see an entry for this workspace, and you can browse the existing

    packages in the repository for which you have permission.

    18P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    19/62

    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 .rdlfile that holds your code.

    Procedure

    1 In the SAP HANA Developmentperspective of the SAP HANA studio, select the Project Explorerview.

    2 Create an SAP River project by choosing File New Project .

    3 Select SAP HANA River Application Development River Project , and choose Next.

    SAP River Developer Guide

    Getting Started

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 19

  • 8/10/2019 SAP River Developer Guide En

    20/62

    4 In the New River Projectdialog box, specify the following:

    a) In the Project Namefield, type HelloWorld.

    b) In theApplication Namefield, type DevPackage.HelloWorldApp.

    c) Select the Include .xsapp and .xsaccess filescheckbox.

    20P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    21/62

    5 Choose Finish.

    A new SAP River project is added to theProject Explorerview. An .rdlfile 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 .xsappfile and an .xsaccessfile, which enable the runtime objects that

    are created when SAP River is compiled to be run. You should not 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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 21

  • 8/10/2019 SAP River Developer Guide En

    22/62

    7 In the Share Projectdialog box, select SAP HANA Repositoryas the repository type, and choose Next.

    8 Specify a repository and 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 theAdd project folder as sub-packagecheckbox.

    d) Choose Finish.

    22P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    23/62

    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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 23

  • 8/10/2019 SAP River Developer Guide En

    24/62

    By default, all changes to your files are automatically committed to the repository. You can change this

    behavior in the settings by choosing Window Preferences SAP HANA Repository .

    3.3.2 Code and Activate HelloWorld

    To create an SAP River application, you add code to the .rdlfile and activate the file in the SAP HANA

    system.

    Context

    The code below creates an entity called MyEntitywith one data element (name), and one action (greeting)

    that returns a greeting using the contents of namefrom the current instance of the entity.

    Procedure

    1 In the HelloWorld.rdlfile, delete all text and copy and paste the following code into the file:

    @ODataapplication 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. However, 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. You can now test it in the Application Explorer and

    make OData calls to retrieve data and run actions.

    24P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    25/62

    3.3.3 Test HelloWorld in Application Explorer

    Check that you can make OData calls based on the SAP River code that you just activated, and that tables

    were created for your entity.

    Procedure

    1 In the Project Explorerview, double-click your .rdlfile (or click in your code in the SAP River editor).

    This enables the Rivermenu.

    2 To open theApplication Explorer, choose River Application Explorer .

    TheApplication Explorerhas an object tree on the left with all the objects that you defined in your code.

    3 Create an instance of your MyEntityentity as follows:

    a) In the object tree, selectMyEntity.

    b) Choose New.

    c) In the namefield, enter a name.

    d) Choose Save.

    A new instance is saved and is displayed in theApplication Explorer.

    4 Run the greetingaction as follows:

    a) In the object tree, selectgreeting.

    b) In the Select Instancefield, choose and then select the instance that you just created.

    c) Choose .

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

    SAP River Developer Guide

    Getting Started

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 25

  • 8/10/2019 SAP River Developer Guide En

    26/62

    5 Generate two more instances with the data generator, as follows:

    a) In the object tree, selectMyEntity.

    b) Choose Generate Data.

    In the Step 1window, 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 the Step 2window, 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 Summarywindow, choose Finish.

    Results

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

    3.3.4 Test HelloWorld with OData

    TheApplication Explorerworks by making background OData calls. You can instead test your application bymanually making OData calls.

    Prerequisites

    You have already created an instance with theApplication Explorer.

    26P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    27/62

    Procedure

    1

    Make an OData call to retrieve the instances in your new entity as follows (make sure to change the servername and XS port for your installation, and provide the credentials for your new developer user):

    URL: http://myserver:8000/DevPackage/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 headerX-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 to provide the credentials for your new

    developer user):

    URL: http://myserver:8000/DevPackage/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-TOKENresponse header.

    SAP River Developer Guide

    Getting Started

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 27

  • 8/10/2019 SAP River Developer Guide En

    28/62

    Response Body:

    { "d": {

    "results": { "__metadata": { "uri": "/DevPackage/odata/DevPackage.HelloWorldApp/MyEntity('Fred')", "type": "DevPackage.HelloWorldApp.MyEntity_entityType", "etag": "W/\"0\"" }, "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/DevPackage/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-TOKENresponse header.

    Enabled-ETag false

    SAP River supports ETags, which are a mechanism for avoiding collisions with other users who are

    updating data or running actions on data. The Enabled-ETagheader 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, you can check in the SAP HANA studio, in the Systemsview, to see

    that a table was created for your entity. The table that holds the data for your entity is called

    DevPackage::HelloWorldApp.MyEntity.

    28P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Getting Started

  • 8/10/2019 SAP River Developer Guide En

    29/62

    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 nameof the entity (HelloWorldApp.MyEntity).

    To view the new data, right-click the table DevPackage::HelloWorldApp.MyEntityand select Open

    Data Preview.

    Related Information

    Test HelloWorld in Application Explorer[page 25]

    Check that you can make OData calls based on the SAP River code that you just activated, and that tables

    were created for your entity.

    SAP River Developer Guide

    Getting Started

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 29

  • 8/10/2019 SAP River Developer Guide En

    30/62

    4 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.B1and A.B2at the same time, but you could

    not define SAP River applications inA.B1and A.B1.C1at 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 .rdlfile in

    the project.

    Procedure

    1 Choose File New Project .

    2 In the New Projectwizard, choose SAP HANA River Application Development River Project , and

    then choose Next.

    3 In the Project Namefield, type a name for the project.

    4 In theApplication Namefield, enter the fully qualified application name you are coding in the project.

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

    30P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Coding Your Application

  • 8/10/2019 SAP River Developer Guide En

    31/62

    Note

    You can instead choose Selectand 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 .rdlfile 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.rdlsource 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 .rdlsource

    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 Newwizard opens.

    2 Select SAP HANA River Application Development River Source File , and choose Next.

    3 In the File Namefield, type a name for the file.

    4 Choose Finish.

    Results

    An .rdlfile is added to the project.

    SAP River Developer Guide

    Coding Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 31

  • 8/10/2019 SAP River Developer Guide En

    32/62

    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 Windows Preferences SAP HANA River

    Application Development Editor 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.

    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.

    32P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Coding Your Application

  • 8/10/2019 SAP River Developer Guide En

    33/62

    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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 33

  • 8/10/2019 SAP River Developer Guide En

    34/62

    To view the quick outline, choose Navigate Quick Outline .

    Outline View: Open the Outlineview 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

    code, and then right-clicking and choosing Source Toggle Comments (or Ctrl + + + / ).

    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 Windows Preferences SAP

    HANA River Application Development Editor Folding .

    34P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Coding Your Application

  • 8/10/2019 SAP River Developer Guide En

    35/62

    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 Modelingrole. 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 River

    Search in SAP HANA Re-index .

    As with any SAP HANA table that you want to use in your SAP River code, the _SYS_REPOuser must have

    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 River Search in SAP HANA Tables / Views (or press Ctrl + Shift + V ).

    2 In the Table/View Searchdialog box, enter a search term, and choose Search.

    The search tries to match the search term with one or more of the following:

    Table name or description.

    View name or description.

    Column name or description.

    3 Select a table or view.

    SAP River Developer Guide

    Coding Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 35

  • 8/10/2019 SAP River Developer Guide En

    36/62

    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 followingSAP River code:

    let myEntity : MyEntity[] = select * from MyEntity;apply delete() to myEntity

    Another way to delete the data is to run a truncate tableSQL statement on the table. The name of the

    underlying table is ::. 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.

    36P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Coding Your Application

  • 8/10/2019 SAP River Developer Guide En

    37/62

    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 willnot activate. For example, if you change a Stringelement to Integer, some of your existing data may not be

    legal Integervalues. 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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 37

  • 8/10/2019 SAP River Developer Guide En

    38/62

    Procedure

    1 In the SAP HANA Developmentperspective of the SAP HANA studio, select your .rdlfile, and choose

    River Data Migration Create Backup Script

    This creates an .sqlfile that, when run, renames the tables for your entities by adding _RENAMEDto 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, and select your SAP HANA system.

    c) Choose the Runicon .

    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 .rdlfile that adds a migrateaction 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 Stringto 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 migrateactions 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 Activate the migration .rdlfile.

    38P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Coding Your Application

  • 8/10/2019 SAP River Developer Guide En

    39/62

    7 Run the migrateactions, either in theApplication Exploreror 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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 39

  • 8/10/2019 SAP River Developer Guide En

    40/62

    5 Testing Your Application

    SAP River provides several tools within the SAP HANA studio for testing your application without having tobuild your own client.

    To access the tools, use theApplication 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 Consoleview to learn how OData calls are constructed for accessing SAP River objects. The

    Application Exploreruses OData calls, and these are displayed in the Consoleview.

    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 theApplication Explorer. While

    the Web-based tool enables role-based testing, it does not include debugging capabilities.

    5.1 Application Explorer

    TheApplication Explorerview enables you to view and modify the data for your entities and views. It also lets

    you quickly test your actions.

    To open theApplication Explorer, in the SAP HANA Development perspective of the SAP HANA studio, choose

    River Application Explorer .

    To use theApplication 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 .

    40P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Testing Your Application

  • 8/10/2019 SAP River Developer Guide En

    41/62

    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 Consoleview. To open the Console, choose .

    Navigation

    You can synchronize the navigation in the editor and theApplication 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 andApplication Explorer, in theApplication Explorerchoose in theApplication

    Explorer.

    SAP River Developer Guide

    Testing Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 41

  • 8/10/2019 SAP River Developer Guide En

    42/62

    5.1.1 Create and Modify Data

    You can create, modify, and delete instances of an entity with theApplication Explorerview.

    Procedure

    1 In theApplication Explorerview, 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:

    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.

    42P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Testing Your Application

  • 8/10/2019 SAP River Developer Guide En

    43/62

  • 8/10/2019 SAP River Developer Guide En

    44/62

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

    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.

    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 Summarywindow, 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 theApplication Explorerview, 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.

    44P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Testing Your Application

  • 8/10/2019 SAP River Developer Guide En

    45/62

    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 theApplication Explorerview, 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 Explorerlets 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 Exploreronline at http://:/sap/

    hana/rdl/applicationexplorer/?AppName=.

    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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 45

  • 8/10/2019 SAP River Developer Guide En

    46/62

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

    46P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Testing Your Application

  • 8/10/2019 SAP River Developer Guide En

    47/62

    Context

    Log on to the Web Application Explorerwith different permissions, and test how your application performs fordifferent roles:

    Procedure

    1 Open an .rdlfile.

    2 Choose River Application Explorer Web .

    3 Log on with the approppriate credentials.

    4 Test your application.

    5.2.2 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 Newwindow opens, displaying options for each element in the entity.

    3 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 , select a row, and choose Create. The association is added to the

    entity in the New Rowwindow.

    4 Choose Create.

    Results

    The row you created is added to the database and appears under the entitytoolbar. Each cell in the row

    represents an element in the entity.

    SAP River Developer Guide

    Testing Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 47

  • 8/10/2019 SAP River Developer Guide En

    48/62

    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 Datawindow 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 Rowsfield, 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.

    48P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Testing Your Application

  • 8/10/2019 SAP River Developer Guide En

    49/62

    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 Updatewindow 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 entitytoolbar.

    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 OKin the confirmation box.

    Choose to select all the rows for this entity, and then choose . Choose OKin the

    confirmation box.

    Select one row you want to delete, and then press and hold the Ctrlkey, and continue selecting rows

    you want to delete. Choose , and then choose OKin the confirmation box.

    SAP River Developer Guide

    Testing Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 49

  • 8/10/2019 SAP River Developer Guide En

    50/62

    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 chooseActions, 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 Resultpane on the bottom of the workspacepane.

    Request: Shows the request URL, request method, and request body.

    Response: Shows the response JSON.

    5.2.7 View History

    The Historypane in the Web Application Explorerdisplays 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 Historypane, select one of the recorded actions.

    The action appears in the workspace pane.

    3 Change parameter values, if needed.

    4 Choose Run.

    50P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Testing Your Application

  • 8/10/2019 SAP River Developer Guide En

    51/62

    6 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:

    Debugperspective

    The following views:

    Debug

    Variables

    Breakpoints

    Note

    In the SAP HANA studio, the Debugperspective does not automatically open when debugging begins. If you

    want it to open automatically, choose Window Preferences Run/Debug Perspectives , and set

    Open the associated perspective when launchingto Prompt.

    Procedure

    1 In the Systemsview, right-click your system and chooseAdministration.

    2 On the Configurationtab, add a section called xsengine.ini debugger (if it does not exist), and add

    (or set) the following parameter:

    a) enabled(true)

    b) listenport(debugging port, default is 8000)

    SAP River Developer Guide

    Debugging Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 51

  • 8/10/2019 SAP River Developer Guide En

    52/62

    Related Information

    Debug with the Application Explorer[page 52]The easiest way to debug is by using theApplication Explorerview, 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 theApplication 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 theApplication Explorerview, 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

    TheApplication Explorerview 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. TheApplication Explorerview automatically

    creates the debug configuration and starts a debug session.

    Procedure

    1 Open the Debugperspective.

    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.

    52P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Debugging Your Application

    http://help.sap.com/hana/SAP_HANA_Developer_Guide_en.pdf
  • 8/10/2019 SAP River Developer Guide En

    53/62

    3 To open theApplication Explorerview, choose River Application Explorer .

    4 In theApplication Explorerview, select the action you want to run.

    5 In theApplication Explorerview, choose .

    Results

    The debugger should now stop at the breakpoint that you set.

    Related Information

    Application Explorer[page 40]

    TheApplication Explorerview 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 theApplication 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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 53

  • 8/10/2019 SAP River Developer Guide En

    54/62

  • 8/10/2019 SAP River Developer Guide En

    55/62

    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 Selectand choose the application you want to debug.

    7 Choose Debug.

    8 In the Select Sessiondialog box, select the session to debug, and choose Select.

    The session name is the same as the xsSessionIdcookie that appeared in your REST client. You can

    filter the sessions by user.

    SAP River Developer Guide

    Debugging Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 55

  • 8/10/2019 SAP River Developer Guide En

    56/62

    9 Open the Debugperspective.

    1 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-Tokenand ETag headers, if needed, because you are making a POST

    call.

    56P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Debugging Your Application

  • 8/10/2019 SAP River Developer Guide En

    57/62

    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 theApplication 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 theAdministrationeditor, double-click your system in the SAP HANA Systemsview.

    2 Choose the Diagnosis Filestab.

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

    3 To filter for the xsenginetrace files, type xsenginein the Filterfield. Look for the xsenginetrace file

    with the most recent date.

    4 To view a file, double-click it.

    SAP River Developer Guide

    Debugging Your Application

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 57

  • 8/10/2019 SAP River Developer Guide En

    58/62

    6.3.1 Change the Log Level

    By default, only error messages are logged for each SAP River application. If you want to log additionalmessages, you can change the log level.

    Procedure

    1 To open theAdministrationeditor, double-click your system in the SAP HANA Systemsview.

    2 Select the Trace Configurationtab.

    3 Under Database Trace, select .

    4 In the Trace Configurationwindow, 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 Change the System Trace Levelfor your application namespace, and choose Finish.

    58P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Debugging Your Application

  • 8/10/2019 SAP River Developer Guide En

    59/62

    7 Viewing OData URLs

    The SAP HANA studio provides a tool for displaying the URLs and other information of the OData services thatyou create when you activate SAP River code.

    Prerequisites

    You must expose your SAP River code with the @ODatakeyword, 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://://odatadocs/

    The OData Callsview 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

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 59

  • 8/10/2019 SAP River Developer Guide En

    60/62

    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 NOWARRANTIES, EXPRESS OR IMPLIED, OR OF MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

    Coding Samples

    Any software coding and/or code lines / s trings ("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 o f 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 co ntractualobligations or commitments are formed either directly or indirectly by this document.

    Gender-Neutral Language

    As far as possible, SAP do cumentation 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 o r 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.

    60P U B L I C2014 SAP SE or an SAP affiliate company. All rights reserved.

    SAP River Developer Guide

    Important Disclaimers on Legal Aspects

    http://help.sap.com/disclaimer/
  • 8/10/2019 SAP River Developer Guide En

    61/62

    SAP River Developer Guide

    Important Disclaimers on Legal Aspects

    P U B L I C2014 SAP SE or an SAP affiliate co mpany. All rights reserved. 61

  • 8/10/2019 SAP River Developer Guide En

    62/62

    www.sap.com/contactsap

    2014 SAP SE 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 SE

    or an SAP affiliate company. The information contained herein may

    be changed without prior notice.

    Some software products marketed by SAP SE and its distributors

    contain proprietary software components of other software

    vendors. National product specifications may vary.

    These materials are provided by SAP SE or an SAP affiliate company

    for informational purposes only without representation or warranty

    http://www.sap.com/contactsap