107
SAP HANA Developer Self-Learning Guide Personal Spend Analysis on SAP HANA Author: Jordan Cao

Sap Hana Step by Step How to Guides

  • Upload
    -

  • View
    400

  • Download
    7

Embed Size (px)

DESCRIPTION

Sap Hana Step by Step How to Guides

Citation preview

  • trial system

    IBM Systems solution forSAP HANA Developer Self-Learning GuidePersonal Spend Analysis on SAP HANA

    Author: Jordan Cao

  • Learning is finding out what you already know. Doing is demonstrating that you know it. Teaching

    is reminding others that they know it as well as you do. We are all learners, doers, and teachers.

    Richard David Bach

    A technology marketing manager for SAP HANA, Jordan Cao has more than 15 years of experience in computing science, including roles as an SAP senior architect and solution manager. Jordan was part of the first SAP HANA in-memory Proof-of-Concept (PoC) project for the Banking field,

    and has participated in multiple SAP projects focused on scientific programming, software architecture, and web services-related tasks. He has a PhD in cloud computing, service-oriented architecture, and software engineering, as well as an MBA.

    ABOUT THE AUTHOR

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    TABlE Of cOnTEnTsToPIC 1:

    IntroductIon 4

    About this Quick Start Guide 5

    Before You Start: Pre-requisites and System Requirements 5

    Introducing SAP HANA 6

    SAP HANA Architecture overview 6

    Underlying design principle 6

    Advanced features 7

    Benefits of SAP HANA for developers 7

    About the Project 9

    Personal Spend Analysis Tool 9

    Infrastructure 10

    Data sources 10ToPIC 2:

    prepare Sap Hana deVeLopMent enVIronMent 11

    1. Add SAP HANA Instance 12

    2. Load the Data 14

    3. Check the data 20ToPIC 3:

    ModeLIng In Sap Hana 21

    1. Create a Package 23

    2. Create an Attribute View 24

    3. Create an Analytic View 28

    4. Create a Time Attribute View 33

    5. Link Views and Generate Time Data 36ToPIC 4:

    BuILdIng a report 38

    1. Create Universe 41

    2. Create a Dashboard 55

    3. Add a Trend in Dashboard 63

    4. Update the Universe model and the Query 68ToPIC 5:

    ModeLIng uSIng SQLScrIptS 72

    1. Create a Calculation View 74

    2. Show the Average Difference Trend 79

    3. Create Procedure and the Summary/Average Function 83

    4. Update Universe and Dashboard 88ToPIC 6:

    ModeLIng WItH r 92

    1. Install R Environment 95

    2. Modeling 97

    3. Update Universe Model 101

    4. Update Dashboard Model 105ToPIC 7:

    referenceS 109

  • Introduction Topic 1: Accessing a SAP HANA Test & Evaluation Environment

    Topic 2: Modeling in SAP HANA

    Topic 3: Building a Report Topic 4: Modeling using SQLScripts

    Topic 5: Modeling with R References

    SAP HANA Developer Quick Start Guide: Personal Spend Analysis on SAP HANA Introduction | 4

    Introduction The 1st Hour: Prepare SAP HANA Instance on Cloud

    The 2nd Hour: Modeling in SAP HANA

    The 3rd Hour: Build a Report

    The 4th Hour: Modeling using SQLScripts

    The 5th Hour: Modeling with R

    Reference

    TOpic 1: inTROdUcTiOn

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Introduction | 5

    About this Quick Start Guide

    This Guide gives an introduction to the SAP HANA development environment. It outlines the steps involved in developing a Personal Spend Analysis tool using a SAP Businessobjects dashboard.

    By following the Guide, you can learn how to:

    Create an SAP HANA development environment using Amazon Web Services Install an SAP HANA Client and Studio Use SAP HANA basic modeling technologies, define calculation view, and use

    R language and text search Build a dashboard

    After you finish developing your Personal Spend Analysis tool, you will have a better understanding of SAP HANAs:

    Underlying principles and concepts, application architecture, and development process

    Modeling language Benefits for developers

    Before You Start: Pre-requisites and System Requirements

    To successfully build the applications outlined in this Guide, you will need:

    Access to an SAP Businessobjects BI Platform Installed SAP BI Platform Clients An installed SAP Businessobjects Dashboard An SCN account Familiarity with Command line tools Internet Explorer Windows 7 or XP

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Introduction | 6

    Introducing SAP HANA

    SAP HANA is a game-changing, real-time platform for analytics and applications. While simplifying the IT stack, it provides powerful features like: significant processing speed, the ability to handle big data, predictive capabilities and text mining capabilities.

    SAP HANA Architecture overview

    SAP HANA is an in-memory database, as well as an in-memory Data platform. Typically, an application platform has five layers, which is illustrated in the following diagram.

    The application architecture supported by the SAP HANA platform combines the data storage function and the data computation layer, showing in the following diagram. SAP also provides multiple tools to seamlessly integrate with SAP HANA, such as data services and BI solutions to support each layers built around SAP HANA.

    Underlying design principle

    The SAP HANA platforms underlying design principle is to push the data computation logic to the data side. Using a Model-View-Controller (MVC) architecture as an example, the SAP HANA application architecture has a simplified structure with two components (MV architecture): Model (data storage and process) and View (data presentation and UI related control logic). The Controller module is divided into two parts merged into either the Model component or the View component.

    Information Composer & Modeling Studio

    Planning andCalculation Engine

    Real-time replicationservices

    Application Services(e.g. HTML 5 Server)

    Predictive Analysis &Business Function Libraries

    In-memory database

    Text Search

    R & Hadoop Integration

    Data Services

    Real-time analytics Real-time apps

    SAP NetWeaverBusiness Client

    SAP BusinessObjects solution

    MicrosoftExcel Others...(Open)

    SAP Business Suite Third-party systems

    A platform for a new class of real-time analytics and applications

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Introduction | 7

    Advanced features

    The SAP HANA platform provides several advanced features, including:

    scheduling engine computation engine security optimization compiler

    SAP HANA translates model artifacts into different domain-specific languages using specific compilers into a common representation called a calculation model. The calculation model is a directed acyclic graph with arrows representing data flows and nodes representing operations. This approach, along with the exclusion of loops and recursion, enable automatic massively parallel processing. The following illustration gives an architecture view of the execution controller:

    Benefits of SAP HANA for developers

    SAP HANA offers numerous benefits for developers, including:

    Simplified application logic: Application complexity can come from the complexity of the data model, algorithms, system configuration, and software architecture. By eliminating aggregates, indexes, and the component boundary, additional logic is no longer required. This reduces complexity and the effort required to define and maintain metadata:

    Elimination of application boundary: Moving the computation to the data platform means different applications will run on the same platform without a boundary. Each application can focus on its tasks and leave the

    Calculation model (data ow graph)

    Model optimizer (rule based)

    Model executor

    Calculation engineoperators

    Calculation engine

    Standard SQL Statement

    SQL processor

    Statistics

    SQL Script MDX* query Planning model Other language / model

    SQLScript compiler MDX compiler Planning engine Other compiler

    Intermediate results

    Database optimizer

    Database executer

    Row store Column store

    Script execution runtime

    Intermediate results

    Execute user-denedfunction

    Logicalexecution plan

    Physicalexecution plan

    R*

    R

    R

    R

    RR

    R

    R

    R RR

    *MDX = Mult dimonsional expression; *R = request

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Introduction | 8

    data management to the in-memory platform. This significantly reduces the need to implement and optimize data management.

    Elimination of additional indexes: In many cases, columnar storage eliminates the need for additional index structures. Column scanning speed and compression mechanisms especially dictionary compression allow high performance read operations. In most cases, additional indexes are not required.

    Elimination of materialized aggregates: Materialized aggregates try to increase read performance by storing the aggregates data; read operations do not need to compute them each time they are required. In-memory column stores make it possible to calculate aggregates on large amounts of data on the fly with high performance.

    Optimized: Moving computation to the data side simplifies design. Moving less data optimizes system computation. And high-speed in-memory computing makes it possible not to materialize aggregates, which further saves on costs. These optimized benefits come from:

    Optimized data management: HANA supports the representation of application-specific business objects (like OLAP cubes) and logic (domain specific function libraries) directly inside the database engine. This permits the exchange of application semantics with the underlying data management platform, which can be exploited to increase query expressiveness, and reduce the number of individual application-to-database round trips and the amount of data transferred between the database and the application.

    Optimized data accessing: The HANA database is optimized to efficiently communicate between the data management and application layers. For example, the HANA database natively supports SAP application servers data types. Future plans include integrating novel application server technology directly into the SAP HANA database cluster infrastructure, to enable interwoven execution of application logic and database management functionality.

    Optimizeddataprocessing: The HANA database comprises a multi-engine query processing environment. This offers different data abstractions supporting data of different degrees of structure from well-structured relational data to irregularly structured data graphs to unstructured text data. And column-based storage makes it easy to execute operations in parallel using multiple processor cores. Operations on different columns can be processed (searched or aggregated) in parallel by assigning different processor cores. Or the column can be partitioned into multiple sections by assigning different processor cores.

    Optimizeddataanalysis: The HANA database also supports efficient processing of both transactional and analytical workloads on the same physical database, leveraging a highly-optimized column-oriented data representation. This is achieved through a sophisticated multi-step record life cycle management approach.

    Unifiedadministrationtools: The SAP HANA database uses one set of administration tools for monitoring or backup and restore. Simplified data modeling with high compression rate.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Introduction | 9

    About the Project

    Personal Spend Analysis Tool

    Most credit card companies provide customers with tools to download their transaction history. Some providers even offer a very useful personal spend analysis tool to help customers analyze their spending. For example, Discover (www.discovercard.com) provides customers with a detailed analysis tool, which includes transactions and a spending history:

    Discovers personal spending analysis tool includes the following features:

    Summary section: for example, All Categories Pie Chart: summarizes transactions from different categories Bar Chart: shows spending trends, such as average spending, YTD, Last 12

    months, and Last 24 months summary. Transaction view: show the transaction date, post data, description, amount,

    and category.

    This Guide will demonstrate how to build a similar personal spending analysis. By following the steps, you will build your own personal spend analysis tool using SAP HANA and an SAP Businessobjects dashboard. You can also download your spending data and follow the instructions to analyze it.

    The start guide provides transaction history sample data. You can expand the scope of the project to include Enterprise financial data, such as banking transaction history analysis, by using data loaded from the SAP ECC core banking component, which has a more complex data structure. You will be able to provide more advanced analyses and deal with a bigger data volume.

    Moreover, you can also build more advanced features to evaluate your own spending. We encourage you to share your work, comments and new features at www.experiencesaphana.com.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Introduction | 10

    Local Machine

    SAP Hana client SAP HANA studio HANA data Loader (only load

    data for this example) csv source data

    Data Source and Data Loading

    AWS HANA Server

    SAP HANA Server R

    Data Storage & Data Computation

    AWS Windows Server

    SAP BusinessObjects BI Platforms SAP BusinessObject BI Client SAP BusinessObjects Dashboard

    Data Representation

    SAPHANA

    SAP In-Memory Computing Engine

    SAP Replication Server RInterface Libraries

    SQL(ODBC/JDBC)

    SQL(ODBC/JDBC)

    Semantic Layer

    Dashboards

    CSV TEXT DATA

    Infrastructure

    Before you build the example application, you need to understand the infrastructure. Below is an illustration showing the system landscape with flow in a three-layer view:

    This example uses a dashboard to show the data through a semantic layer. Multiple tools can show the data, which are listed in the application architecture.

    Data sources

    This Guide uses a simple data structure with two tables. The example application uses psa_category as the table name.

    Name SQL Sample Data

    Data Create column table DATA(ID INTEGER not null,TRAN_DATE DATE null,POST_DATE DATE null,DESCRIPTION VARCHAR (100) null, AMOUNT DOUBLE null,CATEGORY_ID INTEGER null,primary key (ID))

    This is the core transaction data set.

    Category Create column table CATEGORY( CATEGORY_ID INTEGER not null, CATEGORY_TEXT VARCHAR(30) null, primary key(ID))

    This table provides the text description of the category.

    The structure can be expanded with more information to support more analyses. For example, an additional column could be added to identify if a transaction is a deposit/credit.

  • TOpic 2: pREpARE sAp HAnA dEVElOpMEnT EnViROnMEnT

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 12

    STEP 1

    open the SAP HANA Studio and choose either the Modeler Perspective. Please make sure you did not choose Administration Perspective.

    STEP 2

    In the Navigator Panel, right-click the empty space and choose Add System... from the context menu.

    1. Add SAP HANA Instance

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 13

    STEP 3

    on the pop-up, enter:

    a. The IP as the host name. (Use cloudimdb for the HTA environment)b. 00 as the System Number.c. A name for your HANA server as Description.d. Click on Next.

    STEP 4on the next screen, enter:

    a. SYSTEM as the User Name

    b. manager as the Password for AWS instance (CodeJam12 for the HTA environment)

    Note: These can both be changed from the HANA Studio. The tool will notify to setup password recovery setting. Lets ignore this step for now.

    Click Finish.

    Add SAP HANA Instance

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 14

    2. Load the Data

    After installing the HANA client tools and modeling studio, you will need to load the data into the HANA instance to start implementing the example application.

    While data loading can be very complex, SAP provides multiple solution for flexible data loading. For this simple example, we will use the basic text data file loading feature provided by SAP HANA modeler studio. It can directly load your local files into the HANA system.

    STEP 1

    Open the HANA modeler studio, and click on the File/Import menu

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 15

    STEP 2

    The HANA studio pops up a Import wizard, please select the Data from Local File

    STEP 3

    Select the HANA instance, and click on the Next button.

    Load the data:

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 16

    STEP 4

    Click on the Browser button in the source file option.

    STEP 5

    Select the sample_category.csv file provided to you in the example package.

    Note: we store them in C:\PSA directory in the HTA environment.

    Load the Data:

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 17

    STEP 6

    Select the Header row exists and give the Schema to be SYSTEM and the Table Name to be PSA_CATEGORY.

    STEP 7

    In this Manage Table Definition and Data Mappings diagram to define the table structure. Select the check box to set the CATEGORY_ID to be the key field. Click on the Next.

    Load the Data:

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 18

    STEP 8

    Review the data and click on Finish.

    STEP 9

    Similarly, redo the File/Import menu and in the import wizard. At the Define Import Properities step, click on Browser, and select the sample_transaction.csv file provided to you in the example package.

    Select the Header row exists and give the Schema to be SYSTEM and the Table Name to be PSA_TRANSACTION.

    Load the Data:

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 19

    STEP 10

    Select the check box to set ID to be a key field. And change the data type for TRAN_DATE and POST_DATE from NVARCHAR to DATE.

    STEP 11

    Review the data and click on Finish. You should see these two tables that are successfully imported into this system

    Load the Data:

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Prepare SAP HANA Development Environment | 20

    STEP 1

    After successfully loading the data, you will be able to view the PSA_TRANSACTION and PSA_CATEGORY tables in the SAP HANA Studio. You can right click on the table name, for example, PSA_TRANSACTION, and select Open Definition menu. You can see the table definition in this view.

    STEP 2

    To preview the data, you can select the Data Preview menu, and then the data will appear in the preview window as above.

    3. Check the data

  • ABOUT THE pROjEcTTOpic 3: MOdEling in sAp HAnA

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 22

    Your original data are loaded into SAP HANA as database tables. They can be modeled as multiple different views. Those views define all necessary data aggregation, computation, or representation.

    Tables are tabular data structures, with each row identifying a particular entity, and each column having a unique name. Data fields of one row are called the attributes of the entity. Note: The word attribute has multiple meanings in this Guide. It may denote a table column, a particular data field of a table row, or the contents of a data field. The meaning can be gleaned from the context.

    Views are combinations and selections of data from tables modeled to serve a particular purpose. Views always appear like readable tables, i.e., database operations that read from tables can also be used to read data from views. In SAP HANA, there are three different types of views: attribute, analytic, and calculation.

    Attribute Views

    Attribute views are used to give master data tables context. This context is provided by text tables which give meaning to the master data. For example, in this example, our fact table or analytic view contains some numeric category ID for each transaction record.

    You can link the text description to each category ID using an attribute view. You can then display the category description, instead of their IDs, providing the context for the master data table.

    Attribute views are used to select a subset of columns and rows from a data table. Since it is of little use to sum up attributes from master data tables, there is no need to define measures or aggregates for attribute views. You can also use attribute views to join master data tables to each other.

    Analytic Views

    Analytic views are used to build a data foundation based on transactional tables. You can create a selection of measures (sometimes referred to as key figures), add attributes and join attribute views. Analytic views leverage the computing power of SAP HANA to calculate aggregate data, e.g., the number of cars sold per country, or the maximum power consumption per day.

    These views are defined on at least one fact table, for example, a table containing one row per sold car or one row per power meter reading. Fact tables can be joined to allow access to more detailed data using a single analytic view.

    Analytic views can be defined on a single table, or joined tables. They can contain two types of fields/columns, so-called measures and attributes. Measures are fields for which an aggregation must be defined. If analytic views are used in SQL statements, the measures have to be aggregated using the SQL functions, such as SUM, MIN, or MAX. Attributes can be handled as regular columns, which do not need to be aggregated.

    Calculation Views

    Calculation views are used to provide composites of other views. More details will be covered in the subsequent chapters.

    Start Building Your HANA Project

    In this Chapter, we will focus on creating Attribute and Analytic Views..

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 23

    STEP 1

    Choose the Modeling Perspective, and on the project tree, you will see the Content item. Right click on this item.

    Select New/Package from the context menu. The HANA studio Wizard screen will appear.

    STEP 2

    Enter the name and description in the window, then click OK. For example, given the name psa, and the description Personal Spend Analysis

    The new package will be created.

    1. Create a Package

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 24

    2. Create an Attribute View

    STEP 1

    Right click the psa package you just created.

    Select New > Attribute View from the context menu.

    The HANA studio wizard screen will appear.

    STEP 2

    Create the Attribute View for the PSA_CATEGORY table:

    1 Enter ATT_CATEGORY in the Name and Description fields.

    2 Choose Standard Attribute View Type.

    3 Click Next.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 25

    STEP 3

    The Wizard will ask you to choose a table:

    1. Select the CATEGORY table.

    2. Click Finish.

    The Attribute View will be created.

    STEP 4

    In the Attribute View panel:

    1. Right click on CATEGORY_ID, and select Add as Key Attribute from the context menu.

    2. Right click on CATEGORY_TEXT, and select Add as Attribute from the context menu.

    Create an Attribute View

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 26

    Create an Attribute View

    STEP 5

    To check the model, click the Attribute View table and choose Validate from the context menu.

    STEP 6

    To activate the model, click the Attribute View table, and choose Activate from the context menu.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 27

    STEP 7

    To preview the output, check Data Preview in the Attribute View context menu.

    Create an Attribute View

    STEP 8

    The output window will appear.

    Note: To simplify the modeling, this Attribute View has the same output as the table. More advanced models can be defined in Attribute View.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 28

    3. Create an Analytic View

    STEP 1

    Right click the psa package.

    Select New > Analytic View from the context menu.

    STEP 2

    The Analytic Wizard screen will appear. It will ask for the Name and Description of the analytic view. Use the name ANA_TRANSACTION. Note: For this application, you dont need to define the currency conversion schema now. Click Next.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 29

    STEP 3

    Select the fact tables that have the measures. In this example, the PSA_TRANSACTION table is the fact table and the Amount field is the measure. Note: You can also add tables to the Analytic view later.

    Click Next.

    Create an Analytic View

    STEP 4

    Choose predefined Attribute Views. Note: These can be added later.

    1. For this application, choose the PSA_CATEGORY Attribute View you created earlier.

    2. Click Finish.

    The Analytic Views will be created.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 30

    Create an Analytic View

    STEP 5

    Define the attributes in Analytic View:

    1. For this application, hold down the Ctrl key, and left-click on the ID, TRAN_DATE, POST_DATE, DESCRIPTION, and CATEGORY_ID attributes column.

    2. Right click on one of the attributes.

    3. Select Add As Attribute item from the context menu.

    STEP 6

    Items successfully added into the Private Attribute group will appear on the right output panel. Add a measure. The Analytic View will need to have at least one.

    1. For this application, choose the Amount as the measure.

    2. Right click on the Amount column, and select Add as Measure from the context menu.

    The Amount added into the Measures group will appear on the right output panel.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 31

    STEP 7

    Create a link between the Table and Attribute Views:

    1. In Attribute Views, switch from Data foundation tab to Logical View tab.

    2. Drag and drop CATEGORY_ID from the PSA_CATEGORY table to CATEGORY_ID in the Data Foundation table:

    The tool automatically creates a line between the two columns to show the two views are now joined.

    Create an Analytic View

    STEP 8

    To validate the data, choose Validate from the context menu. And then, you need to choose Activate from the context menu to activate the Analytic View,

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 32

    Create an Analytic View

    STEP 9

    To preview the data, select Data Preview from the context menu.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 33

    STEP 1

    To support time-related computation, create a new Time Attribute View.

    From Attribute Views, click New.

    4. Create a Time Attribute View

    STEP 2

    Complete the Attribute View screen. Use the ATT_TIMEVIEW:

    1. Enter a Name and Description.

    2. For Attribute View Type, select Time.

    3. For Calendar Type, select Gregorian.

    4. For Granularity, select Date.

    5. Click the Auto Create checkbox.

    6. Click Finish.

    The Time Attribute View will be created.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 34

    Create a Time Attribute View

    STEP 3

    By default, the Time Attribute View includes multiple predefined attributes. You must delete these attributes:

    1. Select all pre-defined attributes.

    2. Right-click on one of the selected attributes.

    3. Select Remove from the context menu.

    STEP 4

    Add DATE_SQL as the Key Attribute, and Save this view.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 35

    STEP 5

    Add the following items as Attributes: CALQUATER, CALMONTH, CALWEEK, YEAR_INT, QUARTER_INT, MONTH_INT, WEEK_INT, WEEK_YEAR_INT, DAY_OF_WEEK, DAY_INT

    Create a Time Attribute View

    STEP 6

    To activate the new Time Attribute View:

    1. Right-click on the new Attribute Views.

    2. Select Activate from the context menu

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 36

    5. Link Views and Generate Time Data

    STEP 7

    Open the ANA_TRANSACTION analytic view:

    1. Select the Logical view.

    2. Drag and drop the new TIME_VIEW into the Logical view, and then link the TRANS_DATE from Data Foundation with DATE_SQL from TIME_VIEW.

    3. Right click on the ANA_TRANSACTION analytic view, and select the validate menu to validate the model.

    4. Click on the Activate button to activate the new analytic view.

    STEP 8

    Choose Help > Quick Launch.

    Click Generate Time Data

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling in SAP HANA | 37

    STEP 9

    Complete the Generate Time Data screen:

    1. For Calendar Type, select Gregorian.

    2. For From Year, enter 2011.

    3. For To Year, enter 2012.

    4. For Granularity, select DAY.

    5. Click Generate.

    Link Views and Generate Time Data

    STEP 10

    The generated time data is stored in _SYS_BI.M_TIME_DIMENSION. To review the time data, right-click on the ATT_TIMEVIEW, and choose Open Data Preview. Add then you can see the data output in this view.

  • ABOUT THE pROjEcTTOpic 4: BUilding A REpORT

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 39

    SBo 4.0 Business Intelligence Platform

    Intelligence refers to the ability to make the best decision from information available at any given moment. Platform is about the cost. A Business Intelligence Platform provides concentrated services that can be reused by multiple BI tools. It benefits customers by allowing them to operate a simpler system at a lower cost.

    BI tools include Crystal Report, Dashboard, Web Intelligence, Pioneer Web, Business Explorer, Live Office, BI Widget, and BI Mobile. The platform provides a set of features to build intelligence applications, not business features (like the SAP Business Suite).

    A unified infrastructure delivers a set of services, ranging from low-level technical services to high-level BI services. Core platform services include communication, runtime containers, landscape management, integration components, repository management, user management, session management, job scheduling, enterprise data source access, or automation services.

    Businessobject BI platforms communication platform is based on a lightweight CORBA implementation. The Open Computing Architecture (OCA) framework includes complete lightweight CoRBA features, such as failover, server groups, load balancing and caching features.

    This Guides application uses a Businessobjects BI platform to represent the data. The Dashboard tool is built upon a Universe.

    Universe on information models

    A Universe is a set of design time information (InfoObjects) that defines business objects (Business Layer) to be exposed to a BI user and all related information (Data foundation and bindings) that enable to access this information from a data source at consumption time. A Universe is a resource container including three types of information. Using this Guide, you will create one project item for each type of content:

    Connection: Represents the bind to source entities. It describes the connection parameters and the processing capabilities of a source.

    Data foundation: Represents an abstraction of a relational data source connected through the connection.

    Business layer: Represents the BI user view on the data. It enables users to normalize and reduce the view on an entity from a relational source.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 40

    Dashboards

    A dashboard is a comprehensive view of related information gathered from back-end data sources, usually in a graphics-rich presentation format. It has the following unique features:

    Free-form, interactive or template-based design, including a library of commonly used visualization

    Interactive and real-time

    Ability to embed in portals, reports, presentations and PDFs

    Flexible connectivity (semantic layer, SAP NetWeaver BW, and other live data sources)

    The core principle of dashboards is to produce a ready-to-embed Flash file (SWF) that will autonomously manage data retrieval and visualization in the embedding space. Dashboard design is based on queries to access data. Besides queries from universe [CAPITALIZATION], the tool also includes many ways to define data access, such as XML Data, Portal Data, Web Services Query (see QaaWS), Crystal Reports, Web Intelligence documents, or Universe Objects in Live Office.

    Dashboard technology uses a Microsoft Excel spreadsheet to organize the source data and represent the control logic of the dashboards UI components. SWF components implement data presentation details.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 41

    1. Create Universe

    STEP 1

    open the Businessobject Information Design Tool (IDT). And click on the button to insert one session.

    STEP 2

    Go to Repository Resources to add your BOE server information, and login. If you dont have the BoE server information, please contact your administrator.

    1. open the IDT tool.

    2. Right-click on the Repository Resource panel.

    3. Select Add New System from the context menu.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 42

    Create Universe

    STEP 3

    Choose on File > New, or click New on the drop down menu.

    STEP 4

    In the New Project window, enter the Project Name and Project Location. Use the psa_project to be the project name.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 43

    STEP 5

    Right-click on psa_project, and select New > Relational Connection from the context menu.

    STEP 6

    Enter a Name and Description in New Relational Connection window. Use psa_connection as the resource name.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 44

    STEP 7

    Select a middleware driver by clicking SAP/SAP HANA database 1.0/JDBC Drivers

    STEP 8

    Enter your Username and Password, and the Server host and port.

    In the HTA environment, it will be SYSTEM and CodJam12.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 45

    STEP 9

    Accept the default connection parameters. To create the relational connection, click Finish. Expanding the psa_project project, we can see a new relational connection.

    STEP 10

    The relational connection is successfully created. We can use the Test Connection function to check if the relational connection configuration is set correctly.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 46

    STEP 11

    If all configuration is set correctly, you should be able to see this success connected dialog.

    STEP 12

    A connection is included in the project. However, it is not secure. To secure the connection, you must publish the connection to a server. Right-click on the connection, and select Publish Connection to a Repository.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 47

    STEP 13

    Enter the destination BoE server information in the IDT pop-up window, and click Next. (Note: Choose the BOE server information that the administrator provides to you.)

    STEP 14

    To save the connection, accept the default location, and click Finish.

    If the following message appears The connection was published successfully a secure connection was successfully created in the BoE server.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 48

    STEP 15

    To create a secure connection shortcut to your local project, click Yes. You will use this shortcut in the following steps.

    STEP 16

    Click on Close. You now have two connections to your project. Remember to use the secure one.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 49

    STEP 17

    Right-click on your psa_project project, and select New > Data Foundation.

    STEP 18

    To create the data foundation, enter the Name and Description, and click Next.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 50

    STEP 19

    Choose a Single Source data foundation type, and click Next.

    STEP 20

    Choose the connection with a .cns extension (secure connection), and click Finish.

    The data foundation model will be created using the secured relational connection

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 51

    STEP 21

    Expand _SYS_BIC, and double-click psa/ANA_TRANSACTION. Or you can drag and drop this item into the right panel, showing in this example. The analytic view will appear in the right panel. And the data foundation is created. Choose File > Save.

    STEP 22

    Right-click on the psa_project project to create a Business Layer.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 52

    STEP 23

    Choose Relational Data Foundation as the data source, and click on Next. In the next window, you need to enter a Name and Description, and then click on Next.

    STEP 24

    Choose the data foundation you created in the previous steps, and click Finish. The new business layer will be created. Expand psa/ANA_TRANSACTION, and select Amount. It will appear as an attribute.

    Create Universe

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 53

    STEP 25

    Define an aggregation function for this field to make it a measure. Right-click Amount, and choose Turn into Measure with Aggregation Function Sum. Now, the icon of the Amount filed becomes the measures icon.

    Create Universe

    STEP 26

    Right click on the business layer we just created and publish it to a repository by selecting Publish/To a Repository.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 54

    Create Universe

    STEP 27

    To check the universes integrity, click Check Integrity, then click on Next.

    STEP 28

    To store the business layer file, accept the default location, and click Finish. The tool will show the message Universe published successfully.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 55

    STEP 1

    In this step, you will open the dashboard template file personal spend analysis template.xlf.

    In HTA environment, this template file is stored in C:\psa folder.

    2. Create a Dashboard

    STEP 2

    To create the first query, click Add Query in the Query Browser panel.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 56

    Create a Dashboard

    STEP 3

    The Add Query wizard will appear. Select Universe as the data source.

    STEP 4

    Select the published psa_businesslayer.unx file. The business layer will be created.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 57

    STEP 5

    To create the query for the transaction table, double-click on the following fields: Date Sql, Post Data, Description, Amount, and Category Text. All fields will be added to Result Objects. Click on the Property button.

    Create a Dashboard

    STEP 6

    Change the querys name to Transaction View Query, click OK, and then Next. The Preview Query Result view will appear.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 58

    Create a Dashboard

    STEP 7

    This page will test and refresh the query. It executes the query and list the output in this page. Click on Next.

    STEP 8

    Accept the default Usage options. It includes the option to set the trigger or the time to refresh the data.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 59

    STEP 9

    To build a UI component to show values, choose Selector/List View from the Components panel.

    In the List View property panel, click on the Display Data fields drop-down list, and select Query Data.

    The Select from Query window will appear. The Transaction View Query you just created will appear in the window.

    Create a Dashboard

    STEP 10

    Select all fields in the right side window, and click OK.

    The data will appear in this list view.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 60

    Create a Dashboard

    STEP 11

    Modify the Date Sql columns display name to be Transaction Date in the property view.

    STEP 12

    Create the second query to load data for the pie chart:

    1. Click Add Query.

    2. Follow Step 1 to open the business layer you created earlier.

    3. Choose Amount and Category Text for the Result Set.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 61

    STEP 13

    In Query Properties view, change the querys name to Pie Chart Query. The query is defined.

    Create a Dashboard

    STEP 14

    Model the UI components:

    1. Choose Charts > Pie Chart from the Components panel, and drag-and-drop Pie Chart onto the center canvas.

    2. Delete Chart and Subtitle titles.

    3. To define the Values and Labels fields, select Query Data from the drop-down menu.

    The Select from Query window will appear.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 62

    Create a Dashboard

    STEP 15

    Select the Pie Chart Query you just created.

    1. Choose Amount for Value field, and click OK.

    2. Choose Category Text for the Label field, and click OK.

    3. Set the label to the CATEGORY_TEXT field.

    STEP 16

    The values, category text, and the labels fields will be updated. And you will get an updated pie chart to show the correct data.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 63

    3. Add a Trend in Dashboard

    STEP 1

    Drag-and-drop a Line Chart onto the dashboard.

    The template dashboard provides three trend chart choices: Summary, Average Diff, and Average. They are linked to $B$5:$D$5 in the Excel file Spending History Data page. The output of the selection will be stored in $G$5. When you make the selection, the selected label will be copied into $G$5, which will be used to decide which query will be updated.

    To make the diagram bigger, delete the Chart and Subtitle contents.

    STEP 2

    once settings are complete, Spending History will appear on the dashboard.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 64

    STEP 3

    On the Build Query screen, choose Amount and Month Int as result objects.

    Add a Trend in Dashboard

    STEP 4

    Open the query, change the name to Spend History Trend View, and click OK.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 65

    Add a Trend in Dashboard

    STEP 5

    Go back to the query wizard, and click Next. To move to the last page, click Next again.

    STEP 6

    On the Usage Options screen, Select Refresh Before Components Are Loaded, and set the Trigger Cell to be Selector!$G$5;

    And then select the When Value Becomes, and set its value to be Selector!$C$5. Return to the wizard and click on Ok.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 66

    Add a Trend in Dashboard

    STEP 7

    Go to the query browser and select each result object:

    1. Expand Insert in Spreadsheet.

    2. Click on the highlighted button to choose the correct spreadsheet cells to store the output.

    Note: These fields are the input fields defined for the column chart earlier.

    STEP 8

    Configure the Category (X) Axis. Set it to be Spending History Data!$A$2:$A$13. And then set the Data range to be Spending History Data!$B$2:$B$13.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 67

    4. Update the Universe model and the Query

    STEP 1

    Make a copy for the Amount field, and paste it into the same data foundation

    STEP 2

    Rename it to be Avg Amount, and change the Project function to be Average and edit the SELECT box to change the sum() function to avg(). And then publish it to the repository.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 68

    Update the Universe model and the Query

    STEP 3

    Go back to the dashboard tool, click on the Add query button to add the new query into dashboard model.

    STEP 4

    Drag Month Int and Avg Amount into the Result objects.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 69

    Update the Universe model and the Query

    STEP 5

    Click on Query Properties button. And provide a special name for this query. Click on the Next button, you can review the output in the next page.

    STEP 6

    Configure the Usage Options. Because this line chart is designed for average trend. We need to configure the Trigger Cell. Click on the selector button and set it to be Selector!$G$5.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Building a Report | 70

    Update the Universe model and the Query

    STEP 7

    Choose the When Value Becomes, and set it to be Selector!$C$5.

    STEP 8

    Configure where to store the output for the Month Int. Since we know the output will be 12 months. We will use Spending History Data!$A$2:$A$13. Click on OK;

    And similarly, we will define the Spending History Data!$B$2:$B$13. Click on OK. Now, the query data will be loaded into the defined Excel ranges, when the trigger is activated. And then the line chart will show the trend correctly.

  • ABOUT THE pROjEcTTOpic 5: MOdEling Using sQlscRipTs

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 72

    Calculation views are based on the result of a SQLScript. These scripts can join two or more data flows or invoke built-in or generic SQL functions. They can be defined as either graphical views or scripted views depending on how they are created.

    Graphical views can be modeled using the graphical modeling features of the SAP HANA Information Modeler. Scripted views are created as sequences of SQLScript statements. In essence, they are SQLScript procedures with certain properties.

    Calculation views can be used in the same way as Analytic views, which one key difference: several fact tables can be joined in a Calculation view. Also, calculation views must have at least one measure.

    SQLScript functions composed of SQL queries and function calls can be represented as acyclic data flow graphs. These functions, implemented in SQLScript language, are typically transformed into calculation models that contain only one transformation node of type SQLCcript. In some cases, a more complex graph can be created with SQL nodes for embedded SQL queries and nodes for imperative code sequences.

    Each node has a set of inputs and outputs, and an operation that transforms the inputs into outputs. In addition to their primary operation, each node can also have a filter condition for filtering the result set. The operations inputs and outputs are table-valued operands. Inputs can be connected to SAP HANA tables or node outputs. Calculation models support a variety of node types:

    Nodes for set operations, such as projection, aggregation, join, union, minus, and intersection

    SQL nodes that execute an SQL statement that is an attribute of the node

    Scripting nodes for describing complex operations that cannot be described with a graph of data transformations. The function of such a node is described by a procedural script.

    To enable parallel execution, a calculation model may contain split and join operations. A split operation is used to partition input tables for subsequent processing steps based on partitioning criteria. operations between split and join operations may then be executed in parallel for the different partitions.

    SAP HANA also provides a set of CE functions, which can be used to replace some SQLScripts. They provide better optimization and better performance. This session only shows the basic capability of the calculation view. The CE function will be discussed in the following sections.

    Continue Building Your Project

    This example will implement one special feature to demonstrate the Calculation view: the trend of the difference of the average amount comparing to previous month in a time line. You will calculate the average amount, and use the average amount of the successive month minus the average amount of the current month. A derived table will be used to implement this feature.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 73

    STEP 1

    Open SAP HANA Modeler Studio. Right click on your psa project, and select New/Calculation View.

    1. Create a Calculation View

    STEP 2

    Enter a Name (CAL_AVG_TREND), choose SQL Script as the View Type, and click Finish.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 74

    Create a Calculation View

    STEP 3

    The Calculation view will be created.

    The left panel shows a simple graphic with two boxes: Script_View and Output. Script_View is connected to Output through a line and is the place to define the SQLScript logic. Output is the place to define the output field of the Calculation view.

    STEP 4

    Click on the Script_View box. The SQLScript editor will appear.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 75

    STEP 5

    Copy and paste the left side code into the editor, in-between BEGIN and END. This code will generate the average difference between current month and previous month.

    Create a Calculation View

    STEP 6

    Right-click on the Output of Script_View panel to define output from the Script_View.

    This output must have the same name, type, and order as the SQLScript statement used to assign a value to var_out. Note: var_out is the special variable in the calculation view. It represents the only output parameter from the calculation view.

    var_out = SELECT SUM(T2.AMoUNT-T1.AMoUNT) AS AMoUNT, T1.MONTH_INT AS MONTH_INTFRoM(SELECT AVG(AMOUNT) AS AMOUNT, MONTH_INT FRoM _SYS_BIC.psa/ANA_TRANSACTION GROUP BY MONTH_INT) AS T1,(SELECT AVG(AMOUNT) AS AMOUNT, MONTH_INT FRoM _SYS_BIC.psa/ANA_TRANSACTION GROUP BY MONTH_INT) AS T2WHERE T1.MONTH_INT = T2.MONTH_INT - 1GROUP BY T1.MONTH_INT;

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 76

    Create a Calculation View

    STEP 7

    To define the Calculation view output, select the Output box. The Script_View output box will appear.

    Right-click on AMOUNT, and select Add As Measure to define AMOUNT as a measure.

    STEP 8

    Right-click on MONTH_INT, and select Add as Attribute to set this as an attribute.To activate the Calculation view, right-click on the Calculation view, and select Activate.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 77

    STEP 11

    To preview the output data, select Data Preview.

    Create a Calculation View

    STEP 12

    Review the output data from the activated calculation view.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 78

    STEP 1

    Open the IDT tool. Open the data foundation item, select the CAL_AVG_TREND view in the _SYS_BIC folder, and drag-and-drop it onto the Master view.

    2. Show the Average Difference Trend

    STEP 2

    Open the business layer. The CAL_AVG_TREND view is already in the data foundation panel.

    Drag this view onto the psa_businesslayer, and change the Amount to measure. (Recall what we did before to change the Amount to be a measure.)

    After this step, the business layer is updated. Save the business layer and publish it to a repository.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 79

    STEP 3

    open the dashboard project and add a new query. Go to the dashboard. on the Build Query screen:

    1. Select the Universe. Note: The new views you recently added are included in this list.

    2. Select the new Calculation view item.

    3. Select Month Int and Amount as Result Objects.

    Show the Average Difference Trend

    STEP 4

    Name this query Mothly Avg Dif Trend Data, and click OK. To go to the last step, click Next, and click Next again. Review the output value from this query in the next step.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 80

    Show the Average Difference Trend

    STEP 5

    Define when to refresh the query:

    1. For Trigger Cell: select the Excel cell related to the Radio Button selector output ($G$5).

    2. Set When Value Becomes to Selector!$D$5 .

    3. Set the Selector!$G$5 to the Trigger Cell.

    (Recall what we did before for the summary trend and average trend.)

    STEP 6

    Select the option When Value Becomes and click on the selection button. Set the Selector!$D$5 for this option. And then click on OK to finish the process.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 81

    STEP 7

    To assign a range from the Excel table to store the output, select Result Objects, and click on the highlighted button. (Recall the excel range we used to define the Line chart.)

    This step demonstrates we use selector to control the query. Three queries are mapping to the same Excel ranges which are used by the Line Chart. When the queries are refreshed, the Excel data is updated and the Line Chart will be updated.

    Show the Average Difference Trend

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 82

    STEP 1

    Before you can define the summary/average function, you must create a date_range table to define how many different ranges to calculate. Open the SQL Editor. Copy the codes and execute it.

    For this project, we calculate 1-month, 3-month, 6-month, and 12-month ranges.

    3. Create Procedure and the Summary/Average Function

    STEP 2

    Right-click on the project name, and choose New > Procedure.

    CREATE COLUMN TABLE DATE_RANGE(RANGE INT PRIMARY KEY);INSERT INTO DATE_RANGE VALUES(1);INSERT INTO DATE_RANGE VALUES(3);INSERT INTO DATE_RANGE VALUES(6);INSERT INTO DATE_RANGE VALUES(12);

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 83

    Create Procedure and the Summary/Average function

    STEP 3

    Enter a name (PRO_GET_TIME_RANGE), and click Finish.

    The procedure will be created.

    STEP 4

    Copy and paste the above code into the right-side editor, in-between BEGIN and END:

    This code will generate a time range for the four periods (1,3,6,12 months). It uses the latest date in the transaction data and calculates each time periods date as the start time.

    TIME_RANGE_OUT = SELECT L.DATE_SQL AS DATE_FROM, D.LAST_DATE AS DATE_TO, R.RANGE AS RANGE FROM_SYS_BIC.psa/ATT_TIMEVIEW AS L, (SELECTMAX(TRAN_DATE) AS LAST_DATE FROM SYSTEM.PSA_TRANSACTION) AS D,SYSTEM.DATE_RANGE AS R WHERE DAYS_BETWEEN(L.DATE_SQL, D.LAST_DATE) = R.RANGE * 30;

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 84

    STEP 5

    Define the output parameters:

    Enter the same name as the variable used in SQLScript. For this project, the name is TIME_RANGE_OUT. TIME_RANGE_OUT = SELECT

    The output structure needs to be the same as the output defined in the SQLScript statement. SELECT L.DATE_SQL AS DATE_FROM, D.LAST_DATE AS DATE_TO, R.RANGE AS RANGE . Unlike the Calculation view, this procedure can have multiple outputs.

    After creating the procedure, we can right click on the procedure and select the Activate menu to activate this new procedure.

    Create Procedure and the Summary/Average function

    STEP 6

    Right click on the calculation view folder in the navigator panel and then select the New menu to create a new calculation view to generate the average outputs. Give the new Calculation view a name CAL_GET_AMOUNT_REPORT.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 85

    STEP 7

    Copy and paste the sample codes into the editor in between BEGIN and END.

    Create Procedure and the Summary/Average function

    STEP 8

    Right-click on Output of Script_View/Output Parameter, and select Edit. The output definition should be the same as the SQLScript, which includes the RANGE and the AMoUNT.

    CALL _SYS_BIC.psa/PRO_GET_TIME_RANGE(TIME_RANGE); AVG_OUTPUT = SELECT R.RANGE AS RANGE, AVG(AMOUNT) ASAMOUNT, AVG AS OUTPUT_TYPEFROM _SYS_BIC.psa/ANA_TRANSACTION AS D, :TIME_RANGE AS RWHERE D.DATE_SQL >= R.DATE_FROM AND D.DATE_SQL = R.DATE_FROM AND D.DATE_SQL

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 86

    Create Procedure and the Summary/Average function

    STEP 9

    Click on the Output box to define the output of the calculation view.

    Right-click on AMOUNT, and select Add As Measure.

    And then, holding the control key down, select RANGE and OUTPUT_TYPE.

    To define them as attributes, right-click, and select Add as Attribute.

    STEP 10

    Right click on the new calculation view and select the Activate menu button to activate the Calculation view.

    And select the Data Preview button. You can review the output data from the activated calculation view.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 87

    STEP 1

    Open the data foundation. Select the new view psa/CAL_GET_AMOUNT_REPORT generated in the _SYS_BIC, and drag-and-drop it onto the Master view.

    4. Update Universe and Dashboard

    STEP 2

    open the business layer. Select the new view from the data foundation, and drag-and-drop it onto the business layer tree.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 88

    Update Universe and Dashboard

    STEP 3

    Convert the Amount field to be a measure and set Sum as the aggregation function.

    After this step, the universe is updated. Save the business layer, and publish it to a repository.

    STEP 4

    open the dashboard and a new query in the dashboard designer tool. Select Range, Amount and Output Type as Result Objects.

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 89

    Update Universe and Dashboard

    STEP 5

    Give the query this name: Amount Report Data. Click on OK button to return to the wizard screen. There is no other configuration changes are required. And then click OK to exit the wizard.

    STEP 6

    Define when to refresh the query:

    1. Deselect Refresh Before Components Are Loaded

    2. For Trigger Cell: select the Excel cell related to the Radio Button selector output ($G$5).

    2. Set When Value Becomes to Selector!$D$5 .

    3. Set the Selector!$G$5 to the Trigger Cell.

    (Recall what we did before for the summary trend and average trend.)

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling using SQLScripts | 90

    STEP 7

    Select the Result objects one by one. Assign these outputs to the corresponding Excel cells in the Report tab.

    Configure the cells to store the output from this query for the Amount field and the Output Type field.

    Update Universe and Dashboard

  • ABOUT THE pROjEcTTOpic 6: MOdEling WiTH R

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling with R | 92

    R is an open-source programming language and software environment for statistical computing and graphics. The R language has become very popular among statisticians and data miners for developing statistical software and is widely used for advanced data analysis. With over 3,000 add-on packages, it provides a wide range of library functions. SAP HANA database allows R code to be processed in-line as part of the overall query execution plan.

    An efficient data exchange mechanism supports the transfer of intermediate database tables directly into the vector oriented data structures of R. This offers a performance advantage compared to standard SQL interfaces, which are tuple-based and therefore require an additional data copy on the R side.

    SAP does not ship the R environment with the SAP HANA database, as R is open Source and under the GPL license. Also SAP does not provide support for R. In order to use the SAP HANA integration with R, as described in this document, you need to download R from the open source community (http://www.r-project.org/) and configure it accordingly. Additionally, you will need Rserve, a TCP/IP server which allows other programs to use facilities of R without the need to initialize R or link against R library. See further http://www.rforge.net/Rserve/index.html.

    The process R code in the context of the SAP HANA database, the R code is embedded in SQLScript in the form of a RLANG procedure. The SAP HANA database uses the external R environment to execute this R code, similarly to native database operations like joins or aggregations. All operations are represented as a node in the calculation data flow graph. R operators are represented a special customer operation node in this data flow graph. Similar to other nodes, customer operation node consumes a number of input objects and returns one result table. Following is the system architecture and the operation process:

    As we can see in this diagram, the invocation process is listed below:

    1. Calculation engine execute the R-operators;

    2. R-Client in calculation engine will issue a request through Rserve mechanism;

    3. R-Runtime creates a dedicated R process on the R host for this request.

    4. R-Client will efficiently transfer the R function codes and input tables to R process.

    5. R-Runtime complete the function execution;

    Application Architecture for SAP HANA and R

  • SAP HANA Developer Self-Learning Guide: Personal Spend Analysis on SAP HANA

    Topic 1: Introduction Topic 2: Prepare SAP HANA Development Environment

    Topic 3: Modeling in SAP HANA

    Topic 4: Building a Report Topic 5: Modeling using SQLScripts

    Topic 6: Modeling with R Topic 7: References

    Modeling with R | 93

    6. R-Runtime returns the result R data frame to SAP HANA. (SAP HANA database use very similar vector oriented R data frame. This conversion is very efficient. This is asynchronized communication. Before the data is return, calculation engine can continue the other scheduled tasks. )

    Continue Building Your Project

    We dont recommend installing the R environment on the same HANA box. However, to simplify the application architecture, this guide book will introduce installing R environment in the SAP HANA AWS instance through remote login. To do that, we assume you have necessary Linux knowledge and have necessary software installed in your local system, such as the PUTTY remote login tool.

    To access the system from Windows platform, you need to have the key pair (*.pem) file downloaded from Amazon EC2 and use Puttygen.exe to create a private key file for Putty. Now, login to HANA Linux VM as the root user using Putty and the Elastic IP address we discussed in the introduction chapter. From Linux or Mac oS-X, you simply need to run ssh -i hanakey.pem externalIP -l root from a terminal window. The hanakey.pem is the key pairs we downloaded from AWS. The externalIP is the Elastic IP address from AWS associated with our HANA server.

    Some corporate firewalls may not allow SSH to Amazon cloud. You may have to work with your IT organization to resolve this. The user hdbadm is the owner of sap software in the Linux instance. To restart HANA DB without restarting the entire Linux instance, switch to user hdbadm and execute the following stop and start operations using the following commands: