Function libraries add specific business and mathematical operations to the functionality of SAP HANA. They are integrated into special products but can also be used directly within an application via SQLScript. This provides new analysis options, especially in the context of statistical predictions.

12Function Libraries in SAP HANA

This book has already presented several options for analyzing operational business data using SAP HANA. Depending on the usage scenario, you can use direct native database functions in SAP HANA (e.g., via views and procedures) or benefit from the advanced SAP Business Warehouse (SAP BW) infrastructure (see Chapter 9). Regardless of the technology, analyses based on real-time data allow users to respond quickly to current developments. It’s a relatively new trend in business intelligence to take this approach one step further by using statistical models to make predictions on future developments. Such predictive analysis is used to enable decision makers to act before an event occurs, rather than to react after the fact. The mathematical models are quite complex, and the interpretation and calibration of the results generally require a good understanding of the business domain as well as the statistical algorithms. For this reason, data scientists have taken on increasingly important roles in recent years.

For many scenarios, you currently have to use special third-party software. Particularly for operational scenarios where time is important, this approach introduces a number of challenges. Due particularly to the required data extraction and conversion, a significant time delay and complexity are introduced to the process chain. SAP HANA offers special function libraries called Application Function Libraries (AFL) to provide an integrated option for some scenarios, which are based directly on the business data from the ABAP system. Before we discuss these libraries in more detail, we’ll present three specific application scenarios.

A classic usage scenario for statistical models is the creation of forecasts, such as predictions on the development of revenue, sales, or costs. Certain scenarios can also be created using forecasts for customer movements or business environments, which can play an important role within the strategic planning of a company.

The assessment and response to risks in live operations plays a major role in many industries today. You can imagine, for example, assessing the likelihood of potential defaults on payments but also analyzing the risks in a complex production process. Here, frequent use is made of key performance indicators (KPIs) and scorecards, which define limits and assess impacts. The use of statistical predictions enables early detection of exceptional situations and signals in running business processes. This results in new options for closer integration of operational planning, risk analysis, and control options, which opens up great potential for increased efficiency.

Another trend that is currently increasing in importance is related to the derivation of business rules from existing business processes (business rule mining). This approach can particularly support the modernization of a legacy application by identifying execution patterns and decision points. This allows the use of a service-oriented approach within the application that is controllable via business rules. An integrated solution has the advantage of being able to base itself directly on the existing application code.

The required functions are implemented in SAP HANA in function libraries. These libraries are written in C++ and provide highly optimized access to functions for advanced calculations and data-analysis scenarios. With SAP HANA SPS 5, the AFL package provides the following two libraries, which have been released for customer developments:

In the meantime, additional libraries are available, for example, the Data Quality Library that is used for SAP HANA within the scope of the Enterprise Information Management (EIM) module. Product-specific AFLs are also available, that is, libraries that are only deployed in combination with a special product and aren’t part of the SAP HANA delivery. Ultimately, a Software Development Kit (SDK) is available that allows partners to develop their own function libraries and have them certified by SAP.

We can’t present the full range of functions within the scope of this book. The number of functions is too great, and, as mentioned, some of the algorithms are quite complex or require mathematical knowledge of the statistical models. We’ll thus limit the discussion to individual examples to give you an overview.

[»]SAP Predictive Analytics 2.0

With SAP Predictive Analytics 2.0, SAP provides a powerful tool for advanced analyses, for example, for creating forecast models. This product is the successor of SAP Predictive Analysis and SAP InfiniteInsight, which originate from SAP’s acquisitions (Business-Objects and KXEN).

Using SAP Predictive Analytics, even nondevelopers can run advanced statistic analyses. When used in combination with SAP HANA, various function libraries are deployed to execute mathematical algorithms entirely in the SAP HANA database in the ideal case.

Because this involves separate products that are subject to licensing, we won’t discuss this solution in further detail in this book. For further information, refer to the SAP Community Network at http://scn.sap.com/community/predictive-analytics.

As an application scenario, we’ll again consider simple examples from the flight-data model in this chapter. We’ll determine a special key figure for seat utilization in the LINEAR_AVERAGE_UTILIZATION database procedure using a BFL function to illustrate the development of utilization over time by placing more emphasis on recent results than on those of the past. Furthermore, we’ll perform a segmentation of passengers into target groups in the CUSTOMER_SEGMENTATION procedure using a PAL function, which could provide helpful information, for example, in an airline’s customer rewards program.

We’ll first give you a brief overview of the functions and installation of standard AFL in the next section. Then, in Section 12.2 and Section 12.3, we’ll provide examples to describe how you can use AFL functions in your own implementations. For this purpose, we’ll create Core Data Services (CDS) views, respectively, to prepare the data in the required input format and ABAP database procedures for calling the functions.

12.1Basics of the Application Function Library

In this section, we’ll give you a technical overview of the functions of the standard AFL and introduce an example of one function from each of the two libraries: BFL and PAL.

The AFL library is dynamically linked to the index server of the SAP HANA database. Although it’s part of the delivery and license of the SAP HANA appliance, the hardware partner doesn’t preinstall it by default. However, it can be set up on the customer side using the SAP HANA Database Lifecycle Manager (hdblcm). (You’ll find the necessary documentation in the SAP HANA installation guide at http://help.sap.com/hana.) If you as the administrator want to check whether the AFL is installed in the system, you can use the system overview in SAP HANA Studio or Transaction ST04 (DBA Cockpit) in ABAP (see Figure 12.1 under Installed Plug-ins).

After the installation, you as an administrator have to perform some configuration steps, which we’ll discuss briefly now.

Checking the Presence of the AFL in Transaction ST04

Figure 12.1Checking the Presence of the AFL in Transaction ST04

You must configure a separate script server because the AFL functions for large datasets may take up a lot of resources (see SAP Note 1650957 for more information). The script server is a special index server process that doesn’t perform any tasks during normal database operations. This ensures that the execution of AFL functions doesn’t interfere with the operation of a standard application on SAP HANA.

The installation of the AFL results in the creation of the _SYS_AFL technical schema, which contains the AFL procedures. In addition, the administrator must assign a user (the database user of the SAP NetWeaver AS ABAP, in the case of access via ABAP) the following two roles for the execution of AFL functions in SAP HANA:

Some functions of the BFL and virtually all functions of the PAL are implemented as generic functions; that is, the structure of the input and output parameters (number of fields, column names, data types) isn’t defined a priori. This allows flexible usage but has the disadvantage that you, as a developer, can’t call these functions directly after the installation. Instead, you first have to generate a special form of the function—known as a wrapper function—using a special database procedure. To generate procedures, you as the developer additionally require the AFLPM_CREATOR_ERASER_EXECUTE role. In earlier versions (up until SAP HANA SPS 7), you had to create them manually via SQL. Now you can leverage the Application Function Modeler (AFM) as a graphical tool, which we’ll introduce based on a PAL function in Section 12.3.