sap hana business function library (bfl) reference

175
SAP HANA Business Function Library (BFL) Reference SAP HANA Business Function Library (BFL) Reference SAP HANA Appliance Software SPS 05 Target Audience Consultants Administrators SAP Hardware Partner Others Public November 2012

Upload: amanpratap007

Post on 08-Nov-2014

246 views

Category:

Documents


9 download

DESCRIPTION

SAP HANA Business Function Library (BFL) Reference

TRANSCRIPT

Page 1: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 1

SAP HANA Business Function Library (BFL) Reference SAP HANA Appliance Software SPS 05

Target Audience ■ Consultants ■ Administrators ■ SAP Hardware Partner ■ Others

Public November 2012

Page 2: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 2

Copyright

© 2012 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, PowerPoint, Silverlight, and Visual Studio are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, z10, z/VM, z/OS, OS/390, zEnterprise, PowerVM, Power Architecture, Power Systems, POWER7, POWER6+, POWER6, POWER, PowerHA, pureScale, PowerPC, BladeCenter, System Storage, Storwize, XIV, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, AIX, Intelligent Miner, WebSphere, Tivoli, Informix, and Smarter Planet are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the United States and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are trademarks or registered trademarks of Adobe Systems Incorporated in the United States and other countries.

Oracle and Java are registered trademarks of Oracle and its affiliates.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems Inc.

HTML, XML, XHTML, and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

Apple, App Store, iBooks, iPad, iPhone, iPhoto, iPod, iTunes, Multi-Touch, Objective-C, Retina, Safari, Siri, and Xcode are trademarks or registered trademarks of Apple Inc.

IOS is a registered trademark of Cisco Systems Inc.

RIM, BlackBerry, BBM, BlackBerry Curve, BlackBerry Bold, BlackBerry Pearl, BlackBerry Torch, BlackBerry Storm, BlackBerry Storm2, BlackBerry PlayBook, and BlackBerry App World are trademarks or registered trademarks of Research in Motion Limited.

Google App Engine, Google Apps, Google Checkout, Google Data API, Google Maps, Google Mobile Ads, Google Mobile Updater, Google Mobile, Google Store, Google Sync, Google Updater, Google Voice, Google Mail, Gmail, YouTube, Dalvik and Android are trademarks or registered trademarks of Google Inc.

INTERMEC is a registered trademark of Intermec Technologies Corporation.

Wi-Fi is a registered trademark of Wi-Fi Alliance.

Bluetooth is a registered trademark of Bluetooth SIG Inc.

Motorola is a registered trademark of Motorola Trademark Holdings LLC.

Computop is a registered trademark of Computop Wirtschaftsinformatik GmbH.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company.

Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Sybase Inc. Sybase is an SAP company.

Crossgate, m@gic EDDY, B2B 360°, and B2B 360° Services are registered trademarks of Crossgate AG in Germany and other countries. Crossgate is an SAP company.

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

Page 3: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 3

Table of Contents Table of Contents ................................................................................................................................ 3

1 What is BFL? ........................................................................................................................... 5

2 Getting Started........................................................................................................................ 6

2.1 Prerequisites .................................................................................................................. 6 2.2 Application Function Libraries (AFL) .............................................................................. 6 2.3 Security .......................................................................................................................... 6 2.4 How to Call BFL Function .............................................................................................. 7

2.4.1 Generating BFL Procedures ............................................................................ 8

3 BFL Functions ...................................................................................................................... 11

3.1 Annual Depreciation ..................................................................................................... 14 3.1.1 Diminishing Balance Depreciation ................................................................. 14 3.1.2 Straight-line Depreciation .............................................................................. 16 3.1.3 Sum-of-year Depreciation .............................................................................. 18

3.2 Cycles ........................................................................................................................... 20 3.3 Cumulate ...................................................................................................................... 22 3.4 Days ............................................................................................................................. 23 3.5 Days Outstanding ......................................................................................................... 25 3.6 De-cumulate ................................................................................................................. 29 3.7 Delay ............................................................................................................................ 30 3.8 Delay Debt.................................................................................................................... 33 3.9 Delay Stock .................................................................................................................. 36 3.10 Discounted Cash Flow ................................................................................................. 39 3.11 Driver ............................................................................................................................ 41 3.12 Feed ............................................................................................................................. 44 3.13 Feed Overflow .............................................................................................................. 46 3.14 Forecast ....................................................................................................................... 49 3.15 Forecast Agents ........................................................................................................... 53 3.16 Forecast Driver ............................................................................................................. 55 3.17 Forecast Dual Driver .................................................................................................... 58 3.18 Forecast Mix ................................................................................................................. 62 3.19 Forecast Sensitivity ...................................................................................................... 65 3.20 Funds ........................................................................................................................... 69 3.21 Future ........................................................................................................................... 71 3.22 Grow ............................................................................................................................. 73 3.23 Inflated Cash Flow ....................................................................................................... 75 3.24 Internal Rate of Return (IRR) ....................................................................................... 77 3.25 Lag ............................................................................................................................... 80 3.26 Last ............................................................................................................................... 82

Page 4: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 4

3.27 Lease ............................................................................................................................ 83 3.28 Lease Variable ............................................................................................................. 87 3.29 Linear Average ............................................................................................................. 92 3.30 Max Value .................................................................................................................... 93 3.31 Minimum Value ............................................................................................................ 94 3.32 Moving Average & Moving Sum ................................................................................... 95 3.33 Moving Median ........................................................................................................... 100 3.34 Number of Periods ..................................................................................................... 103 3.35 Net Present Value ...................................................................................................... 106 3.36 Outlook ....................................................................................................................... 108 3.37 Payment ..................................................................................................................... 111 3.38 Present Value ............................................................................................................. 114 3.39 Proportion ................................................................................................................... 117 3.40 Rate ............................................................................................................................ 119 3.41 Repeat ........................................................................................................................ 122 3.42 Rounding .................................................................................................................... 124 3.43 Seasonal Simple & Seasonal Complex ..................................................................... 127

3.43.1 Seasonal Complex ...................................................................................... 129 3.43.2 Seasonal Simple .......................................................................................... 133

3.44 Seasonal Simulation .................................................................................................. 136 3.45 Stock Flow .................................................................................................................. 138 3.46 Stock Flow Reverse ................................................................................................... 146 3.47 Stock Flow Batch ....................................................................................................... 153 3.48 Time ........................................................................................................................... 160 3.49 Time Sum ................................................................................................................... 163 3.50 Transform ................................................................................................................... 167 3.51 Volume Driver ............................................................................................................ 168 3.52 Year-Over-Year Difference ........................................................................................ 170 3.53 Year to Date ............................................................................................................... 172 3.54 Year-to-Date Statistical .............................................................................................. 174

Page 5: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 5

1 What is BFL?

SAP HANA In-Memory Computing Engine offers various algorithms for in-memory computing. It provides several application libraries for developers, partners, and customers who develop applications that run on SAP HANA. The libraries are linked dynamically to the SAP HANA database kernel.

The Business Function Library (BFL) is one of these application libraries. It contains pre-built parameter-driven functions in the financial area. The functions are implemented by C++. This library helps you develop compound business algorithms that are fully compliant with the SAP HANA calculation engine. It offers you the flexibility and efficiency to develop HANA-based applications with incredible performance.

The BFL extends the computation ability of SAP HANA with complex and performance-critical algorithms which are requested by applications. By using the library, you can achieve:

■ Significant performance improvement for SAP applications

Utilizing new hardware (e.g. multi core, built-in vector engine)

Massive parallel main memory processing

Changing the boundaries between application server and data management layer

■ Simplification of application programming model

Usage of extended SQL (SQL script)

Rich functionalities in calculation engine

Quick application delivery

Page 6: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 6

2 Getting Started

2.1 Prerequisites

To use the BFL functions, you must:

■ Install SAP HANA SPS05.

■ Install the Application Function Library (AFL), which includes BFL. For more information, see the section Installing Application Function Libraries (AFLs) on a SAP HANA System in the SAP HANA Installation Guide with Unified Installer.

2.2 Application Function Libraries (AFL)

You can dramatically increase performance by executing complex computations in the database instead of at the application sever level. SAP HANA provides several techniques to move application logic into the database, and one of the most important is the use of application functions. Application functions are like database procedures written in C++ and called from outside to perform data intensive and complex operations.

Functions for a particular topic are grouped into an application function library (AFL), such as the Predictive Analysis Library (PAL) and the Business Function Library (BFL). Currently, all AFLs are delivered in one archive (that is, one SAR file with the name AFL<version_string>.SAR). The AFL archive is not part of the HANA appliance, and must be installed separately by the administrator.

Each release of AFL has a version in the form of <revision_number>.<patch_level>. For example, AFL 40.01 refers to revision 40 and patch level 01. The revision of the AFL must match the revision of SAP HANA. Thus, an AFL revision 40 (any patch level) should be installed with SAP HANA revision 40 only.

2.3 Security

This section provides detailed security information which can help administrator and architects answer some common questions.

1. User and Schema During startup, the system creates the user _SYS_AFL, with default schema _SYS_AFL. All AFL objects (such as areas, packages, functions, and procedures) are created under this user and schema. Therefore, all these objects have fully specified names in the form of _SYS_AFL.<object name>.

2. Role Assignment

For each AFL library, there is a role. You must be assigned this role to execute the functions in the library. The role for the BFL library is named:

AFL__SYS_AFL_AFLBFL_EXECUTE

Note There are 2 underscores between AFL and SYS.

Once a role is created, it cannot be dropped anymore. In other words, even when an area with all its objects is dropped and re-created during system startup, the user still keeps the role originally granted.

Page 7: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 7

2.4 How to Call BFL Function

Most of the functions can be called directly once the BFL library has been installed and scriptserver has started. The calling syntax is as follows:

CALL _SYS_AFL.AFLBFL_<function_name>_PROC( {inputTab1,…}, <output_tab>) with overview;

■ _SYS_AFL: The schema under which BFL functions are created.

■ AFLBFL: The name of the BFL library.

■ AFLBFL_<function_name>_PROC: The procedure name automatically generated by AFL.

■ {inputTab1,…}: User-defined name(s) of the current procedure’s input table(s). Detailed input table definition for each procedure can be found in Chapter 3.

■ <output_tab>: User-defined name(s) of the current procedure’s output table(s). Detailed output table definition for each procedure can be found in Chapter 3.

Page 8: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 8

2.4.1 Generating BFL Procedures The following functions require you to generate a procedure that wraps the function:

■ Driver

■ Forecast Driver

■ Forecast Dual Driver

■ Delay

■ Moving Average & Moving Sum

■ Time Sum

Step 1 – Create the AFL_WRAPPER_GENERATOR Procedure Before using any AFL function, you need to create the AFL_WRAPPER_GENERATOR procedure. It is used to generate a wrapper for the AFL functions that take tables with a variable number of columns as inputs. This procedure only needs to be created once by the user SYSTEM.

1. Go to /hanamnt/<SID>/HDB <instance_number>/exe/plugins/afl/.

2. Execute the afl_wrapper_generator.sql script file.

Page 9: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 9

Step 2 – Generate a BFL Procedure You generate a procedure for a specific BFL function by calling AFL_WRAPPER_GENERATOR:

CALL SYSTEM.AFL_WRAPPER_GENERATOR( '<procedure_name>', '<area_name>', '<function_name>', <signature_table>);

■ <procedure_name>: A name for the BFL procedure. This can be anything you want.

■ <area_name>: Always set to AFLBFL.

■ <function_name>: A BFL built-in function name.

■ <signature_table>: A user-defined table variable. The table contains records to describe the input table types and result table types.

A typical table variable references a table with the following definition:

Index Table Type Name Direction

1 BFL_INPUT1_T in

2 … in

3 BFL_INPUTN_T in

4 BFL_OUTPUT_T out

Notes 1. The records in the signature table must follow this order: first input table, then the output

table.

2. The signature table must be created before generating the BFL procedure. The table type names are user-defined. You can find detailed table type definitions for each BFL function in Chapter 3.

3. Generate the BFL procedures with the user SYSTEM.

4. It is suggested that you add <schema_name> before the table type name in <signature_table>.

Page 10: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 10

Step 3 – Call a BFL Procedure

After generating a procedure, you can call the procedure using the syntax below.

CALL <procedure_name> ( {inputTab1,…},<output_tab>) with overview;

■ <procedure_name>: The procedure name specified when generating the procedure in Step 2.

■ <inputTab1,…>: User-defined name(s) of the procedure’s input table(s). Detailed input table definitions for each procedure can be found in Chapter 3.

■ <output_Tab>: User-defined name of the procedure’s output table. Detailed output table definition for each procedure can be found in Chapter 3.

Notes 1. The above tables must be created before calling the procedure.

2. These BFL algorithms have more than one input table.

3. All AFL objects are owned by the _SYS_AFL user and reside in the _SYS_AFL schema. To call the BFL procedure generated in Step 2, you need the AFL_SYS_AFL_AFLBFL_EXECUTE role.

Page 11: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 11

3 BFL Functions

The following lists all available functions in the Business Function Library.

Function Description

Annual Depreciation Calculates annual depreciation according to three common methods: Diminishing balance depreciation, Straight line depreciation and Sum-of-year depreciation. It allows variable length of timescales for all assets/items.

Cumulate Calculates the cumulative totals in one row based on the original numbers in another row.

Cycles Calculates seasonal factors from Fourier coefficients. It combines sine and cosine waves to help you determine seasonality or other cyclical business factors.

Days Returns the number of days in each period defined by each pair of From and To dates.

Days Outstanding Calculates receipts or payments based on the level of days outstanding.

De-cumulate Calculates the original series starting from the cumulated totals.

Delay Calculates receivables or payables based on a delay between the time of invoice and the time of payment.

Delay Debt Calculates cash receipts using actual sales. The closing debtor balance for each period is calculated by referring to historic sales levels for a specified number of days.

Delay Stock Calculates purchases required to meet future demand.

Discounted Cash Flow

Converts a future stream of cash flow to constant prices. It calculates the inflated value of today's money.

Driver Calculates the forecast for future periods using historical data and as many drivers as needed. A driver drives cost, such as headcount, floor space, units sold, and unit price.

Feed Calculates the closing balance and "feeds" it to the opening balance of the next time period.

Feed Overflow Calculates the closing balance and feeds it to the opening balance of the next time period.

Forecast Combines actual and forecast data to produce a rolling forecast. Eliminates scripting of feeds.

Forecast Agents A specialized version of the Driver function focused on the entities required to meet service levels. Used primarily for labor in areas like call centers and mortgage processing based on interest rate.

Forecast Driver A specialized version of the Driver function that calculates the forecast for future periods using historical data and one single driver.

Page 12: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 12

Function Description

Forecast Dual Driver Calculates the forecast for future periods using historical data and two drivers. It also calculates the incremental effect of each driver on the historical base figure.

Forecast Mix Mixes actual data prior to the switchover date with forecast data on and after the switchover date.

Forecast Sensitivity Returns a calculation for the proportion of requests that will be queued because there were no agents available when the request was answered.

Funds Calculates the use of funds or the source of funds.

Future Calculates the closing balance of an account given the start balance and the conditions under which the account runs.

Grow Grows a base figure by a specified percentage each period. It can be compound or linear.

Inflated Cash Flow Calculates the amount of cash you must receive in a future period to compensate for inflation.

Internal Rate of Return

Calculates the internal rate of return for a series of cash flow on specified dates.

Lag Calculates a result in one row by lagging an input from another row by a specified number of periods.

Last Looks back over the series of data of the input row and returns the most recent non-zero value.

Lease Calculates a payment schedule for a lease, loan, mortgage, annuity or savings account.

Lease Variable Allows an account to be scheduled along a time scale representing the life of the loan.

Linear Average Calculates a linear average that applies a larger weight to more recent periods. The weights applied decrease linearly as time goes backward.

Max Value Returns the maximum value of a range.

Minimum Value Returns the minimum value of a specific range.

Moving Average & Moving Sum

Calculates a moving average or moving sum over specified periods. Key statistical component

Moving Median Takes the median value after sorting all input values into an ascending sequence.

Number of Periods Calculates the number of periods over which the account must run.

Net Present Value Calculates the sum of a series of future cash flow values after discounting each to a present value based on the annual rate input for the period in which it is being calculated.

Outlook The outlook is calculated by using actuals of past months and plan figures of future months.

Payment Calculates the regular payment to an account for each period.

Page 13: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 13

Function Description

Present Value Calculates opening value through the given target closing balance and various parameters.

Proportion Allows you to input a start and end date, and then calculates the proportion of the period length. Important for project planning with performance to plan calculations

Rate Calculates the percentage interest rate per period for an account, given its start balance, end balance, payment amount per period and the number of periods.

Repeat It is used to repeat data from a single period or group of periods through the time scale of the Dimension List.

Rounding Calculates the rounded values for a specified input item according to a chosen rounding method.

Seasonal Complex Performs seasonal adjustments of time to determine seasonal patterns in data.

Seasonal Simple Performs seasonal adjustments of time to determine seasonal patterns in data.

Seasonal Simulation Provides the building blocks to seasonal simulation seasonal data using a variety of characteristics.

Stock Flow Works out the level of supply needed to meet target forecasts for stock cover.

Stock Flow Reverse Allows you to input stock cover and work out what purchases were needed to meet the target stock levels.

Stock Flow Batch Let’s you use batch quantities in stock flow calculations. Key for constraint based models or non-discrete manufacturing units of measure.

Time Returns the information requested by the option you have input. Eliminates scripting of alternative time dimensions

Time Sum Allows you to accumulate an expense over a specified number of periods in advance or arrears.

Transform Helps users to build equations using angles and trigonometry functions when Cycles does not provide the functionality that they need.

Volume Driver Calculates the year-over-year percentage difference for each volume driver.

Year over Year Difference

Calculates the year over year difference between the current and previous time periods.

Year to Date Calculates year to date totals based on original data.

Year to Date Statistical

Calculates the original numbers in one row based on the year-to-date figures in another row.

Page 14: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 14

3.1 Annual Depreciation

This function calculates annual depreciation according to three common methods: Diminishing balance depreciation, Straight line depreciation and Sum-of-year depreciation. It allows variable length of timescales for all assets/items. This is critical for seasonality and creating adjusting periods.

3.1.1 Diminishing Balance Depreciation This function calculates depreciation based on diminishing balances. It provides a higher depreciation charge in the first year of an asset’s life and gradually decreases charges in subsequent years. Depreciation for the first period is calculated by taking a percentage of the opening asset capitalization. Depreciation for the next period is calculated based on taking a percentage of that diminished balance. Depreciation starts high, progressively decreases. The asset will never be fully depreciated.

Formula

Depreciation = (Capitalization - Accumulated depreciation to date) * (rate / 100)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Capitalization Input Table 1 Double VALUE Asset capitalization (the cost of purchase)

Rate Input Table 1 Double VALUE The life of the capitalized asset in years

Flag Input Table 1 Double VALUE Period(0) or year(1)

Capitalization Type

Input Table 1 Double VALUE Period(0) or year(1)

Periods Input Table 1 Double VALUE The periods used to calculate

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Depreciation Output Table

2 Double VALUEINDEX The index of the depreciation result

Double DEP_VALUE Diminishing balance depreciation result

Page 15: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 15

Example

DROP TABLE CAPITALIZATION_TAB;

CREATE TABLE CAPITALIZATION_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO CAPITALIZATION_TAB VALUES (100000) ;

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "VALUE" DOUBLE) ;

INSERT INTO RATE_TAB VALUES (0.1) ;

DROP TABLE FLAG_TAB ;

CREATE TABLE FLAG_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO FLAG_TAB VALUES (0) ;

DROP TABLE CAPITALIZATIONTYPE_TAB ;

CREATE TABLE CAPITALIZATIONTYPE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO CAPITALIZATIONTYPE_TAB VALUES (0) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ("VALUE" DOUBLE) ;

INSERT INTO PERIODS_TAB VALUES (10) ;

DROP TABLE DEPRECIATION_TAB ;

CREATE TABLE DEPRECIATION_TAB ("VALUEINDEX" DOUBLE, "DEP_VALUE" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_DBDEPRECIATION_PROC (CAPITALIZATION_TAB, RATE_TAB,FLAG_TAB, CAPITALIZATIONTYPE_TAB, PERIODS_TAB, DEPRECIATION_TAB) WITH OVERVIEW;

SELECT * FROM DEPRECIATION_TAB ;

Page 16: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 16

3.1.2 Straight-line Depreciation This function is the simplest and most-often-used method, which a company uses to estimate the residual value of an asset at the end of the period during which it will be used to generate revenues (useful life).

It calculates depreciation by dividing the asset capitalization by the life of it based on two inputs.

1. Asset capitalization

2. The life in periods or years.

Formula

Depreciation = Capitalization / Life of the asset

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Capitalization Input Table 1 Double VALUE Asset capitalization (the cost of purchase)

Life Input Table 1 Double VALUE Life of the asset. Possible to import from NWBI or other ledger

Flag Input Table 1 Double VALUE Period(0) or year(1)

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Depreciation Output Table

2 Double VALUEINDEX The index of the depreciation result

Double DEP_VALUE Straight line depreciation result

Page 17: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 17

Example

DROP TABLE CAPITALIZATION_TAB ;

CREATE TABLE CAPITALIZATION_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO CAPITALIZATION_TAB VALUES (2400);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

INSERT INTO CAPITALIZATION_TAB VALUES (0);

DROP TABLE LIFE_TAB ;

CREATE TABLE LIFE_TAB( "VALUE" DOUBLE );

INSERT INTO LIFE_TAB VALUES (10);

DROP TABLE FLAG_TAB ;

CREATE TABLE FLAG_TAB ( "VALUE" DOUBLE );

INSERT INTO FLAG_TAB VALUES (1) ;

DROP TABLE DEPRECIATION_TAB ;

CREATE TABLE DEPRECIATION_TAB ( "VALUEINDEX" DOUBLE, "DEP_VALUE" DOUBLE) ;result tables

CALL _SYS_AFL.AFLBFL_SLDEPRECIATION_PROC (CAPITALIZATION_TAB, LIFE_TAB, FLAG_TAB,DEPRECIATION_TAB) with overview;

SELECT * FROM DEPRECIATION_TAB ;

Page 18: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 18

3.1.3 Sum-of-year Depreciation This is a depreciation method that results in a more accelerated write-off than straight line depreciation, but less than diminishing-balance method. It calculates the depreciation by dividing the asset capitalization by a weighting that decreases over time.

Formula

(Depreciation, period p) = c * (n - p + 1)/ (n*(n+1)/2) Where:

c = capitalization, n = life of the asset, p = period for which depreciation is being calculated

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Capitalization Input Table 1 Double VALUE Asset capitalization (the cost of purchase)

Life Input Table 1 Double VALUE Life of the asset. Can be imported from NWBI for actual assets

Flag Input Table 1 Double VALUE Period(0) or year(1)

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Depreciation Output Table

2 Double VALUEINDEX The index of the depreciation result

Double DEP_VALUE Sum-of-year depreciation result

Page 19: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 19

Example

DROP TABLE CAPITALIZATION_TAB ;

CREATE TABLE CAPITALIZATION_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO CAPITALIZATION_TAB VALUES (15000);

DROP TABLE LIFE_TAB ;

CREATE TABLE LIFE_TAB( "VALUE" DOUBLE );

INSERT INTO LIFE_TAB VALUES (5);

DROP TABLE FLAG_TAB ;

CREATE TABLE FLAG_TAB ( "VALUE" DOUBLE );

INSERT INTO FLAG_TAB VALUES (0) ;

DROP TABLE DEPRECIATION_TAB ;

CREATE TABLE DEPRECIATION_TAB ( "VALUEINDEX" DOUBLE, "DEP_VALUE" DOUBLE) ;result tables

CALL _SYS_AFL.AFLBFL_SOYDEPRECIATION_PROC (CAPITALIZATION_TAB, LIFE_TAB, FLAG_TAB,DEPRECIATION_TAB) with overview;

SELECT * FROM DEPRECIATION_TAB ;

Page 20: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 20

3.2 Cycles

This function calculates seasonal factors by using Fourier coefficients. It combines sine and cosine waves to help you determine seasonality or other cyclical business factors.

Formula

■ When {sine/cosine} = sine, the equation is:

{Cycle} = {amplitude} * Sin(360 * ({time} - {start date}) / {length}) ■ When {sine/cosine}= cosine, the equation is:

{Cycle}= {amplitude} * Cos(360 * ( {time} - {start date}) / {length}) Where: {time} is the center of the period.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Amplitude Input Table 1 Double AMPLITUDE Amplitude of sine/cosine.

Length Input Table 1 Double LENGTH Length (in years) over which the cycle repeats itself.

Startdate Input Table 1 Double START Time in years at which the cycle starts.

Function Input Table 1 Double FUNCTION 0 for a sine wave, and 1 for a cosine wave.

Time Input Table 1 Double TIME Time periods.

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double CYCLE Result table that contains the expected result.

Example

---Table Preparation

DROP TABLE AMPLITUDE_TAB;

CREATE COLUMN TABLE AMPLITUDE_TAB( "AMPLITUDE" DOUBLE ) ;

INSERT INTO AMPLITUDE_TAB VALUES (200) ;

INSERT INTO AMPLITUDE_TAB VALUES (300) ;

INSERT INTO AMPLITUDE_TAB VALUES (2000) ;

Page 21: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 21

DROP TABLE LENGTH_TAB;

CREATE COLUMN TABLE LENGTH_TAB( "LENGTH" DOUBLE ) ;

INSERT INTO LENGTH_TAB VALUES (20) ;

INSERT INTO LENGTH_TAB VALUES (6.5) ;

INSERT INTO LENGTH_TAB VALUES (0) ;

DROP TABLE START_TAB;

CREATE COLUMN TABLE START_TAB( "START" DOUBLE ) ;

INSERT INTO START_TAB VALUES (2000) ;

INSERT INTO START_TAB VALUES (2003) ;

INSERT INTO START_TAB VALUES (0) ;

DROP TABLE FUNCTION_TAB;

CREATE COLUMN TABLE FUNCTION_TAB( "FUNCTION" INTEGER ) ;

INSERT INTO FUNCTION_TAB VALUES (0) ;

INSERT INTO FUNCTION_TAB VALUES (0) ;

INSERT INTO FUNCTION_TAB VALUES (0) ;

DROP TABLE TIME_TAB;

CREATE COLUMN TABLE TIME_TAB( "TIME" DOUBLE ) ;

INSERT INTO TIME_TAB VALUES (2003) ;

INSERT INTO TIME_TAB VALUES (2004) ;

INSERT INTO TIME_TAB VALUES (2005) ;

INSERT INTO TIME_TAB VALUES (2006) ;

INSERT INTO TIME_TAB VALUES (2007) ;

INSERT INTO TIME_TAB VALUES (2008) ;

INSERT INTO TIME_TAB VALUES (2009) ;

INSERT INTO TIME_TAB VALUES (2010) ;

DROP TABLE RESULTS_TAB ;

CREATE COLUMN TABLE RESULTS_TAB ( "CYCLE" DOUBLE);

truncate table RESULTS_TAB;

CALL _SYS_AFL.AFLBFL_CYCLES_PROC (AMPLITUDE_TAB, LENGTH_TAB, START_TAB, FUNCTION_TAB, TIME_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 22: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 22

3.3 Cumulate

This function calculates the cumulative totals in one row based on the original numbers in another row.

Formula

∑==

n

iiOriginalnCumulative

1)()(

Where: n is the current period number.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name Description

Original Input Table 1 Double VALUE Item you want to accumulate

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Cumulated Output Table 1 Double CUMULATED_DECUMULATE

Cumulative Total

Input Flag

Name Direction Value Type Description

Flag Input Value 1 Int Specifies this as Cumulate function, corresponding to De-cumulate Function

Example

DROP TABLE ORIGINAL_TAB;

CREATE TABLE ORIGINAL_TAB( "VALUE" DOUBLE );

INSERT INTO ORIGINAL_TAB VALUES (50);

INSERT INTO ORIGINAL_TAB VALUES (90);

INSERT INTO ORIGINAL_TAB VALUES (90);

DROP TABLE CUMULATED_TAB;

CREATE TABLE CUMULATED_TAB( "CUMULATED_DECUMULATE" DOUBLE);

CALL _SYS_AFL.AFLBFL_CUMULATE_DECUMULATE_PROC (ORIGINAL_TAB, CUMULATED_TAB,1) WITH OVERVIEW;

SELECT *FROM CUMULATED_TAB;

Page 23: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 23

3.4 Days

This function returns the number of days in each period defined by each pair of “From” and “To” dates.

Formula

Days = Number of days in period

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

FromDate Input Table 1 String FROMDATE Beginning of date to be calculated

ToDate Input Table 1 String TODATE End of date to be calculated

Config Input Table 1 Double CONFIG Normal(0)

Generic Month: return 365/12

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

TotalDays Output Table 1 Double TOTALDAYS Displays the days in the current period

Page 24: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 24

Example

DROP TABLE FROMDATE_TAB;

CREATE COLUMN TABLE FROMDATE_TAB( "FROMDATE" VARCHAR(255));

INSERT INTO FROMDATE_TAB VALUES('20000106');

INSERT INTO FROMDATE_TAB VALUES('20000206');

INSERT INTO FROMDATE_TAB VALUES('19990223');

DROP TABLE TODATE_TAB;

CREATE COLUMN TABLE TODATE_TAB ( "TODATE" VARCHAR(255));

INSERT INTO TODATE_TAB VALUES('20090909');

INSERT INTO TODATE_TAB VALUES('20100106');

INSERT INTO TODATE_TAB VALUES('20000806');

DROP TABLE CONFIG_TAB ;

CREATE COLUMN TABLE CONFIG_TAB ( "CONFIG" DOUBLE ) ;

INSERT INTO CONFIG_TAB VALUES (0) ;

INSERT INTO CONFIG_TAB VALUES (0) ;

INSERT INTO CONFIG_TAB VALUES (0) ;

DROP TABLE TOTALDAYS_TAB ;

CREATE COLUMN TABLE TOTALDAYS_TAB ( "TOTALDAYS" DOUBLE) ;result table

CALL _SYS_AFL.AFLBFL_DAYS_PROC (FROMDATE_TAB, TODATE_TAB, CONFIG_TAB, TOTALDAYS_TAB) WITH OVERVIEW;

SELECT * FROM TOTALDAYS_TAB;

Page 25: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 25

3.5 Days Outstanding

This function calculates receipts or payments based on the level of days outstanding. It is similar to the Delay Debt business function, and other business functions which can create an atypical period specific to each business event (i.e. the average days outstanding of an invoice). However, it can also significantly simplify the procedure of user business rule setup by allowing the period length to be abstracted. Normally, it would be driven by a separate table/cube which has the actual DSO derived from the ERP system or NWBI – so the Days Outstanding is accurate for each customer and provides a highly accurate forecast of pending receipts for treasury (and for collections). In addition, it would guide the organization to easily understand the impact of collection activities relative to cash flow.

Formula

The closing balance is calculated as a function of the level of days outstanding.

Closing = (Days Outstanding / Days in Period) * Invoices this period Or

(Closing, period n) = ([Level, period n] / [Days in period n]) * (Invoices, period n) However, if the level of days outstanding is greater than the days in the current period

i.e. If

(Level, period n) > Days in period n Then

(Closing, period n) = (Invoices, period n) + ([Invoices, period n - 1] *[Level - Days in period n] / Days period n - 1) Payments are calculated as follows:

Cash payments = Opening - Closing + Invoices Opening balances = The closing balance from the previous period

Page 26: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 26

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Indicator Input Table 1 Double VALUE Used to indicate what level value specifies:

0: Period; 1: Days; 2: Start/End

Prime Input Table 1 Double VALUE Debtor or creditor balance at start of first period

Invoice Input Table 1 Double VALUE Invoice in amount

Duration Input Table 1 Double VALUE Period length

Level Input Table 1 Double VALUE Number of days outstanding or periods outstanding

Days Input Table 1 Double VALUE Number of days for each period

Input flag

Name Type Value Description

Indicator Int 1 Specify this is function of days outstanding corresponding to delay debt

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 3 Double OPENNING Debtor or creditor balance at start of subsequent periods, fed from the closing balance of the previous period

Double CLOSING Closing balance, calculated from days outstanding

Double RECEIPTS Payments

Page 27: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 27

Example

DROP TABLE INDICATOR_TAB ;

CREATE TABLE INDICATOR_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO INDICATOR_TAB VALUES (1) ;

DROP TABLE PRIME_TAB ;

CREATE TABLE PRIME_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PRIME_TAB VALUES (3000) ;

DROP TABLE INVOICE_TAB ;

CREATE TABLE INVOICE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

DROP TABLE DURATION_TAB ;

CREATE TABLE DURATION_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO DURATION_TAB VALUES (2.5) ;

DROP TABLE LEVEL_TAB ;

CREATE TABLE LEVEL_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

DROP TABLE DAYS_TAB ;

CREATE TABLE DAYS_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (30) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ( "OPENNING" DOUBLE, "CLOSING" DOUBLE,"RECEIPTS" DOUBLE) ;

Page 28: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 28

CALL _SYS_AFL.AFLBFL_DAYSOUTSTANDING_PROC(INDICATOR_TAB, PRIME_TAB, INVOICE_TAB, DURATION_TAB, LEVEL_TAB, DAYS_TAB, 1, RESULTS_TAB) WITH OVERVIEW ;

SELECT * FROM RESULTS_TAB ;

Page 29: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 29

3.6 De-cumulate

This function calculates the original series from the cumulated totals.

Formula

(Original, Period n) = (Cumulative, Period n) - (Cumulative, Period n-1)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Cumulative Input Table 1 Double VALUE Item you want to break down (Cumulative Sales)

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Original Output Table 1 Double CUMULATED_DECUMULATE

Original item (Sales)

Input Flag

Name Direction Value Type Description

Flag Input Value 0 Int Specifies this as De-cumulate function, corresponding to Cumulate Function

Example

DROP TABLE CUMULATIVE_TAB;

CREATE TABLE CUMULATIVE_TAB( "VALUE" DOUBLE );

INSERT INTO CUMULATIVE_TAB VALUES (50);

INSERT INTO CUMULATIVE_TAB VALUES (90);

INSERT INTO CUMULATIVE_TAB VALUES (90);

DROP TABLE ORIGINAL_TAB;

CREATE TABLE ORIGINAL_TAB( "CUMULATED_DECUMULATE" DOUBLE);

CALL _SYS_AFL.AFLBFL_CUMULATE_DECUMULATE_PROC (CUMULATIVE_TAB, ORIGINAL_TAB,0) WITH OVERVIEW;

SELECT *FROM ORIGINAL_TAB;

Page 30: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 30

3.7 Delay

This function needs to use the generator mentioned in chapter 2.4.

This function calculates receivables or payables based on a delay between the time of invoice and the time of payment. For invoices in a given month, a certain percentage is paid by the end of the month, a certain percentage is paid in the next month, and so on. This is represented by the inputs % Period1, % Period2, % Period3, and until up to the greatest delay expected.

It calculates elements such as the cash received (paid) in a given period based on the sales (purchases) history.

Formula

Cash Paid, this month = + (Input current month) * (%period1 current month)/100 + (Input last month) * (%period2 from last month)/100 + (Input 2 months ago) * (%period3 from 2 months ago)/100 + (Input 3 months ago) * (%period4 from 3 months ago)/100 + ........ (Opening n months ago) * (%period n+1 from n months ago/100) The opening balance from the prior year is assigned to the future month using the percentages entered in the first time period.

Closing = Opening + Inputs - Cash Paid Opening, period 1 = Prime, period1 Opening, this month = Closing, last month Note: The parameters do not necessarily have to be Dimension List items; they can also be constants.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double VALUE Opening balance, beginning period

Invoice Input Table 1 Double INVOICE Invoices

Paid Input Table 1 or n Double/Int PAID1~PAIDn Percentage of current period’s invoices paid in current period.

Page 31: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 31

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 3 Double/Int OPENING Opening balance as closing of previous period

Double/Int PAID Cash receipts or payments

Double/Int CLOSING Closing balance

Example

DROP TYPE PRIME_T;

CREATE TYPE PRIME_T AS TABLE("VALUE" DOUBLE);

DROP TYPE INVOICE_T;

CREATE TYPE INVOICE_T AS TABLE("INVOICE" DOUBLE);

DROP TYPE PAID_T;

CREATE TYPE PAID_T AS TABLE("PAID1" DOUBLE, "PAID2" DOUBLE, "PAID3" DOUBLE, "PAID4" DOUBLE);

DROP TYPE DELAY_T;

CREATE TYPE DELAY_T AS TABLE("OPENING" DOUBLE,"PAID" DOUBLE, "CLOSING" DOUBLE);

DROP table PDATA;

CREATE column table PDATA("ID" INT,"TYPENAME" VARCHAR(100),"DIRECTION" VARCHAR(100));

insert into PDATA values (1,'PRIME_T','in');

insert into PDATA values (2,'INVOICE_T','in');

insert into PDATA values (3,'PAID_T','in');

insert into PDATA values (4,'DELAY_T','out');

DROP PROCEDURE _SYS_AFL.AFLBFL_DELAY_PROC;

DROP TYPE "_SYS_AFL"."AFLBFL_DELAY_PROC__TT_P1";

DROP TYPE "_SYS_AFL"."AFLBFL_DELAY_PROC__TT_P2";

DROP TYPE "_SYS_AFL"."AFLBFL_DELAY_PROC__TT_P3";

DROP TYPE "_SYS_AFL"."AFLBFL_DELAY_PROC__TT_P4";

call afl_wrapper_generator('AFLBFL_DELAY_PROC','AFLBFL','DELAY',PDATA);

DROP TABLE PRIME_TAB ;

CREATE TABLE PRIME_TAB ( "VALUE" DOUBLE );

INSERT INTO PRIME_TAB VALUES (1000) ;

DROP TABLE INVOICE_TAB ;

CREATE TABLE INVOICE_TAB ( "INVOICE" DOUBLE) ;

INSERT INTO INVOICE_TAB VALUES (500) ;

INSERT INTO INVOICE_TAB VALUES (500) ;

Page 32: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 32

INSERT INTO INVOICE_TAB VALUES (500) ;

INSERT INTO INVOICE_TAB VALUES (500) ;

INSERT INTO INVOICE_TAB VALUES (500) ;

INSERT INTO INVOICE_TAB VALUES (500) ;

DROP TABLE PAID_TAB ;

CREATE TABLE PAID_TAB ( "PAID1" DOUBLE, "PAID2" DOUBLE, "PAID3" DOUBLE, "PAID4" DOUBLE) ;

INSERT INTO PAID_TAB VALUES (40, 25, 20, 15) ;

INSERT INTO PAID_TAB VALUES (40, 25, 20, 15) ;

INSERT INTO PAID_TAB VALUES (40, 25, 20, 15) ;

INSERT INTO PAID_TAB VALUES (40, 25, 20, 15) ;

INSERT INTO PAID_TAB VALUES (40, 25, 20, 15) ;

INSERT INTO PAID_TAB VALUES (40, 25, 20, 15) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ( "OPENING" DOUBLE, "PAID" DOUBLE, "CLOSING" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_DELAY_PROC(PRIME_TAB, INVOICE_TAB, PAID_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 33: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 33

3.8 Delay Debt

This function calculates cash receipts using actual sales data. The closing debtor balance for each period is calculated by referring to historical sales levels for a specified number of days. The days are taken first from the current period, then the previous periods.

When using the Days function to calculate days, the start and the end dates must be defined for each period in the timescale field or extracted from NetWeaver.

Formula

The closing balance is calculated as a function of the level of debtor days.

Closing = (Debtor Days/ Days in Period) * Sales of this period Or

(Closing, period n) = ((Level, period n)/ (Days in period n)) * (Sales, period n)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Indicator Input Table 1 Double VALUE Used to indicate what level value specifies:

0: Period; 1: Days

Prime Input Table 1 Double VALUE Opening debtor balance

Invoice Input Table 1 Double VALUE Actual sales

Duration Input Table 1 Double VALUE Period length

Level Input Table 1 Double VALUE Number of debtor days/periods

Days Input Table 1 Double VALUE Calculated in days instead of periods

Input flag

Name Type Value Description

Indicator Int 0 Specifies this is a function of delay debt corresponding to days outstanding

Page 34: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 34

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 3 Double OPENNING

Debtor balance from closing balance of the previous period

Double CLOSING Closing debtor balance

Double RECEIPTS Cash receipts required to meet debtor targets

Example

DROP TABLE INDICATOR_TAB ;

CREATE TABLE INDICATOR_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO INDICATOR_TAB VALUES (1) ;

DROP TABLE PRIME_TAB ;

CREATE TABLE PRIME_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PRIME_TAB VALUES (3000) ;

DROP TABLE INVOICE_TAB ;

CREATE TABLE INVOICE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

INSERT INTO INVOICE_TAB VALUES (3000) ;

DROP TABLE DURATION_TAB ;

CREATE TABLE DURATION_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO DURATION_TAB VALUES (2.5) ;

DROP TABLE LEVEL_TAB ;

CREATE TABLE LEVEL_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

INSERT INTO LEVEL_TAB VALUES (41) ;

DROP TABLE DAYS_TAB ;

CREATE TABLE DAYS_TAB ( "VALUE" DOUBLE ) ;

Page 35: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 35

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (30) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ( "OPENNING" DOUBLE, "CLOSING" DOUBLE,"RECEIPTS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_DELAYDEBT_PROC(INDICATOR_TAB, PRIME_TAB, INVOICE_TAB, DURATION_TAB, LEVEL_TAB, DAYS_TAB, 0,RESULTS_TAB) WITH OVERVIEW ;

SELECT * FROM RESULTS_TAB ;

Page 36: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 36

3.9 Delay Stock

This function calculates purchases required to meet future demand. The closing stock for each period is calculated by forecasting sales demand in a specified number of days or periods. Purchases are calculated to meet the required closing stock levels.

Formula

Closing Inventory = (Inventoryturn Days/ Days Next Period) * Sales Next Period or

(Closing, Period n) = ((Level, Period n)/ (Days in Period n+1) ) * (Sales, Period n+1) If

(Level, Period n) > Days in Period n+1 Then

(Closing, Period n) = (Sales, Period n+1) + ((Level, Period n) - Days in Period n+1) / (Days in Period n+2) * (Sales, Period n+2) Purchases are calculated to meet the closing inventory levels required:

Purchases = Closing - Opening + Sales Opening inventory balances are calculated as the closing inventory balance from the previous period except for the first period, only when the opening balance equals prime.

Opening, Period n = Closing, Period n-1 Opening, Period 1= Prime, Period 1

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double PRIME Stock balance at the start of the first period.

Demand Input Table 1 Double DEMAND Expected sales demand.

Level Input Table 1 Double LEVEL Number of stock days or periods.

Days Input Table 1 Double DAYS Time series. Number of days in each stage (e.g. month).

Indicator Input Table 1 Double INDICATOR Periods or days.

Page 37: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 37

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 3 Double OPENING Stock balance at the start of subsequent periods

Double CLOSING Closing stock balance

Double PURCHASES Purchases required to meet stock targets

Example

---Table Preparation

DROP TABLE PRIME_TAB;

CREATE COLUMN TABLE PRIME_TAB ( "PRIME" DOUBLE ) ;

INSERT INTO PRIME_TAB VALUES (5000) ;

DROP TABLE DEMAND_TAB;

CREATE COLUMN TABLE DEMAND_TAB ( "DEMAND" DOUBLE ) ;

INSERT INTO DEMAND_TAB VALUES (2000) ;

INSERT INTO DEMAND_TAB VALUES (3000) ;

INSERT INTO DEMAND_TAB VALUES (3000) ;

INSERT INTO DEMAND_TAB VALUES (3000) ;

INSERT INTO DEMAND_TAB VALUES (3000) ;

INSERT INTO DEMAND_TAB VALUES (3000) ;

DROP TABLE LEVELS_TAB;

CREATE COLUMN TABLE LEVELS_TAB ( "LEVEL" DOUBLE ) ;

INSERT INTO LEVELS_TAB VALUES (61) ;

INSERT INTO LEVELS_TAB VALUES (61) ;

INSERT INTO LEVELS_TAB VALUES (62) ;

INSERT INTO LEVELS_TAB VALUES (61) ;

INSERT INTO LEVELS_TAB VALUES (61) ;

INSERT INTO LEVELS_TAB VALUES (61) ;

DROP TABLE DAYS_TAB;

CREATE COLUMN TABLE DAYS_TAB ( "DAYS" DOUBLE ) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (31) ;

INSERT INTO DAYS_TAB VALUES (30) ;

Page 38: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 38

DROP TABLE INDICATOR_TAB;

CREATE COLUMN TABLE INDICATOR_TAB ( "INDICATOR" DOUBLE ) ;

INSERT INTO INDICATOR_TAB VALUES (1) ;

DROP TABLE RESULT_TAB;

CREATE INSERT ONLY COLUMN TABLE RESULT_TAB ( "OPENING" DOUBLE, "CLOSING" DOUBLE,"PURCHASES" DOUBLE) ;

TRUNCATE TABLE RESULT_TAB;

CALL _SYS_AFL.AFLBFL_DELAYSTOCK_PROC(PRIME_TAB, DEMAND_TAB, LEVELS_TAB, DAYS_TAB, INDICATOR_TAB, RESULT_TAB) WITH OVERVIEW;

SELECT * FROM RESULT_TAB;

Page 39: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 39

3.10 Discounted Cash Flow

This function converts a future stream of cash flow to constant prices. It calculates the inflated value of today's money.

Formula

Constant nrCurrent

)1( +=

Where:

r = discount rate expressed as a decimal fraction

n = number of periods into the future

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double PRIME Prime/base value

Time Input Table 1 String TIME The periods to be calculated

Rate Input Table 1 Double RATE Discount rate

APR Input Table 1 Double APR =annual % by default

= annual rate (rate=%/100)

= Periodic %

= Periodic rate

Switchover Input Table 1 Double SWITCHOVER

The switchover date defines the last historic period:

= Historic: Treat all periods as historic

=Input Date: Formatted date

=TimeScale: Use rate defined in timescale

=Month: Use month

SwitchoverDate

Input Table 1 String SWITCHOVERDATE

Specify the switchover date

Page 40: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 40

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double RESULT Constant value

Example

DROP TABLE PRIME_TAB;

CREATE COLUMN TABLE PRIME_TAB( "PRIME" DOUBLE ) ;

INSERT INTO PRIME_TAB VALUES (1000) ;

DROP TABLE TIME_TAB;

CREATE COLUMN TABLE TIME_TAB( "TIME" VARCHAR(255)) ;

INSERT INTO TIME_TAB VALUES ('20100101') ;

INSERT INTO TIME_TAB VALUES ('20110101') ;

INSERT INTO TIME_TAB VALUES ('20120101') ;

INSERT INTO TIME_TAB VALUES ('20130101') ;

INSERT INTO TIME_TAB VALUES ('20140101') ;

INSERT INTO TIME_TAB VALUES ('20150101') ;

DROP TABLE RATE_TAB;

CREATE COLUMN TABLE RATE_TAB( "RATE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.1) ;

DROP TABLE APR_TAB;

CREATE COLUMN TABLE APR_TAB( "APR" DOUBLE) ;

INSERT INTO APR_TAB VALUES (1) ;

DROP TABLE SWITCHOVER_TAB;

CREATE COLUMN TABLE SWITCHOVER_TAB( "SWITCHOVER" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES (1) ;

DROP TABLE SWITCHOVERDATE_TAB ;

CREATE COLUMN TABLE SWITCHOVERDATE_TAB( "SWITCHOVERDATE" VARCHAR(255));

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20091231') ;

DROP TABLE RESULTS_TAB ;

CREATE COLUMN TABLE RESULTS_TAB ( "RESULT" DOUBLE);

truncate table RESULTS_TAB;

CALL _SYS_AFL.AFLBFL_DISCOUNTEDCASHFLOW_PROC(PRIME_TAB, TIME_TAB, RATE_TAB, APR_TAB, SWITCHOVER_TAB, SWITCHOVERDATE_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 41: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 41

3.11 Driver

This function needs to use the generator mentioned in chapter 2.4.

This function is the key embedded calculation for system planning. It deploys a table-driven approach to calculate the forecast for future periods using historical data and as many drivers as needed. A driver drives cost, such as headcount, floor space, units sold, and unit price.

Although drivers can also be manually scripted for each item, the driver function is much more maintainable. It facilitates real-time modeling and seasonal simulation.

Formula

The forecast is worked out as follows:

Forecast, Period n = (History, Period p) * Ratio 1 * Ratio 2 * … * Ratio n Where:

Ratio 1 = (Driver 1, Period n) / (Driver 1, Period p) Ratio 2 = (Driver 2, Period n) / (Driver 2, Period p) Ratio 3 = (Driver 3, Period n) / (Driver 3, Period p) “Period n” denotes the current period. “Period p” denotes the base period immediately prior to the switchover date. “Period p” is the last period that contains historical data. From that period on, the data is forecast.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

History Input Table 1 Double HISTORY Base cost

Time Input Table 1 String TIME Time series to do forecast based on drivers

Switchover Input Table 1 Double SWITCHOVER

Switchover type:

■ 0 = Default Date

■ 1 = Specific Date

■ 2 = Dimension List

■ 3 = Today

■ 4 = Month

Note: The 1 and 2 options are the same in SAP HANA 1.0 SP3

Page 42: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 42

Name Direction Number of Columns

Column Type

Column Name

Description

Switchover Date

Input Table 1 String SWITCHOVE RDATE

Defines the first future period. This parameter is dependent on the SWITCHOVER type you specify.

Drivers Input Table 1~n Double/Int DRIVER1~DRIVERN

A driver drives cost (e.g. headcount, floor space, unit price, etc.). There is no limit to the number of drivers.

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double FORECAST Forecasted cost

Example

DROP TYPE HISTORY_T;

CREATE TYPE HISTORY_T AS TABLE("HISTORY" DOUBLE);

DROP TYPE TIME_T;

CREATE TYPE TIME_T AS TABLE("TIME" VARCHAR(100));

DROP TYPE SWITCHOVER_T;

CREATE TYPE SWITCHOVER_T AS TABLE("SWITCHOVER" DOUBLE);

DROP TYPE SWITCHOVERDATE_T;

CREATE TYPE SWITCHOVERDATE_T AS TABLE("SWITCHOVERDATE" VARCHAR(255));

DROP TYPE DRIVER_T;

CREATE TYPE DRIVER_T AS TABLE("DRIVER1" DOUBLE, "DRIVER2" DOUBLE, "DRIVER3" DOUBLE);

DROP TYPE RESULT_T;

CREATE TYPE RESULT_T AS TABLE("FORECAST" DOUBLE);

DROP table PDATA;

CREATE column table PDATA("ID" INT,"TYPENAME" VARCHAR(100),"DIRECTION" VARCHAR(100));

insert into PDATA values (1,'HISTORY_T','in');

insert into PDATA values (2,'TIME_T','in');

insert into PDATA values (3,'SWITCHOVER_T','in');

insert into PDATA values (4,'SWITCHOVERDATE_T','in');

insert into PDATA values (5,'DRIVER_T','in');

insert into PDATA values (6,'RESULT_T','out');

DROP PROCEDURE _SYS_AFL.AFLBFL_DRIVER_PROC;

DROP TYPE "_SYS_AFL"."AFLBFL_DRIVER_PROC__TT_P1";

DROP TYPE "_SYS_AFL"."AFLBFL_DRIVER_PROC__TT_P2";

Page 43: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 43

DROP TYPE "_SYS_AFL"."AFLBFL_DRIVER_PROC__TT_P3";

DROP TYPE "_SYS_AFL"."AFLBFL_DRIVER_PROC__TT_P4";

DROP TYPE "_SYS_AFL"."AFLBFL_DRIVER_PROC__TT_P5";

DROP TYPE "_SYS_AFL"."AFLBFL_DRIVER_PROC__TT_P6";

call afl_wrapper_generator('AFLBFL_DRIVER_PROC','AFLBFL','DRIVER',PDATA);

DROP TABLE HISTORY_TAB ;

CREATE COLUMN TABLE HISTORY_TAB ( "HISTORY" DOUBLE ) ;

INSERT INTO HISTORY_TAB VALUES (1000) ;

DROP TABLE MONTHTAB_TAB ;

CREATE COLUMN TABLE MONTHTAB_TAB ( "TIME" VARCHAR(255)) ;

INSERT INTO MONTHTAB_TAB VALUES ('20100401') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100501') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100601') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100701') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100801') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100901') ;

DROP TABLE SWITCHOVER_TAB ;

CREATE COLUMN TABLE SWITCHOVER_TAB ( "SWITCHOVER" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES (1) ;

DROP TABLE SWITCHOVERDATE_TAB ;

CREATE COLUMN TABLE SWITCHOVERDATE_TAB ( "SWITCHOVERDATE" VARCHAR(255) ) ;

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20100401') ;

DROP TABLE DRIVERS_TAB ;

CREATE TABLE DRIVERS_TAB ( "DRIVER1" DOUBLE, "DRIVER2" DOUBLE, "DRIVER3" DOUBLE) ;

INSERT INTO DRIVERS_TAB VALUES (10, 5, 10) ;

INSERT INTO DRIVERS_TAB VALUES (10, 6, 10) ;

INSERT INTO DRIVERS_TAB VALUES (10, 6, 10) ;

INSERT INTO DRIVERS_TAB VALUES (10, 6, 10) ;

INSERT INTO DRIVERS_TAB VALUES (12, 7, 10) ;

INSERT INTO DRIVERS_TAB VALUES (13, 8, 11) ;

DROP TABLE FORECAST_TAB ;

CREATE COLUMN TABLE FORECAST_TAB ( "FORECAST" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_DRIVER_PROC(HISTORY_TAB, MONTHTAB_TAB, SWITCHOVER_TAB, SWITCHOVERDATE_TAB, DRIVERS_TAB, FORECAST_TAB) WITH OVERVIEW;

SELECT * FROM FORECAST_TAB;

Page 44: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 44

3.12 Feed

This function calculates the closing balance and feeds it to the opening balance of the next time period. For the first period only, the opening balance is defined as Prime. This parameter can either be a constant or a field item. Thereafter, the opening balance derives from the closing balance of the previous period.

Formula

Closing Balance = Opening + In - Out Opening Balance, Period n = Closing Balance, Period n-1 Opening Balance, Period 1 = Prime, Period 1

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double VALUE The opening balance of the first period

In Input Table 1 Double VALUE Incremental amount

Out Input Table 1 Double VALUE Decremented amount

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 2 Double OPENING The opening balance based on previous closing balance

Double CLOSING Closing balance

Page 45: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 45

Example

DROP TABLE PRIME_TAB ;

CREATE TABLE PRIME_TAB ( "VALUE" DOUBLE );

INSERT INTO PRIME_TAB VALUES (5000) ;

DROP TABLE IN_TAB ;

CREATE TABLE IN_TAB ( "VALUE" DOUBLE );

INSERT INTO IN_TAB VALUES (2000) ;

INSERT INTO IN_TAB VALUES (5000) ;

INSERT INTO IN_TAB VALUES (6000) ;

INSERT INTO IN_TAB VALUES (2000) ;

INSERT INTO IN_TAB VALUES (3000) ;

INSERT INTO IN_TAB VALUES (2000) ;

DROP TABLE OUT_TAB ;

CREATE TABLE OUT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO OUT_TAB VALUES (1000) ;

INSERT INTO OUT_TAB VALUES (1000) ;

INSERT INTO OUT_TAB VALUES (1000) ;

INSERT INTO OUT_TAB VALUES (1000) ;

INSERT INTO OUT_TAB VALUES (1000) ;

INSERT INTO OUT_TAB VALUES (1000) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ("OPENING" DOUBLE, "CLOSING" DOUBLE);

CALL _SYS_AFL.AFLBFL_FEED_PROC(PRIME_TAB, IN_TAB, OUT_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 46: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 46

3.13 Feed Overflow

This function calculates the closing balance and feeds it to the opening balance of the next period.

The difference between Feed and Feed Overflow is the following:

• The Out parameter in Feed is a fixed input

• The Out parameter in Feed Overflow is an output which is proportional to Opening.

Feed overflow is commonly used to predict closing balances. This is critical in current planning and seasonal simulation scenarios when the balance sheet has replaced the P&L as the dominant financial report. It is used when the outflow is a function of the opening balance such as tax payments, periodic payments, and accruals or wastage calculations.

For the first period only, the opening balance is defined as Prime. This can either be a constant or a dimension list item. Thereafter, the opening balance derives its value from the closing balance of the previous period.

Formula

Out = Opening * Factor / 100 for Param set to % Out = Opening * Factor for Param set to * Out = Opening / Factor for Param set to / Closing = Opening + In - Out Opening, Period 1 = Prime, Period 1 Opening, Period n = Closing, Period n-1

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double VALUE The opening balance of the first period (default=0)

In Input Table 1 Double VALUE Inflow or incremental amount

Factor Input Table 1 Double VALUE The factor to apply to the opening balance when calculating the parameter, Out (can be multiplied, divided, or taken as a percentage depending on the value of Param.

Indicator Input Table 1 Double VALUE Indicate factor is used as a percentage(0), fraction(1), or denominator(2).

Page 47: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 47

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 3 Double OPENING The opening balance of each period; fed from closing balance of previous period.

Double OUTS Outflow or reduction calculated using the opening balance, parameter and factor

Double CLOSING Closing balance (Closing cash balance)

Example

DROP TABLE PRIME_TAB ;

CREATE TABLE PRIME_TAB ( "VALUE" DOUBLE );

INSERT INTO PRIME_TAB VALUES (5000) ;

DROP TABLE IN_TAB ;

CREATE TABLE IN_TAB ( "VALUE" DOUBLE );

INSERT INTO IN_TAB VALUES (1000) ;

INSERT INTO IN_TAB VALUES (1000) ;

INSERT INTO IN_TAB VALUES (1000) ;

INSERT INTO IN_TAB VALUES (1000) ;

INSERT INTO IN_TAB VALUES (1000) ;

INSERT INTO IN_TAB VALUES (1000) ;

DROP TABLE FACTOR_TAB ;

CREATE TABLE FACTOR_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO FACTOR_TAB VALUES (0) ;

INSERT INTO FACTOR_TAB VALUES (0) ;

INSERT INTO FACTOR_TAB VALUES (50) ;

INSERT INTO FACTOR_TAB VALUES (0) ;

INSERT INTO FACTOR_TAB VALUES (0) ;

INSERT INTO FACTOR_TAB VALUES (0) ;

DROP TABLE INDICATOR_TAB ;

CREATE TABLE INDICATOR_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO INDICATOR_TAB VALUES (0) ;

DROP TABLE RESULTS_TAB ;

Page 48: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 48

CREATE TABLE RESULTS_TAB ( "OPENING" DOUBLE, "OUTS" DOUBLE,"CLOSING" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FEEDOVERFLOW_PROC(PRIME_TAB, IN_TAB, FACTOR_TAB, INDICATOR_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 49: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 49

3.14 Forecast

This function combines actual and forecast data to produce a rolling forecast. In general, it can consume hundreds or thousands of lines of custom business rules in any business scenario or plan, potentially more if it is a "rolling forecast" where actual results refactor forward feeds (see Feed). So implementing forecast as a common function not only reduces the effort on the part of the customer, but also ensures integrity and delivers predictable performance.

Formula

Forecast allows you to use any of the following methods:

• Act/Bud = Use actuals of historical periods and budget for future periods.

• Override = Enter your own forecast manually, overriding the original budget.

• Trend% = Follow the trend to date by working out the actuals to date as a percentage of the budget, and applying this percentage to the future budget.

• Goal = Scale future periods to meet the budget goal over the duration of the timescale.

• Average = Forecast based on an average of actuals to date.

• Linear = Forecast using linear extrapolation.

• Periodic = Scale future periods to meet the cumulative budget goal between points in time defined by a flag.

• Subtotal = Scale future periods to meet the cumulative budget goal between points in time defined by subtotals in the timescale Dimension List.

• Full-term = Scale future periods to meet the budget goal over the duration of the timescale. When the budgets for future periods are all zero, spread any shortfall according to days in period so that the full-term forecast always matches the budget.

Note: The forecast method used is whichever one is specified in the first time period.

Page 50: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 50

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name Description

Period Input Table 1 String PERIOD Specify the period value

Budget Input Table 1 Double BUDGET The budget amount

Actual Input Table 1 Double ACTUAL The actual amount

AFflag Input Table 1 Int AFFLAG A list of specific table driven labels (actual, budget, forecast, etc)

PeriodsNum Input Table 1 Int PERIODSNUM Number of periods to be calculated

Override Input Table 1 Double OVERRIDE Allows new forecast used to override the budget- key for resetting the budget

Days Input Table 1 Int DAYS Number of days (When method is average or linear)

PeriodsFlag Input Table 1 Int PERIODSFLAG Average, Linear

Input Flags

Name Direction Type Description

Method Input Value Int Act/Bud(0), Override(1), Trend(2), Goal(3), Average(4), Linear(5), Periodic(6), Subtotal(7), Full-term(8).

Indicator Input Value Int Number periods(0)

Days in period(1)

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 2 String RE_PERIOD The period value from period table

Double FORECAST The revised forecast based on a combination of actual and forecast amounts

Page 51: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 51

Example

DROP TABLE PERIOD_TAB ;

CREATE COLUMN TABLE PERIOD_TAB ( "PERIOD" VARCHAR(255)) ;

INSERT INTO PERIOD_TAB VALUES ('Jan') ;

INSERT INTO PERIOD_TAB VALUES ('Feb') ;

INSERT INTO PERIOD_TAB VALUES ('Mar') ;

INSERT INTO PERIOD_TAB VALUES ('Apr') ;

INSERT INTO PERIOD_TAB VALUES ('May') ;

INSERT INTO PERIOD_TAB VALUES ('Jun') ;

INSERT INTO PERIOD_TAB VALUES ('Jul') ;

INSERT INTO PERIOD_TAB VALUES ('YEAR') ;

DROP TABLE BUDGET_TAB ;

CREATE COLUMN TABLE BUDGET_TAB ( "BUDGET" DOUBLE ) ;

INSERT INTO BUDGET_TAB VALUES (1000) ;

INSERT INTO BUDGET_TAB VALUES (1000) ;

INSERT INTO BUDGET_TAB VALUES (2000) ;

INSERT INTO BUDGET_TAB VALUES (1000) ;

INSERT INTO BUDGET_TAB VALUES (1000) ;

INSERT INTO BUDGET_TAB VALUES (2000) ;

INSERT INTO BUDGET_TAB VALUES (2000) ;

DROP TABLE ACTUAL_TAB ;

CREATE COLUMN TABLE ACTUAL_TAB ( "ACTUAL" DOUBLE ) ;

INSERT INTO ACTUAL_TAB VALUES (800) ;

INSERT INTO ACTUAL_TAB VALUES (800) ;

INSERT INTO ACTUAL_TAB VALUES (1200) ;

DROP TABLE AFFLAG_TAB ;

CREATE COLUMN TABLE AFFLAG_TAB ( "AFFLAG" INT) ;

INSERT INTO AFFLAG_TAB VALUES (0) ;

INSERT INTO AFFLAG_TAB VALUES (0) ;

INSERT INTO AFFLAG_TAB VALUES (0) ;

INSERT INTO AFFLAG_TAB VALUES (1) ;

INSERT INTO AFFLAG_TAB VALUES (1) ;

INSERT INTO AFFLAG_TAB VALUES (1) ;

INSERT INTO AFFLAG_TAB VALUES (1) ;

DROP TABLE PERIODSNUM_TAB ;

CREATE COLUMN TABLE PERIODSNUM_TAB ( "PERIODSNUM" INT ) ;

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

Page 52: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 52

INSERT INTO PERIODSNUM_TAB VALUES (0) ;

DROP TABLE OVERRIDE_TAB ;

CREATE COLUMN TABLE OVERRIDE_TAB ( "OVERRIDE" DOUBLE ) ;

INSERT INTO OVERRIDE_TAB VALUES (0) ;

INSERT INTO OVERRIDE_TAB VALUES (0) ;

INSERT INTO OVERRIDE_TAB VALUES (0) ;

INSERT INTO OVERRIDE_TAB VALUES (1500) ;

INSERT INTO OVERRIDE_TAB VALUES (1500) ;

INSERT INTO OVERRIDE_TAB VALUES (1500) ;

INSERT INTO OVERRIDE_TAB VALUES (1500) ;

DROP TABLE DAYS_TAB ;

CREATE COLUMN TABLE DAYS_TAB ( "DAYS" INT ) ;

INSERT INTO DAYS_TAB VALUES (0) ;

INSERT INTO DAYS_TAB VALUES (0) ;

INSERT INTO DAYS_TAB VALUES (0) ;

INSERT INTO DAYS_TAB VALUES (0) ;

INSERT INTO DAYS_TAB VALUES (0) ;

INSERT INTO DAYS_TAB VALUES (0) ;

INSERT INTO DAYS_TAB VALUES (0) ;

DROP TABLE PERIODSFLAG_TAB ;

CREATE COLUMN TABLE PERIODSFLAG_TAB ( "PERIODSFLAG" INT ) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

INSERT INTO PERIODSFLAG_TAB VALUES (0) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ( "RE_PERIOD" VARCHAR(255), "FORECAST" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FORECAST_PROC(PERIOD_TAB, BUDGET_TAB, ACTUAL_TAB, AFFLAG_TAB, PERIODSNUM_TAB,OVERRIDE_TAB,DAYS_TAB, PERIODSFLAG_TAB,0,0,RESULTS_TAB) WITH OVERVIEW ;

SELECT * FROM RESULTS_TAB;

Page 53: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 53

3.15 Forecast Agents

This function is a specialized version of the Driver function. It is focused on the entities required to meet service levels.

Forecast Agents is used primarily for labor in areas like call centers and mortgage processing based on interest rate. It can also be used for any constraint-based discrete drivers such as CPU requirements for cloud computing (based on load/users).

Formula

The calculation of Forecast Agents is complex. It can be summarized as follows:

(Agents; LevelFound; LowerLevel; C; LowerC) = Forecast Agents (Method; SLA; ServiceTime; CallsPerHour; AHT)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Method Input Table 1 Double VALUE 1 for fractional agents, and otherwise for whole agents (default)

SLA Input Table 1 Double VALUE Service level: the proportion of service requests that reach an agent in time

ServiceTime Input Table 1 Double VALUE Critical average waiting time (in seconds) before a service request reaches an agent

SRPH Input Table 1 Double VALUE Average number of service requests received in an hour (or a defined period)

Average Handle Time

Input Table 1 Double VALUE Average handling time: service request duration (in seconds)

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double AGENTS Number of agents required

Page 54: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 54

Example

---Table Preparation

DROP TABLE METHOD_TAB ;

CREATE COLUMN TABLE METHOD_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (0) ;

DROP TABLE SLA_TAB ;

CREATE COLUMN TABLE SLA_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO SLA_TAB VALUES (0.7975606) ;

DROP TABLE SERVICETIME_TAB ;

CREATE COLUMN TABLE SERVICETIME_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO SERVICETIME_TAB VALUES (15) ;

DROP TABLE SRPH_TAB ;

CREATE COLUMN TABLE SRPH_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO SRPH_TAB VALUES (720) ;

DROP TABLE HANDLETIME_TAB ;

CREATE COLUMN TABLE HANDLETIME_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO HANDLETIME_TAB VALUES (240) ;

DROP TABLE RESULTS_TAB ;

CREATE COLUMN TABLE RESULTS_TAB ( "AGENTS" DOUBLE) ;

TRUNCATE TABLE RESULTS_TAB;

CALL _SYS_AFL.AFLBFL_FORECASTAGENTS_PROC(METHOD_TAB, SLA_TAB, SERVICETIME_TAB, SRPH_TAB, HANDLETIME_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 55: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 55

3.16 Forecast Driver

This function needs to use the generator mentioned in chapter 2.4.

This function is a specialized version of the Driver Function. It calculates the forecast for future periods using historical data and one single driver.

Forecast Driver shows the incremental effect of the driver on the historical base figure. The forecast is based on the ratio of the driver value at a future time to the driver value in a base period. The base period is defined as the last period containing historical data, namely, the period before the switchover date.

Formula

The forecast and effect are calculated as follows:

Forecast = h * (c / o) Effect = h * ((c / o) – 1)) Where:

c = Current Driver

o = Original Driver

h = Historical base cost in the period before the switchover date

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name Description

History Input Table 1 Double HISTORY Base cost.

Time Input Table 1 String TIME Time series to do forecast based on drivers.

Switchover Input Table 1 Double SWITCHOVER Switchover type:

■ 0 = Default Date

■ 1 = Specific Date

■ 2 = Dimension List

■ 3 = Today

■ 4 = Month

Note: The 1 and 2 options are the same in SAP HANA 1.0 SP3.

Switchover Date

Input Table 1 String SWITCHOVE RDATE

Defines the first future period. This parameter is dependent on the SWITCHOVER type you specify.

Page 56: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 56

Name Direction Number of Columns

Column Type

Column Name Description

Driver Input Table 1 Double/ Int

DRIVER A driver drives cost (e.g. headcount, floor space, unit price, etc.). Only one driver is allowed.

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double FORECAST Forecasted cost

Double EFFECT Incremental effect of an increase in driver

String TIME The time value from time table

Example

DROP TYPE HISTORY_T;

CREATE TYPE HISTORY_T AS TABLE("HISTORY" DOUBLE);

DROP TYPE TIME_T;

CREATE TYPE TIME_T AS TABLE("TIME" VARCHAR(100));

DROP TYPE SWITCHOVER_T;

CREATE TYPE SWITCHOVER_T AS TABLE("SWITCHOVER" DOUBLE);

DROP TYPE SWITCHOVERDATE_T;

CREATE TYPE SWITCHOVERDATE_T AS TABLE("SWITCHOVERDATE" VARCHAR(255));

DROP TYPE DRIVER_T;

CREATE TYPE DRIVER_T AS TABLE("DRIVER" DOUBLE);

DROP TYPE RESULT_T;

CREATE TYPE RESULT_T AS TABLE("FORECAST" DOUBLE, "EFFECT" DOUBLE, "TIME" VARCHAR(100));

DROP TABLE HISTORY_TAB ;

DROP table PDATA;

CREATE column table PDATA("ID" INT,"TYPENAME" VARCHAR(100),"DIRECTION" VARCHAR(100));

insert into PDATA values (1,'HISTORY_T','in');

insert into PDATA values (2,'TIME_T','in');

insert into PDATA values (3,'SWITCHOVER_T','in');

insert into PDATA values (4,'SWITCHOVERDATE_T','in');

insert into PDATA values (5,'DRIVER_T','in');

insert into PDATA values (6,'RESULT_T','out');

DROP PROCEDURE _SYS_AFL.AFLBFL_FORECASTDRIVER_PROC;

Page 57: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 57

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDRIVER_PROC__TT_P1";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDRIVER_PROC__TT_P2";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDRIVER_PROC__TT_P3";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDRIVER_PROC__TT_P4";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDRIVER_PROC__TT_P5";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDRIVER_PROC__TT_P6";

call afl_wrapper_generator('AFLBFL_FORECASTDRIVER_PROC','AFLBFL','DRIVER',PDATA);

CREATE COLUMN TABLE HISTORY_TAB ( "HISTORY" DOUBLE ) ;

INSERT INTO HISTORY_TAB VALUES (1000) ;

INSERT INTO HISTORY_TAB VALUES (2000) ;

DROP TABLE MONTHTAB_TAB ;

CREATE COLUMN TABLE MONTHTAB_TAB ( "TIME" VARCHAR(255)) ;

INSERT INTO MONTHTAB_TAB VALUES ('20100401') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100501') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100601') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100701') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100801') ;

INSERT INTO MONTHTAB_TAB VALUES ('20100901') ;

DROP TABLE SWITCHOVER_TAB ;

CREATE COLUMN TABLE SWITCHOVER_TAB ( "SWITCHOVER" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES (2) ;

DROP TABLE SWITCHOVERDATE_TAB ;

CREATE COLUMN TABLE SWITCHOVERDATE_TAB ( "SWITCHOVERDATE" VARCHAR(255) ) ;

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20100501') ;

DROP TABLE DRIVER_TAB ;

CREATE COLUMN TABLE DRIVER_TAB ( "DRIVER" DOUBLE) ;

INSERT INTO DRIVER_TAB VALUES (10) ;

INSERT INTO DRIVER_TAB VALUES (11) ;

INSERT INTO DRIVER_TAB VALUES (11) ;

INSERT INTO DRIVER_TAB VALUES (11) ;

INSERT INTO DRIVER_TAB VALUES (12) ;

INSERT INTO DRIVER_TAB VALUES (12) ;

DROP TABLE RESULT_TAB;

CREATE COLUMN TABLE RESULT_TAB ( "FORECAST" DOUBLE, "EFFECT" DOUBLE, "TIME" VARCHAR(255)) ;

CALL _SYS_AFL.AFLBFL_FORECASTDRIVER_PROC(HISTORY_TAB, MONTHTAB_TAB, SWITCHOVER_TAB, SWITCHOVERDATE_TAB, DRIVER_TAB, RESULT_TAB) WITH OVERVIEW;

SELECT * FROM RESULT_TAB;

Page 58: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 58

3.17 Forecast Dual Driver

This function needs to use the generator mentioned in chapter 2.4.

This function calculates the forecast for future periods using historical data and two drivers. It also calculates the incremental effect of each driver based on the historical figure. This is a very powerful modeling and scenario planning calculation that is extremely difficult for a customer to script and maintain.

Formula

The base historical period is the period immediately prior to the switchover date. The forecast period is denoted by period n.

Effect1, period n = ((Driver1, period n)/(Driver1, base period)) * (History, base period)

Effect2, period n = ((Driver2, period n)/(Driver2, base period)) * (History, base period)

Interaction, period n = +((Driver1, period n) * (Driver2, period n)) - ((Driver1, base period) * (Driver2, base period)) - ((Effect1, period n) - (Effect2, period n))

Forecast, period n = +(History, base period) +(Effect1, period n) +(Effect2, period n) +(Interaction, period n)

Page 59: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 59

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name Description

History Input Table 1 Double HISTORY Base cost.

Time Input Table 1 String TIME Time series to do forecast based on drivers.

Switchover Input Table 1 Double SWITCHOVER Switchover type:

■ 0 = Default Date

■ 1 = Specific Date

■ 2 = Dimension List

■ 3 = Today

■ 4 = Month

Note: The 1 and 2 options are the same in SAP HANA 1.0 SP3.

Switchover Date

Input Table 1 String SWITCHOVE RDATE

Defines the first future period. This parameter is dependent on the SWITCHOVER type you specify.

Driver Input Table 2 Double/Int

DRIVER1

DRIVER2

A driver is something that drivers the cost (headcount, floor space, unit price, and so on.) Two drivers are allowed.

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double FORECAST Forecasted cost

Double EFFECT1 Incremental effect of an increase in driver

Double EFFECT2 Incremental effect of an increase in second driver

Double INTERACTION The small incremental effect between the drivers

Page 60: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 60

Example

DROP TYPE HISTORY_T;

CREATE TYPE HISTORY_T AS TABLE("HISTORY" DOUBLE);

DROP TYPE TIME_T;

CREATE TYPE TIME_T AS TABLE("TIME" VARCHAR(100));

DROP TYPE SWITCHOVER_T;

CREATE TYPE SWITCHOVER_T AS TABLE("SWITCHOVER" DOUBLE);

DROP TYPE SWITCHOVERDATE_T;

CREATE TYPE SWITCHOVERDATE_T AS TABLE("SWITCHOVERDATE" VARCHAR(255));

DROP TYPE DRIVER_T;

CREATE TYPE DRIVER_T AS TABLE("DRIVER1" DOUBLE, "DRIVER2" DOUBLE);

DROP TYPE RESULT_T;

CREATE TYPE RESULT_T AS TABLE("FORECAST" DOUBLE, "EFFECT1" DOUBLE, "EFFECT2" DOUBLE, "INTERACTION" DOUBLE) ;

DROP table PDATA;

CREATE column table PDATA("ID" INT,"TYPENAME" VARCHAR(100),"DIRECTION" VARCHAR(100));

insert into PDATA values (1,'HISTORY_T','in');

insert into PDATA values (2,'TIME_T','in');

insert into PDATA values (3,'SWITCHOVER_T','in');

insert into PDATA values (4,'SWITCHOVERDATE_T','in');

insert into PDATA values (5,'DRIVER_T','in');

insert into PDATA values (6,'RESULT_T','out');

DROP PROCEDURE _SYS_AFL.AFLBFL_FORECASTDUALDRIVER_PROC;

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDUALDRIVER_PROC__TT_P1";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDUALDRIVER_PROC__TT_P2";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDUALDRIVER_PROC__TT_P3";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDUALDRIVER_PROC__TT_P4";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDUALDRIVER_PROC__TT_P5";

DROP TYPE "_SYS_AFL"."AFLBFL_FORECASTDUALDRIVER_PROC__TT_P6";

call afl_wrapper_generator('AFLBFL_FORECASTDUALDRIVER_PROC','AFLBFL','DRIVER',PDATA);

DROP TABLE HISTORY_TAB;

CREATE TABLE HISTORY_TAB ( "HISTORY" DOUBLE ) ;

INSERT INTO HISTORY_TAB VALUES (1000) ;

INSERT INTO HISTORY_TAB VALUES (1000) ;

INSERT INTO HISTORY_TAB VALUES (1000) ;

INSERT INTO HISTORY_TAB VALUES (1000) ;

DROP TABLE DATECOL_TAB;

CREATE TABLE DATECOL_TAB ( "TIME" VARCHAR(255)) ;

Page 61: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 61

INSERT INTO DATECOL_TAB VALUES ('20100101') ;

INSERT INTO DATECOL_TAB VALUES ('20100201') ;

INSERT INTO DATECOL_TAB VALUES ('20100301') ;

INSERT INTO DATECOL_TAB VALUES ('20100401') ;

INSERT INTO DATECOL_TAB VALUES ('20100501') ;

INSERT INTO DATECOL_TAB VALUES ('20100601') ;

INSERT INTO DATECOL_TAB VALUES ('20100701') ;

INSERT INTO DATECOL_TAB VALUES ('20100801') ;

DROP TABLE SWITCHOVER_TAB;

CREATE TABLE SWITCHOVER_TAB ( "SWITCHOVER" INT ) ;

INSERT INTO SWITCHOVER_TAB VALUES (1) ;

DROP TABLE SWITCHOVERDATE_TAB;

CREATE TABLE SWITCHOVERDATE_TAB ( "SWITCHOVERDATE" VARCHAR(255) ) ;

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20100401') ;

DROP TABLE DRIVERS_TAB;

CREATE TABLE DRIVERS_TAB ( "DRIVER1" DOUBLE,"DRIVER2" DOUBLE) ;

INSERT INTO DRIVERS_TAB VALUES (10,100) ;

INSERT INTO DRIVERS_TAB VALUES (10,100) ;

INSERT INTO DRIVERS_TAB VALUES (10,100) ;

INSERT INTO DRIVERS_TAB VALUES (10,100) ;

INSERT INTO DRIVERS_TAB VALUES (11,120) ;

INSERT INTO DRIVERS_TAB VALUES (11,100) ;

INSERT INTO DRIVERS_TAB VALUES (10,120) ;

INSERT INTO DRIVERS_TAB VALUES (11,124) ;

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ("FORECAST" DOUBLE, "EFFECT1" DOUBLE, "EFFECT2" DOUBLE, "INTERACTION" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FORECASTDUALDRIVER_PROC (HISTORY_TAB, DATECOL_TAB, SWITCHOVER_TAB, SWITCHOVERDATE_TAB, DRIVERS_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 62: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 62

3.18 Forecast Mix

This function mixes actual data prior to the SwitchOver date with forecast data on and after the switchover date. For example Mixed=Mix (April; Actual; Forecast) gives a switchover date of April. This uses actual data up to and including March, and forecast data from April onwards.

Formula

If the current period is before the period containing the switchover date:

Mixed = Actual If the current period comes on or after the switchover date:

Mixed = Forecast

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Actual Input Table 1 Double ACTUAL Actual historic data.

Periods Input Table 1 Double FORECASTMIXPERIODS

Periods need to forecast.

Switchover Input Table 1 Double SWITCHOVER

Switchover type:

■ 0 = Historic

■ 1 = Specific Date

■ 2 = Dimension List

■ 3 = Today

■ 4 = Month

Note: The 1 and 2 options are the same in SAP HANA 1.0 SP3.

Switchover Date

Input Table 1 String SWITCHOVE RDATE

Defines the first future period. This parameter is dependent on the SWITCHOVER type you specify.

Forecast Input Table 1 Double FORECAST Forecast or plan.

Page 63: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 63

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double FORECASTMIX Mixes historic actual data with future forecast figures

Example

DROP TABLE ACTUAL_TAB;

CREATE TABLE ACTUAL_TAB ( "ACTUAL" DOUBLE ) ;

INSERT INTO ACTUAL_TAB VALUES (120) ;

INSERT INTO ACTUAL_TAB VALUES (140) ;

INSERT INTO ACTUAL_TAB VALUES (130) ;

DROP TABLE FORECASTMIXPERIODS_TAB;

CREATE TABLE FORECASTMIXPERIODS_TAB ( "FORECASTMIXPERIODS" DOUBLE) ;

INSERT INTO FORECASTMIXPERIODS_TAB VALUES (12) ;

DROP TABLE SWITCHOVER_TAB;

CREATE TABLE SWITCHOVER_TAB ( "SWITCHOVER" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES (1) ;

DROP TABLE SWITCHOVERDATE_TAB;

CREATE TABLE SWITCHOVERDATE_TAB ( "SWITCHOVERDATE" VARCHAR(255)) ;

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20100301') ;

DROP TABLE FORECAST_TAB;

CREATE TABLE FORECAST_TAB ( "FORECAST" DOUBLE) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

INSERT INTO FORECAST_TAB VALUES (100) ;

DROP TABLE RESULTS_TAB;

Page 64: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 64

CREATE TABLE RESULTS_TAB ("FORECASTMIX" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FORECASTMIX_PROC(ACTUAL_TAB, FORECASTMIXPERIODS_TAB, SWITCHOVER_TAB, SWITCHOVERDATE_TAB, FORECAST_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 65: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 65

3.19 Forecast Sensitivity

Forecast Sensitivity is an erLang function that returns a calculation for the proportion of requests that will be queued because there is no agent available when the request is answered.

Formula

This section lists the equations for each method.

Useful Identities

Some of the equations can be expressed in two Year over Year Difference ways:

(1 - {rho}) * s = s - a or

{mu} * ST / 3600 = ST / AHT The preferred usage is the second expression, which may disguise the equations you are expecting.

Loss

Loss uses the recursive equations:

B[0, a] = 1; and B[s, a] = (a * B[s-1, a]) / (s + a * B[s-1,a] Where B[s, a] is loss for {s} servers and intensity {a}.

Delay

Delay is calculated from the corresponding Loss:

C[s, a] = B[s, a] / ( 1 - {rho}) * ( 1 - B[s, a]) Service Level

Service Level Provided (SLP) is the service level provided by a given number of agents "s" and a given average service time {ST}:

SLP = 1 - C[s, a] * {e}^((a - s) * ST / AHT) Where {e} is Euler's number.

Agents

The number of agents needed to provide a given SLA is the lowest whole number such that:

SLP >= SLA Queue Time

The average waiting time in queue once a call is put in:

1 / ((s - a) * {mu}) Queue Length

The average number of calls in the queue is:

(C[s,a] * {rho} / ( 1 - {rho}) Time to Agent

The average time to agent is:

C[s, a] * AQT=Cs{AQT}

Page 66: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 66

Critical Queue Time

The CQTP is the proportion of calls in the queue for longer than the critical queue time:

{e} ^ ((a-s) * CQT / AHT) Where {e} is Euler's number.

Critical Queue Length

When critical queue length is positive, CQLP is the probability that the number of calls in the queue is greater or equal to the critical queue length:

C[s, a] * {rho} ^ CQL When CQL is negative, the value returned represents the probability that (-{CQL}) or fewer of the agents are free to answer a call when it arrives, or the probability that at least (Agents + Critical Queue Length) agents are busy. The calculations are recursive. Working back from CQL = 0, one agent at a time, they are:

Stop when you know CQLP[j] for j = s + {CQL};

delta[s-1] = C[s,a] * ((s/a)-1); CQLP[s-1] = delta[s-1] + C[s,a] = C[s,a]*s/a. Then, for each j: delta[j-1] = delta[j]*j/a; CQLP[j-1] = delta[j-1] + CQLP[j]

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Agents Input Table 1 Double VALUE The number of agents available

Service Requests Per Hour

Input Table 1 Double VALUE The average service request received in an hour (or period)

Average Handle Time

Input Table 1 Double VALUE The average handling time = request duration in seconds

Service Time

Input Table 1 Double VALUE The critical average waiting time in seconds before a request reaches an agent

Critical Queue Time

Input Table 1 Double VALUE CQT = critical time in seconds that a request remains in the queue once it is put there

Critical Queue Length

Input Table 1 Double VALUE Critical queue length (may be negative)

Page 67: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 67

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 11 Double COMPLETION_RATE

3600/AHT = average number of requests handled per hour by one agent

Double TRAFFIC_RATE Traffic Intensity = Birth Rate/Completion

Double UTILIZATION =Traffic Rate / Agents Proportion of an average agent's time is spent handling a request

Double LOSS Loss Function

Double DELAY Delay Function

Double QUEUE_TIME Average queue time, once a request is put in the queue

Double QUEUE_LENGTH

Average number of requests in the queue

Double TIME_TO_AGENT

Average time in which a request reaches an agent

Double CQT_PROPORTION

Proportion of calls in queue for longer than critical queue time

Double CQL_PROBABILITY

Probability that number of calls in queue is greater or equal to critical queue length

Double SERVICE_LEVEL_PROVIDED

Service level provided

Page 68: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 68

Example

DROP TABLE VALUES1_TAB ;

CREATE TABLE VALUES1_TAB ( "VALUE" DOUBLE );

INSERT INTO VALUES1_TAB VALUES (55) ;

DROP TABLE VALUES2_TAB ;

CREATE TABLE VALUES2_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO VALUES2_TAB VALUES (720) ;

DROP TABLE VALUES3_TAB ;

CREATE TABLE VALUES3_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO VALUES3_TAB VALUES (240) ;

DROP TABLE VALUES4_TAB ;

CREATE TABLE VALUES4_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO VALUES4_TAB VALUES (15) ;

DROP TABLE VALUES5_TAB ;

CREATE TABLE VALUES5_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO VALUES5_TAB VALUES (5) ;

DROP TABLE VALUES6_TAB ;

CREATE TABLE VALUES6_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO VALUES6_TAB VALUES (10) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ( "COMPLETION_RATE" DOUBLE, "TRAFFIC_RATE" DOUBLE,"UTILIZATION" DOUBLE, "LOSS" DOUBLE, "DELAY" DOUBLE, "QUEUE_TIME" DOUBLE, "QUEUE_LENGTH" DOUBLE, "TIME_TO_AGENT" DOUBLE, "CQT_PROPORTION" DOUBLE, "CQL_PROBABILITY" DOUBLE, "SERVICE_LEVEL_PROVIDED" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FORECASTSENSITIVITY_PROC(VALUES1_TAB, VALUES2_TAB, VALUES3_TAB, VALUES4_TAB, VALUES5_TAB, VALUES6_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 69: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 69

3.20 Funds

This function calculates the amount of increased assets or decreased liabilities resulting from the use of funds. This is a critical functionality when planning within government environments or within project planning.

Formula

Funds=Funds (Assets; Sign) With the parameter sign positive, Funds calculates the use of funds.

Funds=Funds (Assets; +) Funds, Period n = (Assets, Period n) - (Assets, Period n-1) With the parameter sign negative, Funds calculates the source of funds.

Funds = Funds (Assets; -) Funds, Period n = (Assets, Period n-1) - (Assets, Period n)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Assets Input Table 1 Double VALUE The asset values

Sign Input Table 1 Int VALUE + or –

Increase in assets displays as positive numbers while source of funds displays as negative numbers.

Change the sign convention so that increase in assets displays as negative numbers and source of funds displays as positive numbers.

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double FUNDS The use of funds

Page 70: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 70

Example

DROP TABLE ASSETS_TAB;

CREATE TABLE ASSETS_TAB( "VALUE" DOUBLE ) ;

INSERT INTO ASSETS_TAB VALUES (1000) ;

INSERT INTO ASSETS_TAB VALUES (2000) ;

INSERT INTO ASSETS_TAB VALUES (4000) ;

INSERT INTO ASSETS_TAB VALUES (8000) ;

INSERT INTO ASSETS_TAB VALUES (8000) ;

DROP TABLE SIGN_TAB;

CREATE TABLE SIGN_TAB( "VALUE" DOUBLE);

INSERT INTO SIGN_TAB VALUES (-1) ;

DROP TABLE FUNDS_TAB;

CREATE TABLE FUNDS_TAB( "FUNDS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FUNDS_PROC(ASSETS_TAB, SIGN_TAB, FUNDS_TAB) WITH OVERVIEW ;

SELECT * FROM FUNDS_TAB ;

Page 71: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 71

3.21 Future

This function calculates the closing balance of an account given the start balance and the conditions under which the account runs. As a key treasury planning function, it is extremely useful for scheduling purchases and payments around favorable account balances, which is particularly important to address when the current economic focus is on balance sheet versus P&L (profit and loss).

Formula

FUTURE VALUE = PRESENT VALUE(Number Periods; Rate; PAYMENT; PRESENT VALUE; Type; Payments; Opening Value; Closing Value; Interest Paid; Periods Left) Start[1+Number Periods]=End[Number Periods]=-FUTURE VALUE If Rate equals 0, then

FUTURE VALUE =-( (PAYMENT * Number Periods) + PRESENT VALUE) If the rate is non-zero, then

FUTURE VALUE = -(( PRESENT VALUE * (1 + Rate) Number Periods) + Payment(1 + (Rate* type))

*Rate

Rate Nper 1)1( −+

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Periods Input Table 1 Double PERIOD Number of periods the account is to run

Rate Input Table 1 Double RATE Rate per period

Original Input Table 1 Double PRESENT Present values

Payment Input Table 1 Double PAYMENT Constant payment applied to the account in each period

Type Input Table 1 Double METHOD Specifies whether the payment is applied at the beginning or end of the period:

■ 0 = at the end of the period

■ 1 = at the beginning of the period

Page 72: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 72

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 6 Double FUTURE Future values

Double PAYMENT Constant payment applied to the account in each period

Double OPENNING The original value

Double CLOSING The final value

Double INTEREST The total paid interest

Double PERIODS Present values

Example

DROP TABLE PERIODS_TAB;

CREATE COLUMN TABLE PERIODS_TAB ( "PERIOD" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (4) ;

INSERT INTO PERIODS_TAB VALUES (3) ;

DROP TABLE RATE_TAB;

CREATE COLUMN TABLE RATE_TAB ( "RATE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

DROP TABLE ORIGINAL_TAB;

CREATE COLUMN TABLE ORIGINAL_TAB ( "PRESENT" DOUBLE ) ;

INSERT INTO ORIGINAL_TAB VALUES (10000) ;

INSERT INTO ORIGINAL_TAB VALUES (-10000) ;

DROP TABLE PAYMENT_TAB;

CREATE COLUMN TABLE PAYMENT_TAB ( "PAYMENT" DOUBLE ) ;

INSERT INTO PAYMENT_TAB VALUES (500) ;

INSERT INTO PAYMENT_TAB VALUES (2500) ;

DROP TABLE METHOD_TAB;

CREATE COLUMN TABLE METHOD_TAB ( "METHOD" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (1) ;

INSERT INTO METHOD_TAB VALUES (1) ;

DROP TABLE FUTURE_TAB;

CREATE TABLE FUTURE_TAB ( "FUTURE" DOUBLE, "PAYMENT" DOUBLE, "OPENNING" DOUBLE, "CLOSING" DOUBLE, "INTEREST" DOUBLE, "PERIODS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_FUTURE_PROC(PERIODS_TAB, RATE_TAB, ORIGINAL_TAB, PAYMENT_TAB, METHOD_TAB, FUTURE_TAB) WITH OVERVIEW;

SELECT * FROM FUTURE_TAB;

Page 73: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 73

3.22 Grow

This function makes a base figure grow at a specified percentage for each period. This can either be compound or linear growth. This function is extremely important for financial calculation that is difficult to script (similar to compound interest functions).

Formula

If the date of which growth is needed to be calculated is prior to the period containing the switchover date:

Grow_result=Base If the date is in the period containing the switchover date:

For compound growth, the increase of each period is calculated based on the previous result:

]100/)(*[ 1___ 11 −−−+= nresultrowresultrowresultrow rateGGG

nnn

For linear growth, the increase of each period is calculated as a percentage of the base figure:

]100/)(*[ 1__ 1 −+=− niresultrowresultrow rateBaseGG

nn

Where n= periods after switchover date, rate=% growth rate, and Base is the base figure in the period containing the switchover date.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Values Input Table 1 Double VALUE Base data.

Periods Input Table 1 Double VALUE Periods to grow.

Rate Input Table 1 Double VALUE Percentage to grow by in each period.

Type Input Table 1 Double VALUE Linear or compound.

Switchover Input Table 1 Double VALUE Linear or compound.

■ Linear – linear growth rate

■ Compound – compound growth rate (default if not specified)

Switchoverdate

Input Table 1 String VALUE Defines the first future period. This parameter is dependent on the switchover type you specify.

Page 74: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 74

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double GROW Grow result

Example

---Table Preparation

DROP TABLE VALUES_TAB ;

CREATE COLUMN TABLE VALUES_TAB ( "VALUE" DOUBLE ) ;base values

INSERT INTO VALUES_TAB VALUES (800);

INSERT INTO VALUES_TAB VALUES (800);

INSERT INTO VALUES_TAB VALUES (900);

INSERT INTO VALUES_TAB VALUES (1000);

DROP TABLE GROWPERIODS_TAB ;

CREATE COLUMN TABLE GROWPERIODS_TAB( "VALUE" DOUBLE );

INSERT INTO GROWPERIODS_TAB VALUES (3);

DROP TABLE GROWRATE_TAB ;

CREATE COLUMN TABLE GROWRATE_TAB ( "VALUE" DOUBLE );

INSERT INTO GROWRATE_TAB VALUES (0.1) ;

DROP TABLE GROWTYPE_TAB ;

CREATE COLUMN TABLE GROWTYPE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO GROWTYPE_TAB VALUES (0) ;

DROP TABLE SWITCHOVER_TAB ;

CREATE COLUMN TABLE SWITCHOVER_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES (1) ;

DROP TABLE SWITCHOVERDATE_TAB ;

CREATE COLUMN TABLE SWITCHOVERDATE_TAB ( "VALUE" VARCHAR(255) ) ;

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20100301') ;

DROP TABLE RESULTS_TAB ;

CREATE COLUMN TABLE RESULTS_TAB ( "GROW" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_GROW_PROC(VALUES_TAB, GROWPERIODS_TAB, GROWRATE_TAB,GROWTYPE_TAB,SWITCHOVER_TAB, SWITCHOVERDATE_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 75: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 75

3.23 Inflated Cash Flow

This function calculates the amount of cash you must receive in a future period to compensate for inflation.

Formula nrBaseValueCurrent )1(* +=

Where,

r = discount rate expressed as a decimal fraction

n = number of periods into the future

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double PRIME Prime/base value

Time Input Table 1 String TIME The periods to be calculated

Rate Input Table 1 Double RATE Discount rate

APR Input Table 1 Double APR =annual % by default

= annual rate (rate=%/100)

= Periodic %

= Periodic rate

Switchover Input Table 1 Double SWITCHOVER

The switchover date defines the last historic period:

= Historic: Treat all periods as historic

=Input Date: Formatted date

=TimeScale: Use rate defined in timescale

=Month: Use month

SwitchoverDate

Input Table 1 String SWITCHOVERDATE

Specify the switchover date

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double RESULT Constant value

Page 76: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 76

Example

DROP TABLE PRIME_TAB;

CREATE COLUMN TABLE PRIME_TAB( "PRIME" DOUBLE ) ;

INSERT INTO PRIME_TAB VALUES (1000) ;

DROP TABLE TIME_TAB;

CREATE COLUMN TABLE TIME_TAB( "TIME" VARCHAR(255)) ;

INSERT INTO TIME_TAB VALUES ('20100101') ;

INSERT INTO TIME_TAB VALUES ('20110101') ;

INSERT INTO TIME_TAB VALUES ('20120101') ;

INSERT INTO TIME_TAB VALUES ('20130101') ;

INSERT INTO TIME_TAB VALUES ('20140101') ;

INSERT INTO TIME_TAB VALUES ('20150101') ;

DROP TABLE RATE_TAB;

CREATE COLUMN TABLE RATE_TAB( "RATE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.1) ;

DROP TABLE APR_TAB;

CREATE COLUMN TABLE APR_TAB( "APR" DOUBLE) ;

INSERT INTO APR_TAB VALUES (3) ;

DROP TABLE SWITCHOVER_TAB;

CREATE COLUMN TABLE SWITCHOVER_TAB( "SWITCHOVER" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES (1) ;

DROP TABLE SWITCHOVERDATE_TAB ;

CREATE COLUMN TABLE SWITCHOVERDATE_TAB( "SWITCHOVERDATE" VARCHAR(255));

INSERT INTO SWITCHOVERDATE_TAB VALUES ('20091231') ;

DROP TABLE RESULTS_TAB ;

CREATE COLUMN TABLE RESULTS_TAB ( "RESULT" DOUBLE);

truncate table RESULTS_TAB;

CALL _SYS_AFL.AFLBFL_INFLATEDCASHFLOW_PROC(PRIME_TAB, TIME_TAB, RATE_TAB, APR_TAB, SWITCHOVER_TAB, SWITCHOVERDATE_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 77: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 77

3.24 Internal Rate of Return (IRR)

This function calculates the IRR for a series of cash flows on specified dates. It is closely related to the Net Present Value Function. For any series of cash flows, the IRR is the rate which makes Net Present value equal to zero.

Formula

Internal Rate of Return is the solution to the equation below:

∑=

+=

N

idd

ii

IRR

P1 )

365( 1

)1(0

Where:

Pi is the Payment Value in the ith period.

di is the ith or last payment date.

d1 is the date at which The IRR is being calculated so that di - d1 means the number of days forward from the day where IRR is being calculated.

It is found by making repeated iterations starting from the value of Estimate.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Values Input Table 1 Double VALUE The series of cash values for which a rate is to be calculated.

Flag Input Table 1 Double FLAG Date of Payment: Start; Middle; End; User defines when, during the period, the payment takes place.

Payment Date

Input Table 1 String PAYDATE The payment date

Estimate Input Table 1 Double ESTIMATE Input as a percentage

Method Input Table 1 Double METHOD Calculate looking forward to all future periods.

Days Input Table 1 Double DAYS Days number in each period

Page 78: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 78

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double INTERNALRATE

The Internal Rate of Return. The rate of return yielded by the series of cash flows calculated as an annual percentage. Recursive calculation.

Example

DROP TABLE VALUES_TAB;

CREATE TABLE VALUES_TAB( "VALUE" DOUBLE );

INSERT INTO VALUES_TAB VALUES (-10000);

INSERT INTO VALUES_TAB VALUES (1000);

INSERT INTO VALUES_TAB VALUES (2500);

INSERT INTO VALUES_TAB VALUES (4000);

INSERT INTO VALUES_TAB VALUES (4000);

INSERT INTO VALUES_TAB VALUES (4000);

INSERT INTO VALUES_TAB VALUES (4000);

DROP TABLE FLAG_TAB;

CREATE TABLE FLAG_TAB( "FLAG" DOUBLE );

INSERT INTO FLAG_TAB VALUES (4);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

DROP TABLE USERDATE_TAB;

CREATE TABLE USERDATE_TAB( "PAYDATE" VARCHAR(255) );

INSERT INTO USERDATE_TAB VALUES ('12/10/00');

DROP TABLE ESTIMATE_TAB;

CREATE TABLE ESTIMATE_TAB( "ESTIMATE" DOUBLE );

INSERT INTO ESTIMATE_TAB VALUES (0.3);

DROP TABLE METHOD_TAB;

CREATE TABLE METHOD_TAB( "METHOD" DOUBLE );

INSERT INTO METHOD_TAB VALUES (0);

INSERT INTO METHOD_TAB VALUES (1);

INSERT INTO METHOD_TAB VALUES (1);

INSERT INTO METHOD_TAB VALUES (1);

INSERT INTO METHOD_TAB VALUES (1);

INSERT INTO METHOD_TAB VALUES (1);

Page 79: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 79

INSERT INTO METHOD_TAB VALUES (1);

DROP TABLE DAYS_TAB;

CREATE TABLE DAYS_TAB( "DAYS" DOUBLE );

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

DROP TABLE RESULT_TAB;

CREATE TABLE RESULT_TAB( "INTERNALRATE" DOUBLE);

CALL _SYS_AFL.AFLBFL_INTERNALRATE_PROC(VALUES_TAB, FLAG_TAB, USERDATE_TAB, ESTIMATE_TAB, METHOD_TAB, DAYS_TAB, RESULT_TAB) WITH OVERVIEW;

SELECT * FROM RESULT_TAB;

Page 80: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 80

3.25 Lag

This function calculates a result in one row by lagging an input from another row by a specified number of periods. This is a streamlined method for estimating lag periods (such as invoice to receipt) directly into the model.

Formula

The result in period n lags the input by p periods;

(Lag result, period n) = (Input, period n-p) If the lagged result requires inputs outside the timescale, use the values from parameter Pad.

(Lag result, period n) = (Pad, period n)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Basevalues Input Table 1 Double VALUE Sets a lag of a variable number of periods according to what is contained in the Dimension List item.

Pad Input Table 1 Double PAD Constant to pad values contrast to the corresponding base values.

Periods Input Table 1 Double PERIOD The series to be lagged (e.g. invoiced amounts).

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double VALUE Lag result (e.g. cash payments made after a lag of n periods).

Page 81: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 81

Example

---Table Preparation

DROP TABLE VALUES_TAB ;

CREATE COLUMN TABLE VALUES_TAB ( "VALUE" DOUBLE ) ;base values

INSERT INTO VALUES_TAB VALUES (1000);

INSERT INTO VALUES_TAB VALUES (2000);

INSERT INTO VALUES_TAB VALUES (2500);

INSERT INTO VALUES_TAB VALUES (2300);

INSERT INTO VALUES_TAB VALUES (3000);

INSERT INTO VALUES_TAB VALUES (1200);

DROP TABLE PAD_TAB ;

CREATE COLUMN TABLE PAD_TAB ( "PAD" DOUBLE ) ;

INSERT INTO PAD_TAB VALUES (999);

INSERT INTO PAD_TAB VALUES (888);

INSERT INTO PAD_TAB VALUES (0);

INSERT INTO PAD_TAB VALUES (0);

INSERT INTO PAD_TAB VALUES (0);

INSERT INTO PAD_TAB VALUES (0);

DROP TABLE PERIOD_TAB ;

CREATE COLUMN TABLE PERIOD_TAB ( "PERIOD" DOUBLE ) ;

INSERT INTO PERIOD_TAB VALUES (2);

INSERT INTO PERIOD_TAB VALUES (2);

INSERT INTO PERIOD_TAB VALUES (2);

INSERT INTO PERIOD_TAB VALUES (2);

INSERT INTO PERIOD_TAB VALUES (2);

INSERT INTO PERIOD_TAB VALUES (2);

DROP TABLE RESULTS_TAB ;

CREATE COLUMN TABLE RESULTS_TAB ( "VALUE" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_LAG_PROC(VALUES_TAB, PAD_TAB, PERIOD_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 82: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 82

3.26 Last

This function looks back over the series of data of the input row and returns the most recent non-zero value. This can be used to avoid re-keying of data over a long timescale in instances where the input changes rarely over the periods (loan receipts).

Formula

The result is the most recent non-zero value of the input in Period n.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double VALUE The series of data on which Last operates.

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double LAST The most recent non-zero value in the series of data to a precision of 1x10^(-12).

Example

DROP TABLE PRIME_TAB;

CREATE TABLE PRIME_TAB( "VALUE" DOUBLE );

INSERT INTO PRIME_TAB VALUES (200);

INSERT INTO PRIME_TAB VALUES (0);

INSERT INTO PRIME_TAB VALUES (0);

INSERT INTO PRIME_TAB VALUES (300);

INSERT INTO PRIME_TAB VALUES (0);

INSERT INTO PRIME_TAB VALUES (400);

INSERT INTO PRIME_TAB VALUES (0);

INSERT INTO PRIME_TAB VALUES (500);

INSERT INTO PRIME_TAB VALUES (0);

DROP TABLE LAST_TAB;

CREATE TABLE LAST_TAB( "LAST" DOUBLE);

CALL _SYS_AFL.AFLBFL_LAST_PROC(PRIME_TAB, LAST_TAB) WITH OVERVIEW;

SELECT * FROM LAST_TAB;

Page 83: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 83

3.27 Lease

This function calculates a payment schedule (e.g. How much you need to pay in each period) for a lease, loan, mortgage, annuity or savings account. It allows several lease contracts to be entered on a single page. The terms of each contract are in a single column. This is similar to the Payment function, but it allows Year over Year Difference leases to be entered in Year over Year Difference columns, as opposed to Year over Year Difference pages.

For each lease, the annual interest rate, term, present and future values are entered, and the constant payments are calculated as a result. Interest is entered per period, and can be constant or vary by each period, and is compounded at the end of each period. Early redemption is allowed, expressed as a percentage of the opening balance. Lease requires equal, consecutive periods.

Embedded Lease Function is a critical element for accurate CAPEX planning and treasury applications.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Advance Amount

Input Table

1 Double ADVANCE The payment to or from the account at the start of the calculation.

Any further amount advanced in subsequent periods can be entered or left as zero if no further advances occur.

Residual Amount

Input Table

1 Double RESIDUAL The payment to or from account at the end of the calculation. Would be zero for a loan which is repayed completely.

Number Periods

Input Table

1 Double PERIODS The number of periods the account is to run.

When to Pay Input Table

1 Double WHENTOPAY 0 = payment is made at the end of the period. (default)

1= payment is made at the start of the period. (reducing end balance faster)

Interest Rate Input Table

1 Double RATE Percentage rate per period.

Redemption Rate

Input Table

1 Double REDEMPTIONREATE

Interpreted as a percentage but must be the rate per period.

Page 84: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 84

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 10 Double OPENING The opening balance of the account. Will be equal to PRESENT VALUE in the first calculation period.

Double ADJUSTED The opening balance of the account adjusted for redemptions and further advances.

Double INTEREST 0 = Adjusted Opening * Rate per Period/100.

1 = (Adjusted Opening + Payment) * Rate per Period/100.

Double PAYMENT The single payment to the account this period. Contains interest element and capital element.

Double REDEMPTION

The amount of the account paid off early

Calculated by:

In Period 1: Advance Amount* Redemption Rate /100.

In subsequent periods:

(Opening Value)* Redemption Rate /100.

Double CAPITAL The amount of capital paid off in the period.

Double RESIDUALPAIDOFF

Will be non-zero only in the last period of the account when it represents the residual value of the loan being repaid.

It is equal to FUTURE VALUE from the first period adjusted by any redemptions during the life of the loan.

Double CLOSING The closing balance of the account. Should be set as a time average, last period.

Page 85: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 85

Name Direction Number of Columns

Column Type

Column Name

Description

Double PERIODSREMAINING

Will be Number Periods in the first calculation period and will reduce by 1 in each subsequent period.

Double CALCRESIDUAL

FUTURE VALUE from the first period adjusted by redemptions during the life of the loan to date.

Example

DROP TABLE ADVANCE_TAB ;

CREATE TABLE ADVANCE_TAB ( "ADVANCE" DOUBLE );

INSERT INTO ADVANCE_TAB VALUES (150000) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

DROP TABLE RESIDUAL_TAB ;

CREATE TABLE RESIDUAL_TAB ( "RESIDUAL" DOUBLE ) ;

INSERT INTO RESIDUAL_TAB VALUES (10000) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ( "PERIODS" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (4) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

DROP TABLE WHENTOPAY_TAB ;

CREATE TABLE WHENTOPAY_TAB ( "WHENTOPAY" DOUBLE ) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

Page 86: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 86

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "RATE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.02) ;

INSERT INTO RATE_TAB VALUES (0.015) ;

INSERT INTO RATE_TAB VALUES (0.015) ;

INSERT INTO RATE_TAB VALUES (0.015) ;

DROP TABLE REDEMPTIONREATE_TAB ;

CREATE TABLE REDEMPTIONREATE_TAB ( "REDEMPTIONREATE" DOUBLE ) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB( "OPENING" DOUBLE, "ADJUSTED" DOUBLE, "INTEREST" DOUBLE, "PAYMENT" DOUBLE, "REDEMPTION" DOUBLE, "CAPITAL" DOUBLE, "RESIDUALPAIDOFF" DOUBLE, "CLOSING" DOUBLE, "PERIODSREMAINING" DOUBLE, "CALCRESIDUAL" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_LEASE_PROC(ADVANCE_TAB, RESIDUAL_TAB, PERIODS_TAB, WHENTOPAY_TAB, RATE_TAB, REDEMPTIONREATE_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 87: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 87

3.28 Lease Variable

This function allows an account to be scheduled along a time scale representing the life of the loan. The time scale must consist of equal consecutive periods and one single payment must be made to the loan account in each period, either at the beginning or end of the period set by the When to Pay parameter. It is not necessary to compound the interest in each period.

Compared with the Lease function, Lease Variable has two more input columns which represent two more parameters: Compound and Recalculate.

• Compound: indicates whether or not to calculate compound interest in this period.

• Recalculate: determines whether or not to recalculate the payment schedule to take account of interest rate changes or other changes during this period.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Advance Amount

Input Table 1 Double ADVANCE The payment to or from the account at the start of the calculation.

Any further amount advanced in subsequent periods can be entered or left zero if no further advances occur.

Residual Amount

Input Table 1 Double RESIDUAL The payment to or from account at the end of the calculation. Would be zero for a loan which repays completely.

Number Periods

Input Table 1 Double PERIODS The number of periods the account is to run.

When to Pay

Input Table 1 Double WHENTOPAY 0 = payment is made at the end of the period. (default)

1= payment is made at the start of the period. (reducing end balance faster)

Interest Rate

Input Table 1 Double RATE Percentage rate per period.

Redemption Rate

Input Table 1 Double REDEMPTIONREATE

Interpreted as a percentage but must be the rate per period.

Compound Input Table 1 Double COMPOUND Indicate whether or not to compound interest this period.

Page 88: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 88

Name Direction Number of Columns

Column Type

Column Name

Description

Recalculate

Input Table 1 Double RECALCULATE

Indicate whether or not to recalculate payments to take account of interest rate changes this period.

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 11 Double OPENING The opening balance of the account. Will be equal to PRESENT VALUE in the first calculation period.

Double ADJUSTED The opening balance of the account adjusted for redemptions and further advances.

Double INTEREST 0 = Adjusted Opening * Rate per Period/100.

1 = (Adjusted Opening + Payment) * Rate per Period/100.

Double ACCRUED Any interest calculated in previous periods not yet applied to the account.

Double PAYMENT The single payment to the account this period. Contains interest element and capital element.

Double REDEMPTION

The amount of the account paid off early

Calculated by:

In Period 1: Advance Amount* Redemption Rate /100.

In subsequent periods:

(Opening Value)* Redemption Rate /100.

Double CAPITAL The amount of capital paid off in the period.

Page 89: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 89

Name Direction Number of Columns

Column Type

Column Name

Description

Double RESIDUALPAIDOFF

Will be non-zero only in the last period of the account when it represents the residual value of the loan being repaid.

It is equal to FUTURE VALUE from the first period adjusted by any redemptions during the life of the loan.

Double CLOSING The closing balance of the account. Should be set as a time average, last period.

Double PERIODSREMAINING

Will be Number Periods in the first calculation period and will reduce by 1 in each subsequent period.

Double CALCRESIDUAL

FUTURE VALUE from the first period adjusted by redemptions during the life of the loan to date.

Page 90: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 90

Example

DROP TABLE ADVANCE_TAB ;

CREATE TABLE ADVANCE_TAB ( "ADVANCE" DOUBLE );

INSERT INTO ADVANCE_TAB VALUES (100000) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

INSERT INTO ADVANCE_TAB VALUES (0) ;

DROP TABLE RESIDUAL_TAB ;

CREATE TABLE RESIDUAL_TAB ( "RESIDUAL" DOUBLE ) ;

INSERT INTO RESIDUAL_TAB VALUES (15000) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

INSERT INTO RESIDUAL_TAB VALUES (0) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ( "PERIODS" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (6) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

INSERT INTO PERIODS_TAB VALUES (0) ;

DROP TABLE WHENTOPAY_TAB ;

CREATE TABLE WHENTOPAY_TAB ( "WHENTOPAY" DOUBLE ) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

INSERT INTO WHENTOPAY_TAB VALUES (1) ;

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "RATE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.01) ;

INSERT INTO RATE_TAB VALUES (0.01) ;

INSERT INTO RATE_TAB VALUES (0.01) ;

INSERT INTO RATE_TAB VALUES (0.01) ;

INSERT INTO RATE_TAB VALUES (0.01) ;

INSERT INTO RATE_TAB VALUES (0.01) ;

Page 91: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 91

DROP TABLE REDEMPTIONREATE_TAB ;

CREATE TABLE REDEMPTIONREATE_TAB ( "REDEMPTIONREATE" DOUBLE ) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

INSERT INTO REDEMPTIONREATE_TAB VALUES (0) ;

DROP TABLE COMPOUND_TAB ;

CREATE TABLE COMPOUND_TAB ( "COMPOUND" DOUBLE ) ;

INSERT INTO COMPOUND_TAB VALUES (2) ;

INSERT INTO COMPOUND_TAB VALUES (2) ;

INSERT INTO COMPOUND_TAB VALUES (2) ;

INSERT INTO COMPOUND_TAB VALUES (2) ;

INSERT INTO COMPOUND_TAB VALUES (2) ;

INSERT INTO COMPOUND_TAB VALUES (2) ;

DROP TABLE RECALCULATE_TAB ;

CREATE TABLE RECALCULATE_TAB ( "RECALCULATE" DOUBLE ) ;

INSERT INTO RECALCULATE_TAB VALUES (2) ;

INSERT INTO RECALCULATE_TAB VALUES (2) ;

INSERT INTO RECALCULATE_TAB VALUES (2) ;

INSERT INTO RECALCULATE_TAB VALUES (2) ;

INSERT INTO RECALCULATE_TAB VALUES (2) ;

INSERT INTO RECALCULATE_TAB VALUES (2) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB( "OPENING" DOUBLE, "ADJUSTED" DOUBLE, "INTEREST" DOUBLE,"ACCRUED" DOUBLE, "PAYMENT" DOUBLE, "REDEMPTION" DOUBLE, "CAPITAL" DOUBLE, "RESIDUALPAIDOFF" DOUBLE, "CLOSING" DOUBLE, "PERIODSREMAINING" DOUBLE, "CALCRESIDUAL" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_LEASEVARIABLE_PROC(ADVANCE_TAB, RESIDUAL_TAB, PERIODS_TAB, WHENTOPAY_TAB, RATE_TAB, REDEMPTIONREATE_TAB,COMPOUND_TAB, RECALCULATE_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 92: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 92

3.29 Linear Average

This function calculates a linear average that applies a larger weight to recent periods. The weights applied decrease linearly as you go back in time.

Formula

∑∑

=

== n

i

n

i

i

iOriginAvg

1

1

)(

))(*()(

Where: Avg(n)= the average for the nth period

Orig(i)= original data for ith period

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Sales Input Table 1 Double VALUE The original series to be averaged (sales)

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double AVERAGED_RESULT

The linear average (average sales)

Example

DROP TABLE SALES_TAB;

CREATE TABLE SALES_TAB( "VALUE" DOUBLE );

INSERT INTO SALES_TAB VALUES (1000) ;

INSERT INTO SALES_TAB VALUES (2000) ;

INSERT INTO SALES_TAB VALUES (1500) ;

INSERT INTO SALES_TAB VALUES (2200) ;

INSERT INTO SALES_TAB VALUES (1750) ;

INSERT INTO SALES_TAB VALUES (2000) ;

DROP TABLE AVERGAESALES_TAB;

CREATE TABLE AVERGAESALES_TAB( "AVERAGED_RESULT" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_LINEARAVERAGE_PROC(SALES_TAB, AVERGAESALES_TAB) WITH OVERVIEW ;

SELECT * FROM AVERGAESALES_TAB ;

Page 93: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 93

3.30 Max Value

This function returns the maximum value of a specific field of items.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Value Input Table 1 Double VALUE Identifies the items that the maximum is taken over

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double MAX_MIXVALUE

The maximum value for the selected items

Input Flag

Name Direction Value Type Description

Flag Input Value 1 Int Specifies this as Max function, corresponding to Min Function

Example

DROP TABLE VALUES1_TAB;

CREATE TABLE VALUES1_TAB("VALUE" DOUBLE);

INSERT INTO VALUES1_TAB VALUES (10);

INSERT INTO VALUES1_TAB VALUES (20);

INSERT INTO VALUES1_TAB VALUES (25);

INSERT INTO VALUES1_TAB VALUES (5);

INSERT INTO VALUES1_TAB VALUES (15);

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ("MAX_MIXVALUE" DOUBLE);

CALL _SYS_AFL.AFLBFL_MAX_MIN_VALUE_PROC(VALUES1_TAB, RESULTS_TAB,1) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 94: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 94

3.31 Minimum Value

This function returns the minimum value of a specific field of items.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Value Input Table 1 Double VALUE Identifies the items that the minimum is taken over

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double MAX_MIXVALUE

The minimum value for the selected items

Input Flag

Name Direction Value Type Description

Flag Input Value 0 Int Specifies this as Min function, corresponding to Max Function

Example

DROP TABLE VALUES1_TAB;

CREATE TABLE VALUES1_TAB("VALUE" DOUBLE);

INSERT INTO VALUES1_TAB VALUES (10);

INSERT INTO VALUES1_TAB VALUES (20);

INSERT INTO VALUES1_TAB VALUES (25);

INSERT INTO VALUES1_TAB VALUES (5);

INSERT INTO VALUES1_TAB VALUES (15);

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ("MAX_MIXVALUE" DOUBLE);

CALL _SYS_AFL.AFLBFL_MAX_MIN_VALUE_PROC(VALUES1_TAB, RESULTS_TAB,0) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 95: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 95

3.32 Moving Average & Moving Sum

This function needs to use the generator mentioned in chapter 2.4.

The Moving Average and Moving Sum built-in functions calculate a moving average or moving sum over specified periods.

Formula

The formula for Moving Average is:

Moving Average = Sum of Originals over n periods/ Number of periods to be averaged The formula for Moving Sum is:

Moving Sum = Sum of Originals over n periods

The relationship between the Moving Sum S and the Moving Average A is:

S=A*length where length is the length of the moving average.

The choice of which originals to include in the formula depends on the style of average and the method of dealing with end conditions for missing data.

Methods R for replicate and L for linear extrapolation estimate the values for the missing periods. Methods P for prime, T for take, U for unequal, and W for weightings estimate the result directly.

Replicate: The first and last original periods are replicated as many times as needed. This is the simplest rule and is used as the default if you do not specify another method.

Linear extrapolation: The missing n periods at the front of the original series are provided by extending the line joining the centers of the first and second set of n periods of the original series. The missing periods at the back are provided in the same way by extending the line joining the last two sets of n input periods to the right.

Prime: Get the unavailable averages from another variable. This is typically a constant (e.g. zero), as strictly speaking the data is not available, but if you know the missing data you can enter it here in the Prime variable.

Take: Takes an average over as many periods as there is data available but does not extrapolate or estimate any further. For example, using a 3 period last average style (L3) with method T for the end conditions would give an average of (Jan/1) in Jan, (Jan+Feb)/2 in Feb and (Jan+Feb+Mar)/3 in Mar. Method T is not permitted with style W.

Unequal: Calculates separate right and left averages using the largest average available and then averages the two averages. This is a better variant of the "T for Take" method for the centered styles C. For styles F and L method U is the same as method T. The central period is shared between the two averages. Method U is not permitted with style W.

Page 96: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 96

Weights: This option gives you the flexibility to provide appropriate weights for the data being averaged/summed. A set of weights is provided for each missing average or sum for styles L and F. For the centered styles C and W, a set of weights is provided for half of the series, the same weights being used to fill the front and the back of the smoothed series.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Original Input Table 1 Double ORIGINAL The original series to be averaged or summed.

Average Style

Input Table 1 Double AVERAGESTYLE

Last Periods(0): Apply to number of previous periods.

Center(1): The average is returned in the center of the n periods averaged.

Weightings(2): Weightings specify the weighting applied to each period. (i.e. 1,2,1 for 3 periods)

Page 97: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 97

Name Direction Number of Columns

Column Type

Column Name

Description

Average Method

Input Table 1 Double AVERAGEMETHOD

Method describes how to fill the periods at the start and end for which data is missing.

Replicate(0): Replicate the first and/or last input periods as many times as needed.

Prime input(1): Prime input variable is used to provide the missing averages that cannot be calculated because the original data is not available. This also applies to Estimating.

Truncated or Take(2): Truncated sums required are scaled up to carry their full weight. For example, if you are calculating a 5 period sum but only 3 periods are available, it will be scaled up by a factor of 5/3.

Unequal length(3): Unequal length averages. Unequal=(Left+Right)/2 using the full length on the side where it is available, and the longest available on the other side.

Weighted Replacement(4): Weights provided in formula to calculate missing inputs.

Prime Input Table 1 Double PRIME The original series to be averaged or summed.

Average Periods

Input Table 1 Double AVERAGEPERIODS

Periods to be calculated.

Weightings Input Table 1~N Double WEIGHTING1~ WEIGHTINGN

Weightings specify the weighting applied to each period. (i.e. 1,2,1 for 3 periods).

Page 98: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 98

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double RESULTS The moving average or sum over n periods.

Example

DROP TYPE ORIGINAL_T ;

CREATE TYPE ORIGINAL_T AS TABLE( "ORIGINAL" DOUBLE ) ;

DROP TYPE AVERAGESTYLE_T ;

CREATE TYPE AVERAGESTYLE_T AS TABLE( "AVERAGESTYLE" DOUBLE ) ;

DROP TYPE AVERAGEMETHOD_T ;

CREATE TYPE AVERAGEMETHOD_T AS TABLE( "AVERAGEMETHOD" DOUBLE ) ;

DROP TYPE PRIME_T ;

CREATE TYPE PRIME_T AS TABLE( "PRIME" DOUBLE ) ;

DROP TYPE AVERAGEPERIODS_T ;

CREATE TYPE AVERAGEPERIODS_T AS TABLE( "AVERAGEPERIODS" DOUBLE ) ;

DROP TYPE WEIGHTINGS_T ;

CREATE TYPE WEIGHTINGS_T AS TABLE( "WEIGHTING1" DOUBLE,"WEIGHTING2" DOUBLE, "WEIGHTING3" DOUBLE) ;

DROP TYPE RESULT_T;

CREATE TYPE RESULT_T AS TABLE("RESULTS" DOUBLE) ;

DROP table PDATA;

CREATE column table PDATA("ID" INT,"TYPENAME" VARCHAR(100),"DIRECTION" VARCHAR(100));

insert into PDATA values (1,'ORIGINAL_T','in');

insert into PDATA values (2,'AVERAGESTYLE_T','in');

insert into PDATA values (3,'AVERAGEMETHOD_T','in');

insert into PDATA values (4,'PRIME_T','in');

insert into PDATA values (5,'AVERAGEPERIODS_T','in');

insert into PDATA values (6,'WEIGHTINGS_T','in');

insert into PDATA values (7,'RESULT_T','out');

DROP PROCEDURE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P1";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P2";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P3";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P4";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P5";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P6";

DROP TYPE "_SYS_AFL"."AFLBFL_MOVINGAVERAGEANDSUM_PROC__TT_P7";

Page 99: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 99

call afl_wrapper_generator('AFLBFL_MOVINGAVERAGEANDSUM_PROC','AFLBFL','MOVINGAVERAGEANDSUM',PDATA);

DROP TABLE ORIGINAL_TAB ;

CREATE TABLE ORIGINAL_TAB ( "ORIGINAL" DOUBLE );

INSERT INTO ORIGINAL_TAB VALUES (1000) ;

INSERT INTO ORIGINAL_TAB VALUES (2000) ;

INSERT INTO ORIGINAL_TAB VALUES (3000) ;

INSERT INTO ORIGINAL_TAB VALUES (2000) ;

INSERT INTO ORIGINAL_TAB VALUES (2000) ;

INSERT INTO ORIGINAL_TAB VALUES (8000) ;

INSERT INTO ORIGINAL_TAB VALUES (6000) ;

INSERT INTO ORIGINAL_TAB VALUES (8000) ;

INSERT INTO ORIGINAL_TAB VALUES (7000) ;

INSERT INTO ORIGINAL_TAB VALUES (10000) ;

INSERT INTO ORIGINAL_TAB VALUES (1000) ;

INSERT INTO ORIGINAL_TAB VALUES (9000) ;

DROP TABLE AVERAGESTYLE_TAB ;

CREATE TABLE AVERAGESTYLE_TAB ( "AVERAGESTYLE" DOUBLE ) ;

INSERT INTO AVERAGESTYLE_TAB VALUES (2) ;

DROP TABLE AVERAGEMETHOD_TAB ;

CREATE TABLE AVERAGEMETHOD_TAB ( "AVERAGEMETHOD" DOUBLE ) ;

INSERT INTO AVERAGEMETHOD_TAB VALUES (0) ;

DROP TABLE PRIME_TAB ;

CREATE TABLE PRIME_TAB ( "PRIME" DOUBLE ) ;

INSERT INTO PRIME_TAB VALUES (1000) ;

DROP TABLE AVERAGEPERIODS_TAB ;

CREATE TABLE AVERAGEPERIODS_TAB ( "AVERAGEPERIODS" DOUBLE ) ;

INSERT INTO AVERAGEPERIODS_TAB VALUES (3) ;

DROP TABLE WEIGHTINGS_TAB ;

CREATE TABLE WEIGHTINGS_TAB ( "WEIGHTING1" DOUBLE,"WEIGHTING2" DOUBLE, "WEIGHTING3" DOUBLE) ;

INSERT INTO WEIGHTINGS_TAB VALUES (1, 2, 1) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB("RESULTS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_MOVINGAVERAGEANDSUM_PROC(ORIGINAL_TAB, AVERAGESTYLE_TAB, AVERAGEMETHOD_TAB, PRIME_TAB, AVERAGEPERIODS_TAB, WEIGHTINGS_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 100: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 100

3.33 Moving Median

This built-in function takes the median value after sorting all input values into ascending sequence. If the number of input values is even, it takes the average of the middle two numbers.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Value Input Table 1 Double VALUE The variable whose median is required

Length Input Table 1 Double LENGTH Number of periods over which to take the median

Offset Input Table 1 Double OFFSET The number of periods offset from the center

Exclude Input Table 1 Double EXCLUDE 0=Include; 1=Exclude

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double RESULTS The median

Page 101: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 101

Example

DROP TABLE VALUE_TAB ;

CREATE TABLE VALUE_TAB ( "VALUE" DOUBLE );

INSERT INTO VALUE_TAB VALUES (1) ;

INSERT INTO VALUE_TAB VALUES (2) ;

INSERT INTO VALUE_TAB VALUES (3) ;

INSERT INTO VALUE_TAB VALUES (4) ;

INSERT INTO VALUE_TAB VALUES (5) ;

INSERT INTO VALUE_TAB VALUES (6) ;

INSERT INTO VALUE_TAB VALUES (7) ;

INSERT INTO VALUE_TAB VALUES (8) ;

INSERT INTO VALUE_TAB VALUES (9) ;

INSERT INTO VALUE_TAB VALUES (10) ;

INSERT INTO VALUE_TAB VALUES (11) ;

INSERT INTO VALUE_TAB VALUES (12) ;

INSERT INTO VALUE_TAB VALUES (13) ;

DROP TABLE LENGTH_TAB ;

CREATE TABLE LENGTH_TAB ( "LENGTH" DOUBLE ) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

INSERT INTO LENGTH_TAB VALUES (6) ;

DROP TABLE OFFSET_TAB ;

CREATE TABLE OFFSET_TAB ( "OFFSET" DOUBLE ) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

Page 102: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 102

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

INSERT INTO OFFSET_TAB VALUES (0.5) ;

DROP TABLE EXCLUDE_TAB ;

CREATE TABLE EXCLUDE_TAB ( "EXCLUDE" DOUBLE ) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (1) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

INSERT INTO EXCLUDE_TAB VALUES (0) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB("RESULTS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_MOVINGMEDIAN_PROC(VALUE_TAB, LENGTH_TAB, OFFSET_TAB, EXCLUDE_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 103: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 103

3.34 Number of Periods

This function calculates the number of periods over which the account must run.

Formula

Start [1+Number Periods] =End [Number Periods] = -Future Value When rate is zero:

Number of Periods =-(Present Value + Future Value)/Payment When rate is not zero:

Number of Periods = )1(*

))/()((*Rate

PVInterFVInter+

+−

Where:

Rate = {%rate}/100 and

Inter = (1+type*rate)*Payment/rate

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Rate Input Table 1 Double VALUE Rate percentage.

Present Input Table 1 Double VALUE The constant payment applied to the account each period.

Payment Input Table 1 Double VALUE The constant payment applied to the account each period.

Future Input Table 1 Double VALUE The value of the account at the end of the calculation.

Method Input Table 1 Double VALUE Specifies whether the payment is applied at the beginning or end of the period:

■ 0 = at the end of the period

■ 1 = at the beginning of the period

Page 104: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 104

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 7 Double PERIOD The number of periods for which the account must run to satisfy the input criteria.

Double CALFUTUREVALUE

The calculated future value of the account. The calculated end cash flow to or from the account.

Double PAYMENT Constant payment applied to the account in each period.

Double OPENNING Returns the opening balance of the account. Will be equal to Present Value.

Double CLOSING Closing balance of the account.

Double INTEREST Opening Value * Rate per Period/100.

(Opening Value + Payment) * Rate per Period/100.

Double PERIODS Will be Number Periods in the first calculation period and will reduce by 1 in each subsequent period.

Page 105: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 105

Example

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "VALUE" DOUBLE );

INSERT INTO RATE_TAB VALUES (0.5) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

DROP TABLE PRESENT_TAB ;

CREATE TABLE PRESENT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PRESENT_TAB VALUES (10000) ;

INSERT INTO PRESENT_TAB VALUES (-10000) ;

DROP TABLE PAYMENT_TAB ;

CREATE TABLE PAYMENT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PAYMENT_TAB VALUES (500) ;

INSERT INTO PAYMENT_TAB VALUES (2500) ;

DROP TABLE FUTURE_TAB ;

CREATE TABLE FUTURE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO FUTURE_TAB VALUES (12000) ;

INSERT INTO FUTURE_TAB VALUES (-2600) ;

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (1) ;

INSERT INTO METHOD_TAB VALUES (1) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ( "PERIOD" DOUBLE,"CALFUTUREVALUE" DOUBLE,"PAYMENT" DOUBLE,"OPENNING" DOUBLE, "CLOSING" DOUBLE,"INTEREST" DOUBLE, "PERIODS" DOUBLE);

CALL _SYS_AFL.AFLBFL_NUMBERPERIODS_PROC(RATE_TAB, PRESENT_TAB, PAYMENT_TAB, FUTURE_TAB, METHOD_TAB, PERIODS_TAB) WITH OVERVIEW;

SELECT * FROM PERIODS_TAB ;

Page 106: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 106

3.35 Net Present Value

This function calculates the sum of a series of future cash flow values after discounting each to a present value based on the annual rate input for the period in which it is being calculated. The calculation for Net Present Value always looks forward, so any values or dates in previous periods are ignored in the calculation. There is no restriction on the number of future payments and the periods between the payments do not need to be equal.

Formula

Net Present Value (j) = ∑=

+

N

jidd

iji

rate

P)

365(

)1(

Where:

Pi is the Payment Value in the ith period.

di is the ith or last payment date.

dj is the date at which the Net Present Value is being calculated so that di - dj means the number of days forward from the day where Net Present Value is being calculated.

Rate is the discount rate per annum to apply to values in future periods.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Rate Input Table 1 Double VALUE The annual rate at which future values are to be discounted.

Values Input Table 1 Double VALUE The series of cash values to be calculated.

Date Flag Input Table 1 Double VALUE Start(1); Mid(2); End(3); User(4)

Payment Date

Input Table 1 String VALUE Date of Payment.

Days Input Table 1 Double VALUE Number of days in each period.

Output Table

Name Direction Number of Columns

Column Type

Column Name

Description

Result Output Table 1 Double NETPRESENTVALUE

The net present value of the series of cash flow.

Page 107: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 107

Example

DROP TABLE RATE_TAB;

CREATE TABLE RATE_TAB( "VALUE" DOUBLE );

INSERT INTO RATE_TAB VALUES (0.05);

INSERT INTO RATE_TAB VALUES (0.05);

INSERT INTO RATE_TAB VALUES (0.05);

INSERT INTO RATE_TAB VALUES (0.05);

INSERT INTO RATE_TAB VALUES (0.05);

INSERT INTO RATE_TAB VALUES (0.05);

DROP TABLE VALUES_TAB;

CREATE TABLE VALUES_TAB( "VALUE" DOUBLE );

INSERT INTO VALUES_TAB VALUES (-100000);

INSERT INTO VALUES_TAB VALUES (60000);

INSERT INTO VALUES_TAB VALUES (0);

INSERT INTO VALUES_TAB VALUES (40000);

INSERT INTO VALUES_TAB VALUES (50000);

INSERT INTO VALUES_TAB VALUES (10000);

DROP TABLE FLAG_TAB;

CREATE TABLE FLAG_TAB( "VALUE" INT );

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

INSERT INTO FLAG_TAB VALUES (3);

DROP TABLE USERDATE_TAB;

CREATE TABLE USERDATE_TAB( "VALUE" VARCHAR(255) );

INSERT INTO USERDATE_TAB VALUES ('12/10/00');

DROP TABLE DAYS_TAB;

CREATE TABLE DAYS_TAB( "VALUE" INT );

INSERT INTO DAYS_TAB VALUES (90);

INSERT INTO DAYS_TAB VALUES (91);

INSERT INTO DAYS_TAB VALUES (92);

INSERT INTO DAYS_TAB VALUES (92);

INSERT INTO DAYS_TAB VALUES (365);

INSERT INTO DAYS_TAB VALUES (365);

DROP TABLE RESULT_TAB;

CREATE TABLE RESULT_TAB( "NETPRESENTVALUE" DOUBLE);

CALL _SYS_AFL.AFLBFL_NETPRESENTVALUE_PROC(RATE_TAB, VALUES_TAB, FLAG_TAB, USERDATE_TAB, DAYS_TAB, RESULT_TAB) WITH OVERVIEW;

SELECT * FROM RESULT_TAB;

Page 108: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 108

3.36 Outlook

The Outlook is calculated by using actuals of past months and plan figures of future months. This is a critical function both for current shortfalls and overachievement. For shortfall, it drives management attention to key drivers, while for overachievement it reflects the necessary changes to the supply chain to meet increased demand.

The switchover date is taken as the first future period. The outlook for future periods is derived by revising the plan. The method is based on keeping the target for each subtotal the same as the plan, taking into account the actuals to date. In periods on/prior to switchover date, the outlook is calculated as equal to the actuals.

Formula

If the current period is before the period containing the switchover date, then:

Outlook = Actual If the current period comes on or after the switchover date, where possible the Outlook is adjusted to meet the plan:

Outlook, Full Year = Plan, Full Year Outlook, period n = Pro-rata allocation of ((Plan, Full Year) - (Sum of actuals to date))

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Plan Input Table 1 Double VALUE The original plan.

Actual Input Table 1 Double VALUE Actual historic data.

Method Input Table 1 Double VALUE 0: Full Year

1: Periods

Switchover Input Table 1 Double VALUE Historic: Treat all periods as historic.

Specific Date: Select a date.

Field: Use switchover date in timescale field.

Today: Use today's date.

Month: Input month.

Switchoverdate

Input Table 1 String SWITCHOVERDATE

Defines the first future period. This parameter is dependent on the switchover type you specify.

Page 109: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 109

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double OUTLOOK The outlook result combines historic actual with a future plan.

Example

DROP TABLE PLAN_TAB ;

CREATE TABLE PLAN_TAB ( "VALUE" DOUBLE );

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

INSERT INTO PLAN_TAB VALUES (1000) ;

DROP TABLE ACTUAL_TAB ;

CREATE TABLE ACTUAL_TAB ("VALUE" DOUBLE) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

INSERT INTO ACTUAL_TAB VALUES (500) ;

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB ("VALUE" DOUBLE) ;

INSERT INTO METHOD_TAB VALUES (0) ;

DROP TABLE SWITCHOVER ;

CREATE TABLE SWITCHOVER ("VALUE" DOUBLE) ;

INSERT INTO SWITCHOVER VALUES (1) ;

DROP TABLE SWITCHOVERDATE ;

Page 110: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 110

CREATE TABLE SWITCHOVERDATE ("SWITCHOVERDATE" VARCHAR(255)) ;

INSERT INTO SWITCHOVERDATE VALUES ('20050701') ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ("OUTLOOK" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_OUTLOOK_PROC(PLAN_TAB, ACTUAL_TAB,METHOD_TAB, SWITCHOVER,SWITCHOVERDATE, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 111: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 111

3.37 Payment

This function calculates the regular payment to an account for each period.

Formula

Start [1+Number Periods] =End [Number Periods] = -Future Value When rate is zero, then:

Payment=-(Present Value +Future Value)/Number Periods When rate is not zero:

QNRPVFV

RateRateTypeRateRatePVFVPMT NPer

NPer

))*(()1)1((*)*1(

*))1(*(

+−=

−++++−

=

Where: riodsNumberofPerateNR )1( +=

and

Q=(1+type*rate)*(NR-1)/rate

Page 112: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 112

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Rate Input Table 1 Double VALUE Rate per period as a percentage.

Periods Input Table 1 Double VALUE The number of periods to be run.

Present Input Table 1 Double VALUE Payment to/from the account initiating the calculation (can be zero).

Future Input Table 1 Double VALUE The payment to or from the account at the end of the calculation, which would be zero if a loan repays completely.

Method Input Table 1 Double VALUE ■ End of Period (0)

■ Beginning of Period (1)

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 5 Double PAYMENT Constant payment applied to the account in each period.

Double OPENNING Returns the opening balance of the account. Will be equal to Present Value.

Double CLOSING Closing balance of the account.

Double INTEREST Opening Value * Rate per Period/100.

(Opening Value + Payment) * Rate per Period/100.

Double PERIODS Number Periods in the first calculation period and will reduce by 1 in each subsequent period.

Page 113: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 113

Example

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (4) ;

INSERT INTO PERIODS_TAB VALUES (3) ;

DROP TABLE PRESENT_TAB ;

CREATE TABLE PRESENT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PRESENT_TAB VALUES (10000) ;

INSERT INTO PRESENT_TAB VALUES (-10000) ;

DROP TABLE FUTURE_TAB ;

CREATE TABLE FUTURE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO FUTURE_TAB VALUES (-12000) ;

INSERT INTO FUTURE_TAB VALUES (-2600) ;

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (1) ;

INSERT INTO METHOD_TAB VALUES (1) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ( "PAYMENT" DOUBLE, "OPENNING" DOUBLE, "CLOSING" DOUBLE,"INTEREST" DOUBLE, "PERIODS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_PAYMENT_PROC(RATE_TAB, PERIODS_TAB, PRESENT_TAB, FUTURE_TAB, METHOD_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 114: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 114

3.38 Present Value

This function calculates opening value given target closing balance and various parameters by assuming:

• Equal consecutive periods

• Constant interest rate compounded to the account at the end of each period

• A constant payment amount each period

Payments can be calculated at either the start or the end of the period.

Formula

Start [1+Number Periods] =End [Number Periods] =-Future Value If Rate = 0, then:

Present Value = (Payment * Number Periods) + Future Value If the rate is non-zero, then:

Nper

Nper

Rate

FVRate

RateTypeRatePMTPV

)1(

)1)1(*))*(1((

+

+−+

+−=

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Rate Input Table 1 Double VALUE Rate per period.

Periods Input Table 1 Double VALUE The number of periods.

Payment Input Table 1 Double VALUE Constant payment applied each period.

Future Input Table 1 Double VALUE The payment to/from at the end of the calculation.

Method Input Table 1 Double VALUE ■ 0 = at the end of the period

■ 1 = at the beginning of the period

Page 115: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 115

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 6 Double ORIGINAL The start value or opening payment to or from the account in the first period.

Double PAYMENT Value of PAYMENT for every period

Double OPENNING Opening balance of the account. Will be equal to Present Value.

Double CLOSING Closing balance of the account.

Double INTEREST Opening Value * Rate per Period/100.

(Opening Value + Payment) * Rate per Period/100.

Double PERIODS Will be Number Periods in the first calculation period and will reduce by 1 in each subsequent period.

Page 116: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 116

Example

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

INSERT INTO RATE_TAB VALUES (0.5) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (4) ;

INSERT INTO PERIODS_TAB VALUES (3) ;

DROP TABLE PAYMENT_TAB ;

CREATE TABLE PAYMENT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PAYMENT_TAB VALUES (500) ;

INSERT INTO PAYMENT_TAB VALUES (2500) ;

DROP TABLE FUTURE_TAB ;

CREATE TABLE FUTURE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO FUTURE_TAB VALUES (12000) ;

INSERT INTO FUTURE_TAB VALUES (-2600) ;

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (1) ;

INSERT INTO METHOD_TAB VALUES (1) ;

DROP TABLE PRESENT_TAB ;

CREATE TABLE PRESENT_TAB ( "ORIGINAL" DOUBLE,"PAYMENT" DOUBLE,"OPENNING" DOUBLE, "CLOSING" DOUBLE,"INTEREST" DOUBLE, "PERIODS" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_PRESENTVALUE_PROC(RATE_TAB, PERIODS_TAB, PAYMENT_TAB, FUTURE_TAB, METHOD_TAB, PRESENT_TAB) WITH OVERVIEW;

SELECT * FROM PRESENT_TAB ;

Page 117: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 117

3.39 Proportion

This function allows you to input a start and end date, and then calculates the proportion of the period length.

Formula

Proportion all days = (Stop date - Start date) / (Period finish date - Period start date) Proportion working days is the same, but excludes weekends.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Year Input Table 1 String VALUE The year to be calculated

Start Input Table 1 String VALUE Start Date

Stop Input Table 1 String VALUE End Date to be calculated

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double PROPORTION The proportion of the period length

Page 118: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 118

Example

DROP TABLE YEAR_TAB ;

CREATE TABLE YEAR_TAB ( "VALUE" varchar(8) ) ;

INSERT INTO YEAR_TAB VALUES ('2000');

DROP TABLE START_TAB ;

CREATE TABLE START_TAB( "VALUE" varchar(8) );

INSERT INTO START_TAB VALUES ('20000401');

DROP TABLE STOP_TAB ;

CREATE TABLE STOP_TAB( "VALUE" varchar(8) );

INSERT INTO STOP_TAB VALUES ('20000625');

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ( "PROPORTION" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_PROPORTION_PROC(YEAR_TAB, START_TAB, STOP_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 119: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 119

3.40 Rate

This function calculates the percentage interest rate per period for an account, given its start balance, end balance, payment amount per period, and the number of periods. The solution is iterative, so it is possible that for a given set of inputs, there may be more than one solution or no solution.

If Present Value, Future Value, and Payment are all input with the same sign then there will be no solution. If there is more than one solution, setting a non-zero value for parameter Estimate may cause an alternative rate value to be returned.

Assumptions:

• Equal consecutive periods

• Constant, compounded interest rate applied at the end of each period

• Payment is constant

Payment can be at the start or the end of the period.

Formula

Start [1+Number Periods] =End [Number Periods] = -Future Value Rate is the solution to the family equation for the Payment, Present Value, Future Value, Number Periods, and Rate:

FVRate

RateTypeRatepmtRatePVNper

Nper +−+

+++=1))1((*))*(1())1((*0

Rate is an iterative method requiring a start value. Therefore parameter Estimate is used as the starting value and is set to a default of 0.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Present Input Table 1 Double VALUE Value of the payment to/from the account at the beginning.

Periods Input Table 1 Double VALUE The number of periods the account runs.

Payment Input Table 1 Double VALUE Constant payment applied each period.

Future Input Table 1 Double VALUE The payment to/from at the end of the calculation.

Method Input Table 1 Double VALUE ■ 0 = at the end of the period

■ 1 = at the beginning of the period

Page 120: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 120

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 6 Double RATE The percentage rate per period for the account.

Double PAYMENT Value of PAYMENT for every period,

Double OPENNING Opening balance of the account. Will be equal to Present Value,

Double CLOSING Closing balance of the account.

Double INTEREST Opening Value * Rate per Period/100.

(Opening Value + Payment) * Rate per Period/100.

Double PERIODS Will be Number Periods in the first calculation period and will reduce by 1 in each subsequent period.

Page 121: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 121

Example

DROP TABLE PRESENT_TAB ;

CREATE TABLE PRESENT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PRESENT_TAB VALUES (10000) ;

INSERT INTO PRESENT_TAB VALUES (-10000) ;

DROP TABLE PERIODS_TAB ;

CREATE TABLE PERIODS_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (4) ;

INSERT INTO PERIODS_TAB VALUES (3) ;

DROP TABLE PAYMENT_TAB ;

CREATE TABLE PAYMENT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO PAYMENT_TAB VALUES (450) ;

INSERT INTO PAYMENT_TAB VALUES (2500) ;

DROP TABLE FUTURE_TAB ;

CREATE TABLE FUTURE_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO FUTURE_TAB VALUES (12000) ;

INSERT INTO FUTURE_TAB VALUES (-2600) ;

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (1) ;

INSERT INTO METHOD_TAB VALUES (1) ;

DROP TABLE RATE_TAB ;

CREATE TABLE RATE_TAB ( "RATE" DOUBLE, "PAYMENT" DOUBLE,"OPENNING" DOUBLE, "CLOSING" DOUBLE,"INTEREST" DOUBLE, "PERIODS" DOUBLE);

CALL _SYS_AFL.AFLBFL_RATE_PROC(PRESENT_TAB, PERIODS_TAB, PAYMENT_TAB, FUTURE_TAB, METHOD_TAB, RATE_TAB) WITH OVERVIEW;

SELECT * FROM RATE_TAB ;

Page 122: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 122

3.41 Repeat

This built-in function is used to repeat data from a single period or group of periods through the time scale of the Dimension List.

It has two inputs:

• Number: The number of periods to be repeated and is set by entering as a prime into the first time period of the timescale.

• Original Value: The series of values to be repeated.

Repeat can be used to copy seasonal factors through the timescale.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Number Input Table 1 Double VALUE The number of periods to be repeated and is set by entering as a prime into the first time period of the timescale.

Input Input Table 1 Double VALUE The series of values to be repeated.

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double RESULT Repeat output result

Page 123: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 123

Example

DROP TABLE NUMBER_TAB;

CREATE TABLE NUMBER_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO NUMBER_TAB VALUES (7) ;

DROP TABLE INPUT_TAB;

CREATE TABLE INPUT_TAB ( "VALUE" DOUBLE );

INSERT INTO INPUT_TAB VALUES (1) ;

INSERT INTO INPUT_TAB VALUES (1) ;

INSERT INTO INPUT_TAB VALUES (1) ;

INSERT INTO INPUT_TAB VALUES (1) ;

INSERT INTO INPUT_TAB VALUES (1) ;

INSERT INTO INPUT_TAB VALUES (0) ;

INSERT INTO INPUT_TAB VALUES (0) ;

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ( "RESULT" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_REPEAT_PROC(NUMBER_TAB, INPUT_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 124: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 124

3.42 Rounding

This function calculates the rounded values for a specified input item according to a chosen rounding method. These rounding methods allow you to round figures up, down, away from zero (up for positive numbers, down for negative numbers), or toward zero (down for positive numbers, up for negative numbers).

You can combine the rounding methods with either of the below cumulative option:

1. Sum a series of rounded values

2. Sum a series of non-rounded values and then rounding the total

Always, ensure the above two results are the same.

Page 125: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 125

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Date Input Table 1 Double DATE The item with the values you want to round.

Precision Input Table 1 Double PRECISION The decimal interval.

1 = To nearest integer

0.1 = To 1 decimal place

0.01 = To 2 decimal places

1000 = To nearest 1000

0.25 = To nearest quarter

12 = To nearest dozen

Method Input Table 1 Double METHOD Nearest(0): Nearest rounds to the nearest whole integer. This is the default method.

Up(1): Up rounds up to the nearest whole integer.

Down(2): Down rounds down to the nearest whole integer.

Away(3): Away from zero rounds a positive value up to the nearest whole integer and a negative value down to the nearest whole integer.

Toward(4): Toward zero rounds a positive value down to the nearest whole integer and a negative value up to the nearest whole integer.

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double ROUNDING The outlook result combines historic actual with a future plan.

Page 126: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 126

Example

DROP TABLE DATE_TAB ;

CREATE TABLE DATE_TAB ( "DATE" DOUBLE ) ;

INSERT INTO DATE_TAB VALUES (200.1345);

DROP TABLE PRECISION_TAB ;

CREATE TABLE PRECISION_TAB( "PRECISION" DOUBLE );

INSERT INTO PRECISION_TAB VALUES (0.1);

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB( "METHOD" DOUBLE );

INSERT INTO METHOD_TAB VALUES (5);

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ( "ROUNDING" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_ROUNDING_PROC(DATE_TAB, PRECISION_TAB, METHOD_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 127: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 127

3.43 Seasonal Simple & Seasonal Complex

These two built-in functions both perform seasonal adjustments of time to determine seasonal patterns in data. They use the same programs to calculate their results. They are different only in the number of methods and input and output variables available.

Seasonal Complex has more functionality and flexibility than Seasonal Simple and is intended for the highly advanced user of statistical data. Seasonal Simple is much easier to use because it uses fewer methods, inputs and outputs.

Method

The full Seasonal Complex model is:

O=T*C*S*W*I Where: O is the original data, T is the trend, C is the cyclical effect, S is the seasonal effect, I is the internal rate of return and W is working days.

Method 1- Basic method

1 = Multiplicative; 2 = Additive.

All Seasonal Simple methods are Multiplicative. The multiplicative model is O = T * C * S * I.

The arithmetic for additive model is O = T + C + S + I.

In the multiplicative model the seasonal effects add up to the number of periods in a year, whereas in an additive model they add up to zero.

You might expect the minimum temperature in a month to be better represented by an additive model, particularly if you want to compare the seasonal patterns of Year over Year Difference places. You must use Seasonal Complex if you want to do this.

Method 2- Average method

1 = Medial average; 2 = MA average; 3 = Average year; 4 = Typical year.

For each actual period, SF(Seasonal Factor) = 100 * {original} / {Trend estimate} gives a value for the seasonal factor. The {Trend estimate} is usually a moving average, that is, with 6 years of history you only have 5 years of SF values. We look at each period over all its years to get one estimate for its factor. The preferred approach is to throw away the highest and lowest values, then average the rest, this is the medial average. With 2 to 5 years of data (that is, 2 to 4 SF values), Seasonal Simple averages all the available factors, this is the MA average.

With fewer than 2 years actual data we have to use the typical year method. For each period, the {period average} is the average of its original values over all available history years. The typical year is then a year of all the {period average} values, and the seasonal factor for each period is

{Factor} = 100 * {Period average} / {year total of period averages} Complex Method 3 - MA method

1 = Centered MA; 2 = Uncentered MA; 3 = Straight line trend fitted to original data; 4 = Straight line trend fitted to whole year totals.

The {Trend Estimate} used when using Averages Methods 1 or 2 is provided by a moving average (MA), whose length is equal to the number of periods in a year. Most timescales have an even number

Page 128: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 128

of periods per year (typically months or quarters), so it is necessary to center the MA to avoid bias when the trend is not constant. The centered MA for May is the average of the two averages for (November to October) and for (December to November). Using this method, you lose a whole year of actuals (six months at the beginning and six months at the end) when you calculate the MA.

With 2 to 4 years of actuals, Seasonal Simple uses method 4, the trend through whole years, to provide the {trend estimate} to calculate factors. This means assembling as many whole year averages, as far apart from each other as possible, and fitting a straight line through them to get the {Trend Estimate}. Method 4 - Working Days

1 = No working day adjustment; 2 = User input working days; 3 = Use calendar days as working days.

Seasonal Simple always uses the no working day adjustment method. Seasonal Complex will remove the adjustment from actual periods, and then apply it to forecast periods. If you believe the level of your data depends on the number of days in your month, then doing this can improve the accuracy of your forecasts.

Method 5 - Cycles

1 = No cycles in forecast or calculations; 2 = Apply cycles to forecast; 3 = Adjust for cycles in calculations and apply them to the forecast.

Seasonal Simple always uses no cycles in forecast or calculations. Using the Seasonal Complex method enables you to exert considerable control over the results from calculating the factors and forecasts.

Method 6 - Trend

1 = Fit straight line trend through the adjusted data; 2 = Fit straight line trend through the original data; 3 = Constant trend = Average of adjusted actual data; 4 = Parabolic trend, through the adjusted data

Seasonal Simple prefers to use method 1, but will use method 3 when there is not much history. You can insist on any of methods 1, 3 or 4. Method 2 is the classic method, you can use Seasonal Complex if you want to.

Page 129: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 129

3.43.1 Seasonal Complex

Formula

Seasonal Complex = Seasonal Complex (Method; ActFlag; Original; WorkingDays; Cycle%; OverFlag; OverValue; Factor; Adjusted; MovingAverage; Ratio; Trend; Cycle; Internal Rate of Returnegular; Calculated; Diagnostics)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Original Input Table 1 Double ORIGINAL The data to be seasonally adjusted

Working Days

Input Table 1 Double WORKINGDAYS

The working days in the period

Cycle Input Table 1 Double CYCLE The cycle percent

Override Input Table 1 Double OVERRIDE Override flag

Override Value

Input Table 1 Double OVERRIDEVALUE

Override value

Config Input Table 1 Double CONFIG Has three rows, the meaning is as follows:

Row 0: Specify method like in Seasonal Simple

Row1: Specify the period number, refer to Seasonal Simple

Row 2: Specify the forecast periods

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 4 Double TREND The long term trend of the data

Double DIAGNOTICS A few simple diagnostics to evaluate the model

Double CALCULATED The forecast of the expected original value for every period

Double FORECAST OverValue if OverFlag = 1, Original if ActFlag = 1, otherwise Calculated

Page 130: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 130

Example

DROP TABLE ORIGINAL_TAB ;

CREATE COLUMN TABLE ORIGINAL_TAB ( "ORIGINAL" DOUBLE ) ;

INSERT INTO ORIGINAL_TAB VALUES (150) ;

INSERT INTO ORIGINAL_TAB VALUES (108) ;

INSERT INTO ORIGINAL_TAB VALUES (112) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (119) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (134) ;

INSERT INTO ORIGINAL_TAB VALUES (139) ;

INSERT INTO ORIGINAL_TAB VALUES (143) ;

INSERT INTO ORIGINAL_TAB VALUES (240) ;

INSERT INTO ORIGINAL_TAB VALUES (220) ;

INSERT INTO ORIGINAL_TAB VALUES (155) ;

INSERT INTO ORIGINAL_TAB VALUES (162) ;

INSERT INTO ORIGINAL_TAB VALUES (166) ;

INSERT INTO ORIGINAL_TAB VALUES (172) ;

INSERT INTO ORIGINAL_TAB VALUES (170) ;

INSERT INTO ORIGINAL_TAB VALUES (171) ;

INSERT INTO ORIGINAL_TAB VALUES (169) ;

INSERT INTO ORIGINAL_TAB VALUES (188) ;

INSERT INTO ORIGINAL_TAB VALUES (195) ;

INSERT INTO ORIGINAL_TAB VALUES (198) ;

INSERT INTO ORIGINAL_TAB VALUES (320) ;

INSERT INTO ORIGINAL_TAB VALUES (300) ;

INSERT INTO ORIGINAL_TAB VALUES (220) ;

INSERT INTO ORIGINAL_TAB VALUES (222) ;

DROP TABLE WORKINGDAYS_TAB ;

CREATE COLUMN TABLE WORKINGDAYS_TAB ( "WORKINGDAYS" DOUBLE ) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (31) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (31) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (28) ;

Page 131: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 131

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (29) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (31) ;

INSERT INTO WORKINGDAYS_TAB VALUES (31) ;

INSERT INTO WORKINGDAYS_TAB VALUES (31) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (29) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (29) ;

INSERT INTO WORKINGDAYS_TAB VALUES (30) ;

INSERT INTO WORKINGDAYS_TAB VALUES (31) ;

DROP TABLE CYCLE_TAB ;

CREATE COLUMN TABLE CYCLE_TAB ( "CYCLE" DOUBLE ) ;

INSERT INTO CYCLE_TAB VALUES (1) ;

INSERT INTO CYCLE_TAB VALUES (100) ;

INSERT INTO CYCLE_TAB VALUES (1) ;

INSERT INTO CYCLE_TAB VALUES (10) ;

INSERT INTO CYCLE_TAB VALUES (2002) ;

DROP TABLE OVERRIDE_TAB ;

CREATE COLUMN TABLE OVERRIDE_TAB("OVERRIDE" DOUBLE);

INSERT INTO OVERRIDE_TAB VALUES (1.0) ;

DROP TABLE OVERRIDEVALUE_TAB ;

CREATE COLUMN TABLE OVERRIDEVALUE_TAB("OVERRIDEVALUE" DOUBLE);

INSERT INTO OVERRIDEVALUE_TAB VALUES (10.0);

DROP TABLE CONFIG_TAB ;

CREATE COLUMN TABLE CONFIG_TAB("CONFIG" DOUBLE);

INSERT INTO CONFIG_TAB VALUES (111111);

INSERT INTO CONFIG_TAB VALUES (12);

INSERT INTO CONFIG_TAB VALUES (1);

DROP TABLE RESULTS_TAB ;

Page 132: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 132

CREATE TABLE RESULTS_TAB ("TREND" DOUBLE, "DIAGNOTICS" DOUBLE,"CALCULATED" DOUBLE, "FORECAST" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_SEASONALCOMPLEX_PROC(ORIGINAL_TAB,WORKINGDAYS_TAB,CYCLE_TAB, OVERRIDE_TAB,OVERRIDEVALUE_TAB, CONFIG_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 133: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 133

3.43.2 Seasonal Simple Seasonal Simple is suitable for calculating data with sufficient history, at least one whole year, although five or more years are preferred and the data is of a multiplicative type, and all trends are straight lines. Other methods should be used if you have a longer history and the seasonal factors have changed during the course of the history.

Formula

In Seasonal Simple the Cyclical and Working Day effects are not calculated, so the model is:

O = T * S * I

Seasonal Simple shows the seasonal factors as percentages (S = SF / 100) and replicates them throughout the time scale. The forecast is set equal to the historical value in the actual periods and calculated as T * SF / 100 for forecast periods.

Seasonal Simple has seven methods which use selected combinations of the six independent Seasonal Complex methods.

## Description Seasonal Complex Method

Note

1 Based on the number of actuals: less than two complete years

2 or more, but less than 4 years

4 or more, but less than 6 years

6 or more years

141113

124111

121111

111111

1

2 Multiplicative, typical year, constant trend 141113 1, 2

3 Multiplicative, whole year initial trend, final trend through adjusted

124111 1, 3

4 Multiplicative, average, centered MA, trend through adjusted

121111 1, 4

5 Multiplicative, medial, centered MA, trend through adjusted 111111 1, 5

6 As method 1, but force constant trend 1xx113 1, 6

7 As method 1, but force linear trend 1xx111 1, 7

Note:

1. To choose the best Seasonal Simple method you must understand something of the Seasonal Complex methods, which are described above.

2. You can use this instead of method 1, even though you have more than 2 years of history.

3. You can use this instead of method 1, even though you have more than 4 years of history.

4. You can use this instead of method 1, even if you have 6 or more years of actuals.

5. You can use this instead of method 1, even if you have less than 6 years of actuals.

Page 134: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 134

6. Use this method if you believe your data is most likely to stay constant, even though you have enough actuals to get a good estimate of the slope.

7. Use this method to use a linear trend, even though you have less than two years history.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Method Input Table 1 Double METHOD Method in which the function works.

ActFlag Input Table 1 Double FLAG Actual periods that are used to calculate the seasonal factors.

Note: this parameter is not supported in SAP HANA 1.0 SP3.

Original Input Table 1 Double ORIGINAL Data to be seasonally adjusted.

Period Number

Input Table 1 Double PERIODNUMBER

Length of step for moving average.

Forecast Period

Input Table 1 Double PERIODFORECAST

Number of periods to be forecasted.

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double FORECAST Forecast result table

Example

---Table Preparation

DROP TABLE METHOD_TAB ;

CREATE COLUMN TABLE METHOD_TAB ( "METHOD" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (141111) ;

DROP TABLE ACTFLAG_TAB ;

CREATE COLUMN TABLE ACTFLAG_TAB ( "FLAG" DOUBLE ) ;

INSERT INTO ACTFLAG_TAB VALUES (0) ;

DROP TABLE ORIGINAL_TAB ;

CREATE COLUMN TABLE ORIGINAL_TAB ( "ORIGINAL" DOUBLE ) ;

INSERT INTO ORIGINAL_TAB VALUES (150) ;

INSERT INTO ORIGINAL_TAB VALUES (108) ;

Page 135: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 135

INSERT INTO ORIGINAL_TAB VALUES (112) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (119) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (115) ;

INSERT INTO ORIGINAL_TAB VALUES (134) ;

INSERT INTO ORIGINAL_TAB VALUES (139) ;

INSERT INTO ORIGINAL_TAB VALUES (143) ;

INSERT INTO ORIGINAL_TAB VALUES (240) ;

INSERT INTO ORIGINAL_TAB VALUES (220) ;

INSERT INTO ORIGINAL_TAB VALUES (155) ;

INSERT INTO ORIGINAL_TAB VALUES (162) ;

INSERT INTO ORIGINAL_TAB VALUES (166) ;

INSERT INTO ORIGINAL_TAB VALUES (172) ;

INSERT INTO ORIGINAL_TAB VALUES (170) ;

INSERT INTO ORIGINAL_TAB VALUES (171) ;

INSERT INTO ORIGINAL_TAB VALUES (169) ;

INSERT INTO ORIGINAL_TAB VALUES (188) ;

INSERT INTO ORIGINAL_TAB VALUES (195) ;

INSERT INTO ORIGINAL_TAB VALUES (198) ;

INSERT INTO ORIGINAL_TAB VALUES (320) ;

INSERT INTO ORIGINAL_TAB VALUES (300) ;

INSERT INTO ORIGINAL_TAB VALUES (220) ;

INSERT INTO ORIGINAL_TAB VALUES (222) ;

DROP TABLE PERIODNUMBER_TAB ;

CREATE COLUMN TABLE PERIODNUMBER_TAB("PERIODNUMBER" DOUBLE);

INSERT INTO PERIODNUMBER_TAB VALUES (12) ;

DROP TABLE FORECATPERIOD_TAB ;

CREATE COLUMN TABLE FORECATPERIOD_TAB("PERIODFORECAST" DOUBLE);

INSERT INTO FORECATPERIOD_TAB VALUES (1);

DROP TABLE FORECAST_TAB ;

CREATE COLUMN TABLE FORECAST_TAB ("FORECAST" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_SEASONALSIMPLE_PROC(METHOD_TAB,ACTFLAG_TAB,ORIGINAL_TAB, PERIODNUMBER_TAB,FORECATPERIOD_TAB, FORECAST_TAB) WITH OVERVIEW;

SELECT * FROM FORECAST_TAB;

Page 136: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 136

3.44 Seasonal Simulation

This built-in function is used to test and explore how Seasonal Complex and other Business Functions handle the input data. It provides the building blocks to Seasonal Simulation seasonal data using a variety of characteristics.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Method Input Table 1 Double METHOD Period(0)

Repeat(1)

Seasonal(2)

BoxMuller(3)

Random(4)

Normal(5)

Uniform(6)

Repeated(7)

Periods Input Table 1 Double PERIODS Specify the period number

Param Input Table 1 Double PARAM Varies with the method data entered across the periods of the timescale as described below

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double RESULT Seasonal simulation for time series

Page 137: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 137

Example

DROP TABLE METHOD_TAB;

CREATE COLUMN TABLE METHOD_TAB ( "METHOD" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (6) ;

DROP TABLE PERIODS_TAB;

CREATE COLUMN TABLE PERIODS_TAB ( "PERIODS" DOUBLE ) ;

INSERT INTO PERIODS_TAB VALUES (5) ;

INSERT INTO PERIODS_TAB VALUES (5) ;

DROP TABLE PARAM_TAB;

CREATE COLUMN TABLE PARAM_TAB ( "PARAM" DOUBLE ) ;

INSERT INTO PARAM_TAB VALUES (5.0) ;

INSERT INTO PARAM_TAB VALUES (6.0) ;

INSERT INTO PARAM_TAB VALUES (12.0) ;

DROP TABLE RESULT_TAB;

CREATE TABLE RESULT_TAB ( "RESULT" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_SEASONALSIMULATION_PROC(METHOD_TAB, PERIODS_TAB, PARAM_TAB,RESULT_TAB) WITH OVERVIEW;

SELECT * FROM RESULT_TAB;

Page 138: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 138

3.45 Stock Flow

The Stock Flow works out the level of supply needed to meet target forecasts for stock cover.

Supply Outlook = Stock Flow(Prime;{Opening Stock};{Forecast Sales};{Forecast Cover};{Closing Stock};{Actual Sales};{Actual Cover};{Actual Supply};{Actual Closing};19980301;1;{Period Length};{Max Supply};{Min Supply};{% Wastage}; Wastage;0;1;1;{Sales Outlook}) The supply is calculated to meet the Closing Stock target.

Outlook method

Outlook Method determines how Sales Outlook is calculated.

Both Outlook methods try to set Sales Outlook to equal Actual Sales for historical periods and Forecast Sales for future periods. The Year over Year Difference is the default Outlook Method, which allows for the Closing Stock to go negative in certain cases, identifying stock shortfalls. Parameters also prevent Closing Stock from dropping below zero, i.e. restrict future sales by setting the Outlook Method parameter to Restrict.

End Method

The demand in the last period is replicated by default, the last period sales are replicated to provide for future periods. Period lengths are replicated in a similar manner.

Alternatively, End Method can calculate an average demand over the last n periods and replicate this average over the future periods.

Min and Max Supply

The maximum supply can be restricted due to production constraints, warehouse capacity, existing contracts...etc. Minimum supply can be restricted where stock can only be depleted at the rate of sales. For example, in June there is an actual stock cover of over 80 days but only a planned cover of 30 days for July. Even with zero incoming supply, sales in June will not reduce stock levels to the planned levels. This then requires disposal (or donation) of stock to bring the stock levels down quickly. The closing stock levels and actual stock cover are adjusted accordingly.

Wastage

Wastage for each period to cover a variety of non-sales related stock reduction, such as shrinkage, spoilage, etc.

Cover Units and Period Length

Using calendar days, Cover Units Forecast Cover is measured in stock-turn days. This is based on the Sales Outlook.

Rounding Method

For most situations, there should be no rounding of discrete units and this is set as the default. The rounding method can be used to round each element or to round each time total (preserve sum and preserve sum YoY ). Using the preserve sum methods, the elements are rounded in such a way that they continue to add up to the time total.

Page 139: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 139

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double PRIME Prime - opening stock of the first period.

Time Input Table 1 String TIME The calculated time.

Forecast Sales

Input Table 1 Double FORECASTSALES

Forecast sales will be used in the period containing the switchover date and there after. Prior to the switchover date there is no forecast, only actuals.

Forecast Cover

Input Table 1 Double FORECASTCOVER

The forecast stock cover. How many days/periods of future sales the closing stock should support. 100 means to set Closing Stock at such a level that it lasts 100 days based on Sales Outlook.

Actual Sales

Input Table 1 Double ACTUALSALES

Actual sales input for historic periods only.

Actual Supply

Input Table 1 Double ACTUALSUPPLY

Actual supply input for historic periods only.

Actual Closing

Input Table 1 Double ACTUALCLOSING

Actual closing stock input for historic periods only.

Switchover Input Table 1 Int SWITCHOVER

The period containing the switchover date is defined as the first future period.

Switchover Date

Input Table 1 String SWITCHOVERDATE

Specify the switchover date base on Switchover

Cover Units

Input Table 1 Int COVERUNITS Identifies the measure for Stock Cover in terms of future sales.

Days: Use calendar days. Default.

Units: Use custom units from the item Period Length

Periods: Use number of periods. Each detail item in the timescale field is a period.

Page 140: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 140

Name Direction Number of Columns

Column Type

Column Name

Description

Period Length

Input Table 1 Int PERIODLENGTH

Available if you want to use non-standard calendar period lengths. For example: 4 - 4 - 5 for weeks in each period. Period Length will be ignored unless you set Cover Units=Period.

Max Supply

Input Table 1 Double MAXSUPPLY Physical limitations (constraints) to the maximum supply available to increase stock levels (warehouse space, etc). If left blank, the default is for Max Supply to be allowed to go to infinity.

Min Supply Input Table 1 Double MINSUPPLY Limitation to the flow out of stock.

Wastage Rate

Input Table 1 Double WASTAGERATE

Changes in stock due to shrinkage (not explained by sales and supply). Wastage is = to % Wastage applied to the Opening Stock.

Rounding Method

Input Table 1 Int ROUNDMETHOD

DNR: Do not round. This is the default if left blank (no partial units…discrete).

Round: Round each element (process).

Preserve Sum: Preserve the sum by changing the most obvious element(s)….where rounded value is furthest from original value.

Preserve Sum YoY: Preserve the sum by rounding cumulated data and then taking the Year over Year Difference (the default).

Page 141: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 141

Name Direction Number of Columns

Column Type

Column Name

Description

End Method

Input Table 1 Int ENDMETHOD Integer Constant: The number of periods over which to average sales when projecting beyond the last period in the timescale. This is used in the closing stock calculation toward the end of the timescale.

N periods: Use the average of the last 3 periods to project sales forward.

Outlook Method

Input Table 1 Int OUTLOOKMETHOD

How Forecast Sales input is used to provide future Sales Outlook.

Default: Use Forecast Sales from the period containing the switchover date onwards, Actual Sales prior to this (the default method).

Restrict: Restrict future sales if closing stock goes negative.

Page 142: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 142

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 6 Double OPENING Opening Stock. Fed from the Closing Stock of the previous period.

Double CLOSING Closing Stock. Actual Closing Stock prior to the switchover date; the level required to meet the Forecast Stock Cover thereafter.

Double ACTUALCOVER

Actual Stock Cover. How many days/periods of future sales the Closing Stock actually does support.

Double WASTAGE Changes in stock due to shrinkage (not explained by sales and supply). Wastage is = to % Wastage applied to the Opening Stock.

Double SALESOUTLOOK

Sales Outlook is equal to the Actual Sales history prior to the switchover date, Forecast Sales thereafter. See Outlook Method.

Double SUPPLYOUTLOOK

The supply in future periods required to meet forecast stock cover based on forecast sales. The supply is subject to the constraints of Min and Max Supply. Prior to the switchover date, Supply Outlook equals Actual Supply.

Page 143: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 143

Example

DROP TABLE PRIME_TAB;

CREATE TABLE PRIME_TAB ("PRIME" DOUBLE);

INSERT INTO PRIME_TAB VALUES(10000);

DROP TABLE TIME_TAB;

CREATE TABLE TIME_TAB ("TIME" VARCHAR(255));

INSERT INTO TIME_TAB VALUES('20100801');

INSERT INTO TIME_TAB VALUES('20100912');

INSERT INTO TIME_TAB VALUES('20101020');

INSERT INTO TIME_TAB VALUES('20101130');

INSERT INTO TIME_TAB VALUES('20110105');

INSERT INTO TIME_TAB VALUES('20110220');

DROP TABLE FORECASTSALES_TAB;

CREATE TABLE FORECASTSALES_TAB ("FORECASTSALES" DOUBLE);

INSERT INTO FORECASTSALES_TAB VALUES(0);

INSERT INTO FORECASTSALES_TAB VALUES(0);

INSERT INTO FORECASTSALES_TAB VALUES(2500);

INSERT INTO FORECASTSALES_TAB VALUES(3000);

INSERT INTO FORECASTSALES_TAB VALUES(2500);

INSERT INTO FORECASTSALES_TAB VALUES(3500);

DROP TABLE FORECASTCOVER_TAB;

CREATE TABLE FORECASTCOVER_TAB ("FORECASTCOVER" DOUBLE);

INSERT INTO FORECASTCOVER_TAB VALUES(0);

INSERT INTO FORECASTCOVER_TAB VALUES(0);

INSERT INTO FORECASTCOVER_TAB VALUES(100);

INSERT INTO FORECASTCOVER_TAB VALUES(70);

INSERT INTO FORECASTCOVER_TAB VALUES(75);

INSERT INTO FORECASTCOVER_TAB VALUES(50);

DROP TABLE ACTUALSALES_TAB;

CREATE TABLE ACTUALSALES_TAB ("ACTUALSALES" DOUBLE);

INSERT INTO ACTUALSALES_TAB VALUES(1500);

INSERT INTO ACTUALSALES_TAB VALUES(2000);

DROP TABLE ACTUALSUPPLY_TAB;

CREATE TABLE ACTUALSUPPLY_TAB ("ACTUALSUPPLY" DOUBLE);

INSERT INTO ACTUALSUPPLY_TAB VALUES(2000);

INSERT INTO ACTUALSUPPLY_TAB VALUES(2500);

DROP TABLE ACTUALCLOSING_TAB;

CREATE TABLE ACTUALCLOSING_TAB ("ACTUALCLOSING" DOUBLE);

INSERT INTO ACTUALCLOSING_TAB VALUES(10000);

INSERT INTO ACTUALCLOSING_TAB VALUES(10000);

DROP TABLE SWITCHOVER_TAB;

CREATE TABLE SWITCHOVER_TAB ("SWITCHOVER" INTEGER);

Page 144: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 144

INSERT INTO SWITCHOVER_TAB VALUES(1);

DROP TABLE SWITCHOVERDATE_TAB;

CREATE TABLE SWITCHOVERDATE_TAB ("SWITCHOVERDATE" VARCHAR(255));

INSERT INTO SWITCHOVERDATE_TAB VALUES('20101001');

DROP TABLE COVERUNITS_TAB;

CREATE TABLE COVERUNITS_TAB ("COVERUNITS" INTEGER);

INSERT INTO COVERUNITS_TAB VALUES(0);

DROP TABLE PERIODLENGTH_TAB;

CREATE TABLE PERIODLENGTH_TAB ("PERIODLENGTH" INTEGER);

INSERT INTO PERIODLENGTH_TAB VALUES(0);

DROP TABLE MAXSUPPLY_TAB;

CREATE TABLE MAXSUPPLY_TAB ("MAXSUPPLY" DOUBLE);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

DROP TABLE MINSUPPLY_TAB;

CREATE TABLE MINSUPPLY_TAB ("MINSUPPLY" DOUBLE);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

DROP TABLE WASTAGERATE_TAB;

CREATE TABLE WASTAGERATE_TAB ("WASTAGERATE" DOUBLE);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

DROP TABLE ROUNDMETHOD_TAB;

CREATE TABLE ROUNDMETHOD_TAB ("ROUNDMETHOD" INTEGER);

INSERT INTO ROUNDMETHOD_TAB VALUES(0);

DROP TABLE ENDMETHOD_TAB;

CREATE TABLE ENDMETHOD_TAB ("ENDMETHOD" INTEGER);

INSERT INTO ENDMETHOD_TAB VALUES(2);

DROP TABLE OUTLOOKMETHOD_TAB;

CREATE TABLE OUTLOOKMETHOD_TAB ("OUTLOOKMETHOD" INTEGER);

INSERT INTO OUTLOOKMETHOD_TAB VALUES(0);

Page 145: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 145

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ("OPENING" DOUBLE,"CLOSING" DOUBLE,"ACTUALCOVER" DOUBLE,"WASTAGE" DOUBLE,"SALESOUTLOOK" DOUBLE,"SUPPLYOUTLOOK" DOUBLE);

CALL _SYS_AFL.AFLBFL_STOCKFLOW_PROC(PRIME_TAB, TIME_TAB, FORECASTSALES_TAB, FORECASTCOVER_TAB,ACTUALSALES_TAB,ACTUALSUPPLY_TAB,ACTUALCLOSING_TAB,SWITCHOVER_TAB,SWITCHOVERDATE_TAB,COVERUNITS_TAB,PERIODLENGTH_TAB , MAXSUPPLY_TAB,MINSUPPLY_TAB,WASTAGERATE_TAB,ROUNDMETHOD_TAB,ENDMETHOD_TAB,OUTLOOKMETHOD_TAB,RESULTS_TAB ) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 146: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 146

3.46 Stock Flow Reverse

This function is based on the standard Stock Flow Business Function. In Stock Flow, the switchover date applies to the entire timescale, but in Stock Flow Reverse, an actual/forecast flag acts as a Year over Year Difference switchover date. This allows stock flow simulation for Year over Year Difference scenarios where the switchover date may vary due to departure from standard calendars and periods (projects).

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double PRIME Prime - opening stock of the first period.

Time Input Table 1 String TIME The calculated time.

Forecast Sales

Input Table 1 Double FORECASTSALES

Forecast sales will be used in the period containing the switchover date and thereafter. Prior to the switchover date there is no forecast, only actual.

Forecast Cover

Input Table 1 Double FORECASTCOVER

The forecast stock cover. How many days/periods of future sales the closing stock should support. 100 sets Closing Stock at such a level that it lasts 100 days based on Sales Outlook.

Actual Sales

Input Table 1 Double ACTUALSALES

Actual Sales input for historic periods only.

Actual Supply

Input Table 1 Double ACTUALSUPPLY

Actual Supply input for historic periods only.

Actual Closing

Input Table 1 Double ACTUALCLOSING

Actual Closing Stock input for historic periods only.

Forecast Flag

Input Table 1 Int FORECASTFLAG

Enter a flag to set a Year over Year Difference switchover date on each page. The first value > 1 indicates the start of forecast periods.

Page 147: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 147

Name Direction Number of Columns

Column Type

Column Name

Description

Cover Units

Input Table 1 Int COVERUNITS Identifies the measure for Stock Cover in terms of future sales.

Days: Use calendar days. Default.

Units: Use custom units from the item Period Length.

Periods: Use number of periods. Each detail item in the timescale field is a period.

Period Length

Input Table 1 Int PERIODLENGTH

Available if you want to use non-standard calendar period lengths. For example: 4 - 4 - 5 for weeks in each period. Period Length will be ignored unless you set Cover Units=Period.

Max Supply

Input Table 1 Double MAXSUPPLY Physical limitations (constraints) to the maximum supply available to increase stock levels (warehouse space, etc). If left blank, the default is for Max Supply to be allowed to go to infinity.

Min Supply Input Table 1 Double MINSUPPLY Limitation to the flow out of stock.

Wastage Rate

Input Table 1 Double WASTAGERATE

Changes in stock due to shrinkage (not explained by sales and supply). Wastage is = to % Wastage applied to the Opening Stock.

Page 148: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 148

Name Direction Number of Columns

Column Type

Column Name

Description

Rounding Method

Input Table 1 Int ROUNDMETHOD

DNR: Do not round. This is the default if left blank (no partial units, that is discrete only).

Round: Round each element (process).

Preserve Sum: Preserve the sum by changing the most obvious element(s), where rounded value is furthest from original value.

Preserve Sum YoY: Preserve the sum by rounding cumulated data and then taking the Year over Year Difference (the default).

End Method

Input Table 1 Int ENDMETHOD Integer Constant: The number of periods over which to average sales when projecting beyond the last period in the timescale. This is used in the Closing Stock calculation toward the end of the timescale.

N periods: Use the average of the last 3 periods to project sales forward.

Outlook Method

Input Table 1 Int OUTLOOKMETHOD

How forecast sales input is used to provide future sales outlook.

Default: Use Forecast Sales from the period containing the switchover date onwards, Actual Sales prior to this (the default method).

Restrict: Restrict future sales if closing stock goes negative.

Page 149: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 149

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 6 Double OPENING Opening Stock. Fed from the Closing Stock of the previous period.

Double CLOSING Closing Stock. Actual Closing Stock prior to the switchover date; the level required to meet the Forecast Stock Cover thereafter.

Double ACTUALCOVER

Actual Stock Cover. How many days/periods of future sales the Closing Stock actually does support.

Double WASTAGE Changes in stock due to shrinkage (not explained by sales and supply). Wastage is = to % Wastage applied to the Opening Stock.

Double SALESOUTLOOK

Sales Outlook is equal to the Actual Sales history prior to the switchover date, Forecast Sales thereafter. See Outlook Method.

Double SUPPLYOUTLOOK

The supply in future periods required to meet forecast stock cover based on forecast sales. The supply is subject to the constraints of Min and Max Supply. Prior to the switchover date, Supply Outlook equals Actual Supply.

Page 150: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 150

Example

DROP TABLE PRIME_TAB;

CREATE TABLE PRIME_TAB ("PRIME" DOUBLE);

INSERT INTO PRIME_TAB VALUES(10000);

DROP TABLE TIME_TAB;

CREATE TABLE TIME_TAB ("TIME" VARCHAR(255));

INSERT INTO TIME_TAB VALUES('20100801');

INSERT INTO TIME_TAB VALUES('20100912');

INSERT INTO TIME_TAB VALUES('20101020');

INSERT INTO TIME_TAB VALUES('20101130');

INSERT INTO TIME_TAB VALUES('20110105');

INSERT INTO TIME_TAB VALUES('20110220');

DROP TABLE FORECASTSALES_TAB;

CREATE TABLE FORECASTSALES_TAB ("FORECASTSALES" DOUBLE);

INSERT INTO FORECASTSALES_TAB VALUES(0);

INSERT INTO FORECASTSALES_TAB VALUES(0);

INSERT INTO FORECASTSALES_TAB VALUES(2500);

INSERT INTO FORECASTSALES_TAB VALUES(3000);

INSERT INTO FORECASTSALES_TAB VALUES(2500);

INSERT INTO FORECASTSALES_TAB VALUES(3500);

DROP TABLE FORECASTCOVER_TAB;

CREATE TABLE FORECASTCOVER_TAB ("FORECASTCOVER" DOUBLE);

INSERT INTO FORECASTCOVER_TAB VALUES(0);

INSERT INTO FORECASTCOVER_TAB VALUES(0);

INSERT INTO FORECASTCOVER_TAB VALUES(100);

INSERT INTO FORECASTCOVER_TAB VALUES(70);

INSERT INTO FORECASTCOVER_TAB VALUES(75);

INSERT INTO FORECASTCOVER_TAB VALUES(50);

DROP TABLE ACTUALSALES_TAB;

CREATE TABLE ACTUALSALES_TAB ("ACTUALSALES" DOUBLE);

INSERT INTO ACTUALSALES_TAB VALUES(1500);

INSERT INTO ACTUALSALES_TAB VALUES(2000);

DROP TABLE ACTUALSUPPLY_TAB;

CREATE TABLE ACTUALSUPPLY_TAB ("ACTUALSUPPLY" DOUBLE);

INSERT INTO ACTUALSUPPLY_TAB VALUES(2000);

INSERT INTO ACTUALSUPPLY_TAB VALUES(2500);

DROP TABLE ACTUALCLOSING_TAB;

CREATE TABLE ACTUALCLOSING_TAB ("ACTUALCLOSING" DOUBLE);

INSERT INTO ACTUALCLOSING_TAB VALUES(10000);

INSERT INTO ACTUALCLOSING_TAB VALUES(10000);

DROP TABLE FORECASTFLAG_TAB;

CREATE TABLE FORECASTFLAG_TAB ("FORECASTFLAG" INTEGER);

Page 151: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 151

INSERT INTO FORECASTFLAG_TAB VALUES(0);

INSERT INTO FORECASTFLAG_TAB VALUES(0);

INSERT INTO FORECASTFLAG_TAB VALUES(2);

DROP TABLE COVERUNITS_TAB;

CREATE TABLE COVERUNITS_TAB ("COVERUNITS" INTEGER);

INSERT INTO COVERUNITS_TAB VALUES(0);

DROP TABLE PERIODLENGTH_TAB;

CREATE TABLE PERIODLENGTH_TAB ("PERIODLENGTH" INTEGER);

INSERT INTO PERIODLENGTH_TAB VALUES(0);

DROP TABLE MAXSUPPLY_TAB;

CREATE TABLE MAXSUPPLY_TAB ("MAXSUPPLY" DOUBLE);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

DROP TABLE MINSUPPLY_TAB;

CREATE TABLE MINSUPPLY_TAB ("MINSUPPLY" DOUBLE);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

DROP TABLE WASTAGERATE_TAB;

CREATE TABLE WASTAGERATE_TAB ("WASTAGERATE" DOUBLE);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

DROP TABLE ROUNDMETHOD_TAB;

CREATE TABLE ROUNDMETHOD_TAB ("ROUNDMETHOD" INTEGER);

INSERT INTO ROUNDMETHOD_TAB VALUES(0);

DROP TABLE ENDMETHOD_TAB;

CREATE TABLE ENDMETHOD_TAB ("ENDMETHOD" INTEGER);

INSERT INTO ENDMETHOD_TAB VALUES(2);

DROP TABLE OUTLOOKMETHOD_TAB;

CREATE TABLE OUTLOOKMETHOD_TAB ("OUTLOOKMETHOD" INTEGER);

INSERT INTO OUTLOOKMETHOD_TAB VALUES(0);

DROP TABLE RESULTS_TAB;

Page 152: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 152

CREATE TABLE RESULTS_TAB ("OPENING" DOUBLE,"CLOSING" DOUBLE,"ACTUALCOVER" DOUBLE,"WASTAGE" DOUBLE,"SALESOUTLOOK" DOUBLE,"SUPPLYOUTLOOK" DOUBLE);

CALL _SYS_AFL.AFLBFL_STOCKFLOWREVERSE_PROC(PRIME_TAB, TIME_TAB, FORECASTSALES_TAB, FORECASTCOVER_TAB,ACTUALSALES_TAB,ACTUALSUPPLY_TAB,ACTUALCLOSING_TAB,FORECASTFLAG_TAB,COVERUNITS_TAB,PERIODLENGTH_TAB , MAXSUPPLY_TAB,MINSUPPLY_TAB,WASTAGERATE_TAB,ROUNDMETHOD_TAB,ENDMETHOD_TAB,OUTLOOKMETHOD_TAB,RESULTS_TAB ) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 153: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 153

3.47 Stock Flow Batch

This built-in function lets you use batch quantities in stock flow calculations.

Supply Outlook=Stock Flow Reverse(Prime; Opening Stock; Forecast Sales; Forecast Cover; Closing Stock; Actual Sales; Actual Cover; Actual Supply; Actual Closing; Forecast flag; Cover Units; Period Length; Max Supply; Min Supply; Batch Quantity; Minimum Method; % Wastage; Wastage; Rounding Method; End Method; Outlook Method; Sales Outlook) Methods

See the Stock Flow function for complete information on methods.

Batch Quantity

When {Batch Quantity} is non-zero, the {Supply Outlook} will be rounded up to the next integer multiple of {Batch Quantity}. Stock Flow Reverse has more information about other inputs and calculations.

Minimum Method

Applies to {Supply Outlook} in forecast periods.

It modifies the effect of {Min Supply}.

Minimum, Maximum and batch size

Stock Flow Batch resolves inconsistent inputs in the following manner:

• If {Min Supply} is positive and {Batch Size} is positive, then round {Min Supply} up to the next integer multiple of {Batch Size}.

• If {Batch Size} is positive and {Max Supply} is positive, then round {Max Supply} down to the next integer multiple of {Batch Size}.

• If {Min Supply} > {Max Supply}, then set {Max Supply} = {Min Supply}.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Prime Input Table 1 Double PRIME Prime - opening stock of the first period.

Time Input Table 1 String TIME The calculated time.

Forecast Sales

Input Table 1 Double FORECASTSALES

Forecast sales will be used in the period containing the switchover date and thereafter. Prior to the switchover date there is no forecast – only actual.

Page 154: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 154

Name Direction Number of Columns

Column Type

Column Name

Description

Forecast Cover

Input Table 1 Double FORECASTCOVER

The forecast stock cover. How many days/periods of future sales the closing stock should support. 100 sets Closing Stock at such a level that it lasts 100 days based on Sales Outlook.

Actual Sales

Input Table 1 Double ACTUALSALES

Actual Sales input for historic periods only.

Actual Supply

Input Table 1 Double ACTUALSUPPLY

Actual Supply input for historic periods only.

Actual Closing

Input Table 1 Double ACTUALCLOSING

Actual Closing Stock input for historic periods only.

Forecast Flag

Input Table 1 Int FORECASTFLAG

Enter a flag to act as a Year over Year Difference switchover date on each page. The first value > 1 indicates the start of forecast periods.

Cover Units

Input Table 1 Int COVERUNITS Identifies the measure for Stock Cover in terms of future sales.

Days: Use calendar days. Default.

Units: Use custom units from the item Period Length.

Periods: Use number of periods. Each detail item in the timescale field is a period.

Period Length

Input Table 1 Int PERIODLENGTH

Available if you want to use non-standard calendar period lengths. For example: 4 - 4 - 5 for weeks in each period. Period Length will be ignored unless you set Cover Units=Period.

Page 155: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 155

Name Direction Number of Columns

Column Type

Column Name

Description

Max Supply

Input Table 1 Double MAXSUPPLY Physical limitations (constraints) to the maximum supply available to increase stock levels (warehouse space, etc). If left blank, the default is for Max Supply to be allowed to go to infinity.

Min Supply Input Table 1 Double MINSUPPLY Limitation to the flow out of stock.

Batch Quantity

Input Table 1 Double BATCHQUANTITY

When {Batch Quantity} is non-zero, the {Supply Outlook} will be rounded up to the next integer multiple of {Batch Quantity}. Stock Flow Reverse has more information about other inputs and calculations.

Wastage Rate

Input Table 1 Double WASTAGERATE

Changes in stock due to shrinkage (not explained by sales and supply). Wastage is = to % Wastage applied to the Opening Stock.

Rounding Method

Input Table 1 Int ROUNDMETHOD

DNR: Do not round. This is the default if left blank (no partial units, discrete units only).

Round: Round each element (process).

Preserve Sum: Preserve the sum by changing the most obvious element(s), where rounded value is furthest from original value.

Preserve Sum YoY: Preserve the sum by rounding cumulated data and then taking the Year over Year Difference (the default).

Page 156: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 156

Name Direction Number of Columns

Column Type

Column Name

Description

End Method

Input Table 1 Int ENDMETHOD Integer Constant: The number of periods over which to average sales when projecting beyond the last period in the timescale. This is used in the closing stock calculation toward the end of the timescale.

N periods: Use the average of the last 3 periods to project sales forward.

Outlook Method

Input Table 1 Int OUTLOOKMETHOD

How forecast sales input is used to provide future sales outlook.

Default: Use Forecast Sales from the period containing the switchover date onwards, Actual Sales prior to this (the default method).

Restrict: Restrict future sales if closing stock goes negative.

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 6 Double OPENING Opening Stock. Fed from the Closing Stock of the previous period.

Double CLOSING Closing Stock. Actual Closing Stock prior to the switchover date; the level required to meet the Forecast Stock Cover thereafter.

Double ACTUALCOVER

Actual Stock Cover. How many days/periods of future sales the Closing Stock actually does support.

Page 157: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 157

Name Direction Number of Columns

Column Type

Column Name Description

Double WASTAGE Changes in stock due to shrinkage (not explained by sales and supply). Wastage is = to % Wastage applied to the Opening Stock.

Double SALESOUTLOOK

Sales Outlook is equal to the Actual Sales history prior to the switchover date, Forecast Sales thereafter. See Outlook Method.

Double SUPPLYOUTLOOK

The supply in future periods required to meet forecast stock cover based on forecast sales. The supply is subject to the constraints of Min and Max Supply. Prior to the switchover date, Supply Outlook equals Actual Supply.

Example

DROP TABLE PRIME_TAB;

CREATE TABLE PRIME_TAB ("PRIME" DOUBLE);

INSERT INTO PRIME_TAB VALUES(10000);

DROP TABLE TIME_TAB;

CREATE TABLE TIME_TAB ("TIME" VARCHAR(255));

INSERT INTO TIME_TAB VALUES('20100801');

INSERT INTO TIME_TAB VALUES('20100912');

INSERT INTO TIME_TAB VALUES('20101020');

INSERT INTO TIME_TAB VALUES('20101130');

INSERT INTO TIME_TAB VALUES('20110105');

INSERT INTO TIME_TAB VALUES('20110220');

DROP TABLE FORECASTSALES_TAB;

CREATE TABLE FORECASTSALES_TAB ("FORECASTSALES" DOUBLE);

INSERT INTO FORECASTSALES_TAB VALUES(0);

INSERT INTO FORECASTSALES_TAB VALUES(0);

INSERT INTO FORECASTSALES_TAB VALUES(2500);

INSERT INTO FORECASTSALES_TAB VALUES(3000);

INSERT INTO FORECASTSALES_TAB VALUES(2500);

INSERT INTO FORECASTSALES_TAB VALUES(3500);

Page 158: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 158

DROP TABLE FORECASTCOVER_TAB;

CREATE TABLE FORECASTCOVER_TAB ("FORECASTCOVER" DOUBLE);

INSERT INTO FORECASTCOVER_TAB VALUES(0);

INSERT INTO FORECASTCOVER_TAB VALUES(0);

INSERT INTO FORECASTCOVER_TAB VALUES(100);

INSERT INTO FORECASTCOVER_TAB VALUES(70);

INSERT INTO FORECASTCOVER_TAB VALUES(75);

INSERT INTO FORECASTCOVER_TAB VALUES(50);

DROP TABLE ACTUALSALES_TAB;

CREATE TABLE ACTUALSALES_TAB ("ACTUALSALES" DOUBLE);

INSERT INTO ACTUALSALES_TAB VALUES(1500);

INSERT INTO ACTUALSALES_TAB VALUES(2000);

DROP TABLE ACTUALSUPPLY_TAB;

CREATE TABLE ACTUALSUPPLY_TAB ("ACTUALSUPPLY" DOUBLE);

INSERT INTO ACTUALSUPPLY_TAB VALUES(2000);

INSERT INTO ACTUALSUPPLY_TAB VALUES(2500);

DROP TABLE ACTUALCLOSING_TAB;

CREATE TABLE ACTUALCLOSING_TAB ("ACTUALCLOSING" DOUBLE);

INSERT INTO ACTUALCLOSING_TAB VALUES(10000);

INSERT INTO ACTUALCLOSING_TAB VALUES(10000);

DROP TABLE FORECASTFLAG_TAB;

CREATE TABLE FORECASTFLAG_TAB ("FORECASTFLAG" INTEGER);

INSERT INTO FORECASTFLAG_TAB VALUES(0);

INSERT INTO FORECASTFLAG_TAB VALUES(0);

INSERT INTO FORECASTFLAG_TAB VALUES(2);

DROP TABLE COVERUNITS_TAB;

CREATE TABLE COVERUNITS_TAB ("COVERUNITS" INTEGER);

INSERT INTO COVERUNITS_TAB VALUES(0);

DROP TABLE PERIODLENGTH_TAB;

CREATE TABLE PERIODLENGTH_TAB ("PERIODLENGTH" INTEGER);

INSERT INTO PERIODLENGTH_TAB VALUES(0);

DROP TABLE MAXSUPPLY_TAB;

CREATE TABLE MAXSUPPLY_TAB ("MAXSUPPLY" DOUBLE);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

INSERT INTO MAXSUPPLY_TAB VALUES(0);

DROP TABLE MINSUPPLY_TAB;

CREATE TABLE MINSUPPLY_TAB ("MINSUPPLY" DOUBLE);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

Page 159: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 159

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

INSERT INTO MINSUPPLY_TAB VALUES(0);

DROP TABLE BATCHQUANTITY_TAB;

CREATE TABLE BATCHQUANTITY_TAB("BATCHQUANTITY" DOUBLE);

INSERT INTO BATCHQUANTITY_TAB VALUES(0);

INSERT INTO BATCHQUANTITY_TAB VALUES(0);

INSERT INTO BATCHQUANTITY_TAB VALUES(0);

INSERT INTO BATCHQUANTITY_TAB VALUES(0);

INSERT INTO BATCHQUANTITY_TAB VALUES(0);

INSERT INTO BATCHQUANTITY_TAB VALUES(0);

DROP TABLE WASTAGERATE_TAB;

CREATE TABLE WASTAGERATE_TAB ("WASTAGERATE" DOUBLE);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

INSERT INTO WASTAGERATE_TAB VALUES(5);

DROP TABLE ROUNDMETHOD_TAB;

CREATE TABLE ROUNDMETHOD_TAB ("ROUNDMETHOD" INTEGER);

INSERT INTO ROUNDMETHOD_TAB VALUES(0);

DROP TABLE ENDMETHOD_TAB;

CREATE TABLE ENDMETHOD_TAB ("ENDMETHOD" INTEGER);

INSERT INTO ENDMETHOD_TAB VALUES(2);

DROP TABLE OUTLOOKMETHOD_TAB;

CREATE TABLE OUTLOOKMETHOD_TAB ("OUTLOOKMETHOD" INTEGER);

INSERT INTO OUTLOOKMETHOD_TAB VALUES(0);

DROP TABLE RESULTS_TAB;

CREATE TABLE RESULTS_TAB ("OPENING" DOUBLE,"CLOSING" DOUBLE,"ACTUALCOVER" DOUBLE,"WASTAGE" DOUBLE,"SALESOUTLOOK" DOUBLE,"SUPPLYOUTLOOK" DOUBLE);

CALL _SYS_AFL.AFLBFL_STOCKFLOWBATCH_PROC(PRIME_TAB, TIME_TAB, FORECASTSALES_TAB, FORECASTCOVER_TAB,ACTUALSALES_TAB,ACTUALSUPPLY_TAB,ACTUALCLOSING_TAB,FORECASTFLAG_TAB,COVERUNITS_TAB,PERIODLENGTH_TAB , MAXSUPPLY_TAB,MINSUPPLY_TAB,BATCHQUANTITY_TAB,WASTAGERATE_TAB,ROUNDMETHOD_TAB,ENDMETHOD_TAB,OUTLOOKMETHOD_TAB,RESULTS_TAB ) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 160: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 160

3.48 Time

This function returns the information requested by the option you have input. It is one of the most time consuming elements in FPM or simulation because of the relevance of specific periods. Scripting of time, particularly in excel driven formats (such as BPC) can be extremely costly and extremely difficult to maintain. If any modeling requires modification of the time series, the condition becomes worse.

For a standard timescale, the start of a period is at midnight on the first day. The middle of a period may be at noon or midnight depending on how many days there are in the period. The end of a period is midnight on the last day, which is formatted as midnight at the start of the next day.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Time Scale Input Table 1 Double TIMESCALE Input amount

Start Date Input Table 1 Double STARTDATE The date start to calculate

Switchover Input Table 1 Double SWITCHOVER

Switchover date

Time information

Input Table 1 Double TIMEINFORMATION

The option you require for time information. Detail information shown below:

Now(0)

Last(1)

Start(2)

Mid(3)

End(4)

Days(5)

IID(6)

Current(7)

Switchover(8)

Actual(9):

Cycle(10):

Period(11):

First(12):

Last(13):

Actual(14):

Min(15):

Method(16)

Page 161: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 161

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 String TIME Returns time-related information

Specification of method:

Now(0): Current system date and time

Last(1): Last Save

Start(2): the date and time at the start of this period

Mid(3): the date and time at the middle of this period

End(4): the date and time at the end of this period

Days(5): the number of days in this period

IID(6)

Current(7): Sets a flag = 1 in the period containing system date

Switchover(8): Sets a flag =1 in the period containing switchover date

Actual(9): Sets a flag =1 in periods up to, but not including, the period containing the system date (current)

Cycle(10): The number of periods like this in a year to the nearest whole number (minimum 1)

Period(11): Period: Numbers the periods within a year, starting again at 1 each year and counting up until it reaches the total number of periods in the year (as defined in ‘cycle’)

First(12): Sets a flag =1 in the first period of every timescale subtotal

Last(13): Sets a flag =1 in the last period of every timescale subtotal

Actual(14): Sets a flag =1 in periods up to, but not including, the period containing the switchover date

Min(15): Returns the date and time 1 minute before midnight on last day of period

Method(16): Returns the middle of each period in year units, where 2003.5 means the middle of 2003. It is used by Cycles as its measure of time

Page 162: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 162

Example

DROP TABLE TIMESCALE_TAB;

CREATE COLUMN TABLE TIMESCALE_TAB ( "TIMESCALE" DOUBLE ) ;

INSERT INTO TIMESCALE_TAB VALUES (0) ;

DROP TABLE STARTDATE_TAB;

CREATE COLUMN TABLE STARTDATE_TAB ( "STARTDATE" DOUBLE ) ;

INSERT INTO STARTDATE_TAB VALUES ('20040228') ;

DROP TABLE SWITCHOVER_TAB;

CREATE COLUMN TABLE SWITCHOVER_TAB ( "SWITCHOVER" DOUBLE ) ;

INSERT INTO SWITCHOVER_TAB VALUES ('20040307') ;

DROP TABLE TIMEINFORMATION_TAB;

CREATE COLUMN TABLE TIMEINFORMATION_TAB ( "TIMEINFORMATION" DOUBLE ) ;

INSERT INTO TIMEINFORMATION_TAB VALUES (4) ;

DROP TABLE TIME_TAB;

CREATE TABLE TIME_TAB ( "TIME" VARCHAR(255)) ;

CALL _SYS_AFL.AFLBFL_TIME_PROC(TIMESCALE_TAB, STARTDATE_TAB, SWITCHOVER_TAB, TIMEINFORMATION_TAB,TIME_TAB) WITH OVERVIEW;

SELECT * FROM TIME_TAB;

Page 163: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 163

3.49 Time Sum

This function needs to use the generator mentioned in chapter 2.4.

This function allows you to accumulate an expense over a specified number of periods in advance or in arrears. It can also be used in conjunction with the Delay function to convert an expense stream in the P&L firstly into invoice amounts, then into cash payments.

Formula

Time Sum=Time Sum (Amount, Periods, Arrears/Advance, End, Override, Days in Period, Indicator)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Data Input Table 1 Double DATE The amount to accrue.

Number Periods

Input Table 1 Double NUMPERIODS

The number of periods to add up to determine the size of the bill.

For example, if you enter 3, it accumulates three periods. This parameter reads the Advance/Arrears parameter to determine whether to count the periods forward (Advance) or backward (Arrears).

Periods are processed in chronological order, regardless of the sequence of the periods.

Page 164: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 164

Name Direction Number of Columns

Column Type

Column Name

Description

Methods Input Table 3 Double METHOD1 Arrears/ Advance type:

• In arrears

• In advance

Double METHOD2 End type:

• Zero (default)

• Average

• Replicate

• Override -The override is used even if the number of periods is 0.

• Spare

Double METHOD2 Override value.

Days Input Table 1 Double DAYS Length of period in days.

Config Input Table 1 Double CONFIG Has six rows, each rows specify as below:

• 0: 0, days is not used; 1, days is used; 2, days is not used

• 1: First calculated month

• 2: To calculate month length

• 3: First calculated year

• 4: Length of Year

• 5: Zero or non-zero, if zero, days is not used

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double TIMESUM The cash payments

Page 165: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 165

Example

DROP TYPE DATA_T;

CREATE TYPE DATA_T AS TABLE("DATA" DOUBLE);

DROP TYPE NUMPERIODS_T;

CREATE TYPE NUMPERIODS_T AS TABLE("NUMPERIODS" DOUBLE);

DROP TYPE METHOD_T;

CREATE TYPE METHOD_T AS TABLE("METHOD1" DOUBLE, "METHOD2" DOUBLE, "METHOD3" DOUBLE);

DROP TYPE DAYS_T;

CREATE TYPE DAYS_T AS TABLE("DAYS" DOUBLE);

DROP TYPE CONFIG_T;

CREATE TYPE CONFIG_T AS TABLE("CONFIG" DOUBLE);

DROP TYPE RESULT_T;

CREATE TYPE RESULT_T AS TABLE("TIMESUM" DOUBLE);

DROP table PDATA;

CREATE column table PDATA("ID" INT,"TYPENAME" VARCHAR(100),"DIRECTION" VARCHAR(100));

insert into PDATA values (1,'DATA_T','in');

insert into PDATA values (2,'NUMPERIODS_T','in');

insert into PDATA values (3,'METHOD_T','in');

insert into PDATA values (4,'DAYS_T','in');

insert into PDATA values (5,'CONFIG_T','in');

insert into PDATA values (6,'RESULT_T','out');

DROP PROCEDURE "_SYS_AFL"."AFLBFL_TIMESUM_PROC";

DROP TYPE "_SYS_AFL"."AFLBFL_TIMESUM_PROC__TT_P1";

DROP TYPE "_SYS_AFL"."AFLBFL_TIMESUM_PROC__TT_P2";

DROP TYPE "_SYS_AFL"."AFLBFL_TIMESUM_PROC__TT_P3";

DROP TYPE "_SYS_AFL"."AFLBFL_TIMESUM_PROC__TT_P4";

DROP TYPE "_SYS_AFL"."AFLBFL_TIMESUM_PROC__TT_P5";

DROP TYPE "_SYS_AFL"."AFLBFL_TIMESUM_PROC__TT_P6";

call afl_wrapper_generator('AFLBFL_TIMESUM_PROC','AFLBFL','TIMESUM',PDATA);

DROP TABLE DATA_TAB;

CREATE TABLE DATA_TAB ( "DATA" DOUBLE ) ;

INSERT INTO DATA_TAB VALUES (30) ;

INSERT INTO DATA_TAB VALUES (40) ;

INSERT INTO DATA_TAB VALUES (40) ;

INSERT INTO DATA_TAB VALUES (300) ;

INSERT INTO DATA_TAB VALUES (400) ;

INSERT INTO DATA_TAB VALUES (500) ;

Page 166: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 166

DROP TABLE NUMPERIODS_TAB;

CREATE TABLE NUMPERIODS_TAB ( "NUMPERIODS" DOUBLE ) ;

INSERT INTO NUMPERIODS_TAB VALUES (0) ;

INSERT INTO NUMPERIODS_TAB VALUES (3) ;

INSERT INTO NUMPERIODS_TAB VALUES (0) ;

INSERT INTO NUMPERIODS_TAB VALUES (12) ;

DROP TABLE METHOD_TAB;

CREATE TABLE METHOD_TAB ( "METHOD1" DOUBLE ,"METHOD2" DOUBLE,"METHOD3" DOUBLE);

INSERT INTO METHOD_TAB VALUES (1, 0, 0) ;

DROP TABLE DAYS_TAB;

CREATE TABLE DAYS_TAB ( "DAYS" DOUBLE ) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (30) ;

INSERT INTO DAYS_TAB VALUES (360) ;

INSERT INTO DAYS_TAB VALUES (360) ;

INSERT INTO DAYS_TAB VALUES (360) ;

DROP TABLE CONFIG_TAB;

CREATE TABLE CONFIG_TAB ( "CONFIG" DOUBLE) ;

INSERT INTO CONFIG_TAB VALUES (1) ;

INSERT INTO CONFIG_TAB VALUES (10) ;

INSERT INTO CONFIG_TAB VALUES (1) ;

INSERT INTO CONFIG_TAB VALUES (0) ;

INSERT INTO CONFIG_TAB VALUES (3) ;

INSERT INTO CONFIG_TAB VALUES (3) ;

DROP TABLE TIMESUM_TAB;

CREATE TABLE TIMESUM_TAB ( "TIMESUM" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_TIMESUM_PROC(DATA_TAB, NUMPERIODS_TAB, METHOD_TAB, DAYS_TAB,CONFIG_TAB,TIMESUM_TAB) WITH OVERVIEW;

SELECT * FROM TIMESUM_TAB;

Page 167: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 167

3.50 Transform

This built-in function helps users to build equations using angles and trigonometry functions when the Cycles function does not provide the functionality they need.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Input Input Table 1 Double VALUE Input value, varies with the method, for example: angle measured in radians.

Method Input Table 1 Double VALUE Methods: 0=No Change; 1=Sine; 2=Cosine; 3=Tangent;4=(1+input^2)^.5;5=sinh;6=cosh;7=tanh; 8=Degrees to radians; ...

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double TRANSFORM Transformations for time series

Example

DROP TABLE INPUT_TAB ;

CREATE TABLE INPUT_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO INPUT_TAB VALUES (10) ;

DROP TABLE METHOD_TAB ;

CREATE TABLE METHOD_TAB ( "VALUE" DOUBLE ) ;

INSERT INTO METHOD_TAB VALUES (7) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ("TRANSFORM" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_TRANSFORM_PROC(INPUT_TAB, METHOD_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 168: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 168

3.51 Volume Driver

This function calculates the year-over-year percentage difference (for detailed information about Year over Year Difference, click here) for each volume driver. A volume driver is entered as a percentage and a bandwidth. The bandwidth should be a positive number. The bandwidth of the first volume driver always starts at zero.

After allocating percentage to all non-zero bandwidth, the remaining percentage will be applied to any residue.

Formula

Volume Driver result = Volume Driver(Value, Volume Driver1 %, Volume Driver1, Volume Driver2 %, Volume Driver2, Volume Driver3 %, Volume Driver3 …)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Salary Input Table 1 Double SALARY Input amount

Percent Input Table 1 Double PERCENT Percentage to be applied, starting at zero

Bandwidth Input Table 1 Double BANDWIDTH Bandwidth value

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double OVERHEAD Calculated volume driver result

Page 169: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 169

Example

---Table Preparation

DROP TABLE VALUES_TAB;

CREATE COLUMN TABLE VALUES_TAB ( "SALARY" DOUBLE );

INSERT INTO VALUES_TAB VALUES (2000);

INSERT INTO VALUES_TAB VALUES (15000);

INSERT INTO VALUES_TAB VALUES (25000);

INSERT INTO VALUES_TAB VALUES (35000);

INSERT INTO VALUES_TAB VALUES (45000);

DROP TABLE PERCENTS_TAB;

CREATE COLUMN TABLE PERCENTS_TAB ( "PERCENT" DOUBLE );

INSERT INTO PERCENTS_TAB VALUES (0);

INSERT INTO PERCENTS_TAB VALUES (0.2);

INSERT INTO PERCENTS_TAB VALUES (0.4);

DROP TABLE BANDWITHS_TAB;

CREATE COLUMN TABLE BANDWITHS_TAB ( "BANDWIDTH" DOUBLE );

INSERT INTO BANDWITHS_TAB VALUES (3000);

INSERT INTO BANDWITHS_TAB VALUES (27000);

DROP TABLE RESULTS_TAB;

CREATE COLUMN TABLE RESULTS_TAB ( "OVERHEAD" DOUBLE);

CALL _SYS_AFL.AFLBFL_VOLUMEDRIVER_PROC(VALUES_TAB, PERCENTS_TAB, BANDWITHS_TAB, RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB;

Page 170: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 170

3.52 Year-Over-Year Difference

This function calculates the year-over -year difference between the current and previous one time period. The function result can be a percentage, proportion, or actual amount.

Formula

Three formulas are required by the Business function for percentage, actual number, or proportion respectively.

Year over Year Difference = Year over Year Difference (Base; Style)

For percentage:

Year over Year Difference, period n = Year over Year Difference (Base; %) = 100*(((Base, period n) - (Base period n-1))/(Base, period n)) For actual amount:

Year over Year Difference, period n = Year over Year Difference (Base; a) = (Base, period n) - (Base, period n-1) For proportion:

Year over Year Difference, period n = Year over Year Difference ({Base Sales; p) = (Base, period n)/(Base, period n-1)

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Base Input Table 1 Double BASE The data to compare

Style Input Table 1 Double STYLE 0: Percent Year over Year Difference

1: Arithmetic Year over Year Difference

2: Proportion Year over Year Difference

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double DIFFERENCE The Year over Year Difference

Page 171: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 171

Example

DROP TABLE BASE_TAB;

CREATE TABLE BASE_TAB( "BASE" DOUBLE ) ;

INSERT INTO BASE_TAB VALUES (1000) ;

INSERT INTO BASE_TAB VALUES (2000) ;

INSERT INTO BASE_TAB VALUES (4000) ;

INSERT INTO BASE_TAB VALUES (5000) ;

INSERT INTO BASE_TAB VALUES (2000) ;

INSERT INTO BASE_TAB VALUES (1000) ;

INSERT INTO BASE_TAB VALUES (0) ;

DROP TABLE STYLE_TAB;

CREATE TABLE STYLE_TAB( "STYLE" INT);

INSERT INTO STYLE_TAB VALUES (0) ;

DROP TABLE DIFFERENCE_TAB;

CREATE TABLE DIFFERENCE_TAB( "DIFFERENCE" DOUBLE) ;

CALL _SYS_AFL.AFLBFL_YEAROVERYEARDIFFERENCE_PROC(BASE_TAB, STYLE_TAB, DIFFERENCE_TAB) WITH OVERVIEW;

SELECT * FROM DIFFERENCE_TAB ;

Page 172: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 172

3.53 Year to Date

This function calculates year-to-date totals based on original figures. It starts accumulating again from scratch if the period contains start date of the fiscal year.

It is one of the most reused calculations in business and is extremely time-consuming to constantly re-script.

Formula

Year to Date = Sum of original data from the start of the fiscal year.

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Sales Input Table 1 Double SALES The original series

Start Date Input Table 1 Double STARTDATE The date used to start to calculate

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double YEARTODATE Year to date result (Year To Date Sales)

Page 173: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 173

Example

DROP TABLE SALES_TAB ;

CREATE TABLE SALES_TAB ( "SALES" DOUBLE );

INSERT INTO SALES_TAB VALUES (1000) ;

INSERT INTO SALES_TAB VALUES (1000) ;

INSERT INTO SALES_TAB VALUES (1000) ;

INSERT INTO SALES_TAB VALUES (1000) ;

INSERT INTO SALES_TAB VALUES (1000) ;

INSERT INTO SALES_TAB VALUES (1000) ;

DROP TABLE STARTDATE_TAB ;

CREATE TABLE STARTDATE_TAB ( "STARTDATE" DOUBLE );

INSERT INTO STARTDATE_TAB VALUES (4) ;

DROP TABLE RESULTS_TAB ;

CREATE TABLE RESULTS_TAB ("YEARTODATE" DOUBLE);

CALL _SYS_AFL.AFLBFL_YEARTODATE_PROC(SALES_TAB, STARTDATE_TAB,RESULTS_TAB) WITH OVERVIEW;

SELECT * FROM RESULTS_TAB ;

Page 174: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 174

3.54 Year-to-Date Statistical

This function calculates the original numbers based on the year-to-date values in another row. This is a critical planning function for spreading, target seeking and so on.

Formula

Original, Period n = (Year to Date Value, Period n) - (Year to Date Value, Period n-1) At the first period of the fiscal year, use the below formula:

Original, Period 1 = Year to Date value, Period 1

Signature

Input Tables

Name Direction Number of Columns

Column Type

Column Name

Description

Year to Date Series

Input Table 1 Double YEARTODATESERIES

Accumulated total (Year to Date Sales)

Start Date Input Table 1 Int STARTDATE The date used to start to calculate

Output Table

Name Direction Number of Columns

Column Type

Column Name Description

Result Output Table 1 Double ORIGINAL Original Series

Page 175: SAP HANA Business Function Library (BFL) Reference

SAP HANA Business Function Library (BFL) Reference

© SAP AG 2012 175

Example

DROP TABLE SALES_TAB;

CREATE TABLE SALES_TAB( "YEARTODATESERIES" DOUBLE );

INSERT INTO SALES_TAB VALUES (1000);

INSERT INTO SALES_TAB VALUES (2000);

INSERT INTO SALES_TAB VALUES (3000);

INSERT INTO SALES_TAB VALUES (2000);

INSERT INTO SALES_TAB VALUES (4000);

INSERT INTO SALES_TAB VALUES (6000);

INSERT INTO SALES_TAB VALUES (8000);

INSERT INTO SALES_TAB VALUES (10000);

INSERT INTO SALES_TAB VALUES (12000);

DROP TABLE STARTDATE_TAB;

CREATE TABLE STARTDATE_TAB( "STARTDATE" INT);

INSERT INTO STARTDATE_TAB VALUES (3);

DROP TABLE ORIGINAL_TAB;

CREATE TABLE ORIGINAL_TAB( "ORIGINAL" DOUBLE);

CALL _SYS_AFL.AFLBFL_YEARTODATESTATISTICAL_PROC(SALES_TAB, STARTDATE_TAB, ORIGINAL_TAB) WITH OVERVIEW;

SELECT * FROM ORIGINAL_TAB;