SAP River(1)—SAP River overview
We have a Chinese version (SAP River (一)：SAP River概述) of this blog.
The most common architecture of SAP HANA application is like below(From SAP River Datasheet):
Figure 1: Traditional SAP HANA application architecture
With the traditional architecture shown in Figure 1, application developer is responsible for both creating data model in database level and implementing control logic in XS level. SQL and SQL Script are required to create data model in SAP HANA database, while xsjs needed to implement control logic in XS level. Therefore, the developer of SAP HANA application at least needs to grasp two technologies to finish a SAP HANA application. Sometimes, developing a SAP HANA application needs the cooperation of two or more developers. SAP River is an option to void this problem.
SAP River is a brand new method to develop SAP HANA application. SAP River consists of a programming language, a programming model and a suit of development tools. With help of SAP River, developer can concentrate on the design of business intent, ignoring how is it implemented and optimized in SAP HANA database. SAP River only exists in design-time. When SAP River objects activated, all SAP River code is compiled into SQL Script or XSJS code and then transferred to XS engine indexserver for execution.
Figure 2: Function model of SAP River
The function model is shown in Figure 2 (From SAP River Datasheet). SAP River integrates all the segments involved in development of SAP HANA application, including data modeling, control logic and access control, which makes developer capable of accomplishing a SAP HANA application grasping only one single technology. Firstly, developer can design the data model for SAP HANA application with SAP River language. During compilation, SAP River will create corresponding database objects for the data model you designed using SAP River language. For example, the entity in SAP River program will be mapped to a table in SAP HANA database. Secondly, using SAP River language, developer can define methods for data objects, which implements business logic. Last but not least, SAP River provides developer a way to design the access control for data and method.
SAP River Language
As a new generation of SAP HANA application development method, SAP River provides a strongly typed and declarative programing language. With this programming language, even a non-computer-major developer can also easily develop a SAP HANA application. In addition, SAP River also supports embedded SQL Script and XSJS code in SAP River program, which is useful for some complicated logic.
SAP River Language mainly includes:
- Application: Application is the largest object in SAP River Language, all other objects must be included in an application. Objects in an application can be exposed to external applications via some ways, such as OData.
- Entity: Entity is used to store data in database. Usually, one entity is mapped to a table in SAP HANA Database. An entity consists of one or more elements. Usually, one element is mapped to a column of a table. Each element has its own type, the type here can be fundamental type such as integer, string, and can also be a custom type or entity.
- Types: Type defined the size and validity of data. SAP River supports different kinds of types, including fundamental type, structured type and stream type. Each entity will automatically define a corresponding implicit type, which has same name with the entity.
- Action: Action is similar to the function or method in other programming languages. Usually, SAP River define the business logic of the application in the actions.
- View: With the help of view, you can create a data stream using select statement, this data stream is a subset of target data set. The data of this data stream will be dynamically extracted from target data set when the data stream is used.
- Role: Role can be created in SAP River code, and assigned some privileges to this role. In this way, access control is implemented.
Figure 3. SAP River example program: Hello World
As a programming language, SAP River also provides some libraries, which contains many common functions. These libraries can be divided to some categories according to their functionality:
- Math Functions: mathematic calculation functions, such as absolute, ceil, floor, etc.
- Integer Functions: process the data of integer type, such as toDecimalFloat, toString, etc.
- String Functions: deal with strings, such as length, substring, etc.
- Date Functions: date functions, such as day, month, etc.
- Session Functions: session functions, such as getUserName.
- Logging Functions: log function, such log.
- Utility Functions: some utility functions, such as parseDecimalFloat, parseInt, etc.
- HTTP Calls: Http library is used to send Http request in SAP River code, such as OData or REST services.
SAP River can expose the data and business logic to client via OData protocol. SAP River can expose data to client either in application level or in namespace level via OData. If exposed in namespace level, then every entities, views, and actions in this namespace are exposed to client. If exposed in application level, then only the objects that are tagged for exposure are exposed to client. Here, let’s take application level as example to illustrate how to expose data via OData.
Figure 4. Expose SAP River application via OData
① when expose object in application level, you must use the keyword export to specify which objects are to be exposed to client. Such as Employee in TestSyntax here.
② There are more than one ways to expose SAP River object, OData is one of them. So it is necessary to add a notation “@OData” to declare the way of exposure. SAP River will create corresponding OData service for the application or namespace.
③ By Default, SAP River object is private. To let specified users to access certain object, you need to use the keyword “accessible by” to tell which role or privileges are required to access the object. If every users are allowed to access, you can just use “accessible by sap.hana.All”.
How to learn SAP River
SAP HANA begin to support SAP River from SPS07, we have many materials to study SAP River. Here are some materials for studying SAP River:
- SAP River Datasheet
- SAP River Help Docs
- Videos and PPTs introducing SAP River
- Series of videos introducing SAP River in SAP Academy
In this blog, we talked about functionality of SAP River, advantage and structure, including the advantages of SAP River over traditional development framework, main features of SAP River and how to expose data to client via OData.