SAP ABAP On HANA by Ravi Anand

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

SAP ABAP on HANA – Ravi Anand

A database schema is a way to logically group objects such as tables, views, stored procedures etc.
Think of a schema as a container of objects. You can assign a user login permissions to a
single schema so that the user can only access the objects they are authorized to access.

Access to User 1 / User 2 Access to User 3 / User 4

Schema 1 Schema 2 Schema 3

Table 1 / Table 2 View1 View2 Procedure1 Procedure2 Table3

Data Base

In a Database we have several objects which created through several schemas, User have authorization to
Schema. So in another word user can not directly interact with database objects . In the SAP HANA we
have two type of Schema. One is default Schema which by default assign to user when we create user,
Another is Global Schema where actual database object stored. Default Schema is local and objects
cannot be move to Global Schema. Schema contains database objects like Tables, Views, Procedures Etc.

In SAP HANA Data is stored in two types of table

1. Row Based Transactional Data


2. Column Based Analytical Data

Page 1 of 82
SAP ABAP on HANA – Ravi Anand

A database table is conceptually a two-dimensional data structure organized in rows and columns.
Computer memory, in contrast, is organized as a linear structure. A table can be represented in row-order
or column-order. A row-oriented organization stores a table as a sequence of records. Conversely, in
column storage the entries of a column are stored in contiguous memory locations. SAP HANA supports
both, but is particularly optimized for column-order storage.

Now How the data is physical stored.

US | Alpha | 3000 US | Beta | 1250 JP | Alpha | 700

In Row Based model Data is stored in sequential format, One record than next Record, The Arrow
contain two address, One where is next Node and where is previous Node.

In case of column based storing data of all the column stored in same block.

US Alpha
US Beta
JP Alpha
Etc. Etc.

This is helpful since we generally fetch the data based on key fields. We are storing all the key fields in
same column. Here we are considering that Country is key field. So when we have to make a search

Page 2 of 82
SAP ABAP on HANA – Ravi Anand

Case one : Row Based Table.

System makes a sequential search Like first read Node1 than Node 2 than Node3 ( We are reading node
in sequence on the assumption that data is sorted, if it is not sorted than again search become more
complex and on that case we have to read full table ). Node1 know where is node2 located and node 2
know where is node 3 located.

Case Two : Column Based Table.

Read the first column only and read the key fields. The first node of column knows where is next node
which is Alpha. So it is always fast to read in a column instead of reading in different rows.

Additionally HANA works in parallel processing and In memory concept. SAP HANA three different data
engine which acts on requirement. Exa.

1. JOIN Engine : When Querying an attribute view. It also run when we use simple SQL.
2. OLAP Engine : Used in Analytic View.
3. Calculation Engine : Used in Calculation View and Analytic View. Complex calculation.

There are four types of View exist in SAP HANA :

1. Attribute View
2. Analytical View
3. Procedure View
4. Calculation View.

Page 3 of 82
SAP ABAP on HANA – Ravi Anand

Use Above Graphics to select the method.

Data in SAP HANA is stored in two ways

1. Row Based Table


2. Column based table.

Transactional data stored in Row Based table and Analytical data stored in Column based table. As per
current scenario Current SAP system will store all the data in Row Based Tables in case our primary
database is HANA than also it will store data in row based table. Column based table we can use when
we are creating / generating report using Custom Tables, or in case of Web Dynpro where we will create
custom table, populate the data and fetching /calculation logic in HANA, and for displaying output in
Portal /Screen.

SAP HANA says put max. load on database. Move calculation into database, Transfer Results.

Load on DATA Base Load on DATA Base

Load on Application Server Load on Application Server

Classical Approach SAP HANA Approach.

Page 4 of 82
SAP ABAP on HANA – Ravi Anand

SAP HANA uses Views to display the output. Actual data always stored in Database in Table format. View
is only definition Part.

Before starting lets first see how data flows from ECC to SAP HANA. DATA Provisioning.

SAP LT Application Server. ( SLT ) SAP LANDSCAPE TRANSFORMATION. SLT acts as a middleware which is
responsible for data transferring between SAP HANA and SAP or Non SAP System. SLT is a server, It can
be separate server or it can be part of ECC System. SLT contain function ( Logical codes used in Mapping
/ Conversion ). SLT contain control Module which can

1. Triggering write module.


2. Mapping and conversion.
3. Convert Row based data into column base.
4. De Clustering.
5. Filtering.
6. RE Structuring.
7. Renaming Tables Etc. In case we are using SAP HANA as primary data base than also we
need SLT, at lest for converting Row -> Column. Look and feel of SLT server is sam as ECC
System.

The write module is responsible for writing data and deleting log files using DB connection. In ECC
System there is one trigger program for every table, which get trigger whenever there is any operation
happened in database. Exa. Updation, Insertion, Deletion. This trigger program will create a log file at
run time which hold the data need to replicate, as soon as write module write the data into database,
Log file get deleted.

RF ECC System RFC SLT System ODBC / JDBC SAP HANA

DB Connection

ECC Data Base

ECC System and SLT system can be in Same Box, in Either case RFC is required.

Page 5 of 82
SAP ABAP on HANA – Ravi Anand

Connection between Source System and HANA System is defined in Configuration. Transaction code LTR
in SLT. For each configuration there will be one schema generated. Configuration require following
actions.

1. Define a schema for each source system.


2. Define connection to source system.
3. Define DB connection into SAP HANA.
4. Define replication frequency (real-time; frequency for scheduled replication).
5. Define maximum number of background jobs for data replication.

Before that let’s see how SAP HANA Studio Looks.

Name of your HANA Database, You have


to login here.

HDB(BEST) Means HDB is database and BEST is user name.

After login you will see the following screen.

Page 6 of 82
SAP ABAP on HANA – Ravi Anand

1. The Catalog Nodes navigate to Physical Tables, Views Etc. This contain all the Database Schema
which will get created when user g.et created. Each Schema contain folder for Column Views,
Functions, Tables and Views.
2. The Content Node Navigates to Attribute View, Analytic View, Calculation View, Procedure and
Analytical Privileges. Its only visible under Modeler perspective.
3. Provisioning refer to data movement between system. Refer to SLT.
4. Security contain Role and Authorization.

Expanding the views give us details about objects. Exa. Click on Tables. Click on any table name, you will
get the table details and also if it is row based on column based. Based on symbol you get it. Other
option is see the table type.

Page 7 of 82
SAP ABAP on HANA – Ravi Anand

Right click on table and select Table Open Data Preview, you will see the table data.

You will see the output.

Page 8 of 82
SAP ABAP on HANA – Ravi Anand

You have the option to filter it , Analysis it Etc.

Now let’s about data provisioning . click on reset perspective.

Click on Open Perspective.

Page 9 of 82
SAP ABAP on HANA – Ravi Anand

Click on HANA Modeler.

Click on data Provisioning.

Select the Data Base.

Click on Finish.

Page 10 of 82
SAP ABAP on HANA – Ravi Anand

Now let’s understand activity involve in loading.

1. Load is referring to Initial Load. All the table data get refreshed and new entry get inserted.
2. Replicate refer to Delta, Only changes will get updated.
3. Stop Replication , Stop the replication and old data will take place again. Log file get cleared so
that nothing to replicate.
4. Suspend, Its like Pause, Trigger program will still activated, Log table will not clear, it kept the
changes.
5. Resume, Resume from Suspend. After resuming trigger program get inactivate, Log table get
clear, Write Module get activated, and nothing pending to write.

For making data transfer we need to create a configuration, The Name of the configuration would be
your name of Schema. Login to SLT Server and run transaction LTR. Enter User Name / Password. System
will show you existing configuration.

Page 11 of 82
SAP ABAP on HANA – Ravi Anand

Click on New for making a new configuration.

Fill the require Details.

See the Replication


Option. You can change it as per your requirement.

You can directly upload data in to database and create table . Exa. We have following excel sheet.

Select Import->Data from Local File.

Page 12 of 82
SAP ABAP on HANA – Ravi Anand

Select the system, Where u want to import..

Fill the details.

Provide Schema Name / Table Name. Do the mapping, Set the key fields, Change the data type. Select
the type of table (Row Based / Column Based ).

Page 13 of 82
SAP ABAP on HANA – Ravi Anand

Finish it. Check on History about any error.

Since Data / Table and Schema are at Database, expand the Catalog node and see your table.

If you want to see the data. Right Click and click on Open Data Preview.

Page 14 of 82
SAP ABAP on HANA – Ravi Anand

You will see the data there.

Modeling of object is only possible if its assign to _sy_Repo User. See Package ZRA*.

Delivery Unit is like a Transport Request there we can put a logical packet( Object List) to transport it to
Production Server.

Page 15 of 82
SAP ABAP on HANA – Ravi Anand

Generating Time Data.


In SAP HANA we can create time related data, Exa. Calendar from where we can fetch the data. Its up to
us how deep we can keep the data, It would be like a system table where date and time related data
exist.

Click on Generate Time Data.

We have option either we want to create a Year calendar or Fiscal year calendar. For creating Fiscal Year
it will ask for Variant Schema and Variant.

The Data will be stored at following location.

Catalog->SY_BI->Tables->M_TIME_DIMENSION.

Page 16 of 82
SAP ABAP on HANA – Ravi Anand

Data Preview.

During the selection you have to make selection for here.

Few Things need to remember during SLT Process.

Transaction IUCC_SYNC_MON for monitoring activity. We run this transaction in SLT Server. Its like
SM66 in ECC. Login to SLT.

Page 17 of 82
SAP ABAP on HANA – Ravi Anand

Provide Mass Transaction ID. This ID you will get when you do the configuration in Data
Provisioning.

You can see the table name used in replication. Add Table option, we can add table here, But
SAP Recommend not to add table name here, add the table at Data Provisioning.

For creating a new configuration, Click on new config. Fill the required data.

Page 18 of 82
SAP ABAP on HANA – Ravi Anand

Save it , A new Schema will get created name would be your config. Name. Once it is created
you can add tables which need to replicate.
For any change in the structure we need to start Initial load again, The old table will get drop
and new table will get created, No trigger program generated for initial load. During the
replication Job IUUC_MONITOR_012 started automatically and it will control the replication.
When we kill this job, Replication get cancelled.
When adding tables, screen looks like.

When the replication started screen look like.

There are Few table provided by SAP which we can use to modify / validate data during
replication.

1. IUUC_ASS_RUL_MAP

Structure of table

Page 19 of 82
SAP ABAP on HANA – Ravi Anand

There are two type of Transformation Rule,

1. Event Based
2. Parameter Based.

Possible Events are :

1. BOP Begin of processing


a. Processed only once, before the data transfer really starts.
b. Can be used to initialize certain fields that might be used in subsequent events.
2. BOT Begin of Blocks
a. Access to all data records of a portion read from the sender system
3. BOL Begins of Loop
a. Like BOT if only one table is included in the conversion object; in case of objects with
multiple tables, it can be applied to each specific table.
b. Move-corresponding Source to Target.
4. BOR Begin of Record
a. This event is processed before the field mapping of the individual fields is started.
b. Individual field Mapping.
5. EOR End of Record
a. This event is processed after the field mapping of the individual fields of a certain data
record has finished
6. EOL End of Loop
7. EOT End of Block
8. EOP End of processing

Page 20 of 82
SAP ABAP on HANA – Ravi Anand

Example of using table.


1. Based on Parameter.

2. Based on Event. Here its BOR.

Next. Triggering condition: It can be defined in table IUUC_SPC_PROCOPT. When triggering condition is
true than only it will get replicated to Target System. Fields details of table are :

Now Lets an Exa.

Page 21 of 82
SAP ABAP on HANA – Ravi Anand

In the above Example, Data will be replicated to HANA system only when Company code is 1000 or
More. There are two ways to filter the data.

1. Based on Triggering Event ( Source System ). For every table there is one triggering program
associated with it. It get executed when there is some table updation happens.
2. By Rules ( Event Based / Parameter Based ) in SLT.

Working with different types of Join

Inner Join.

Page 22 of 82
SAP ABAP on HANA – Ravi Anand

Inner Join in Analytic View.

Left Outer Join.

Page 23 of 82
SAP ABAP on HANA – Ravi Anand

Customer is Left table


here.

See the SQL.

1. Sales Order table is our Left Table, Select all the records from there.
2. On Inner join Customer is our Left Table so collect all the data from Customer Table.
3. Match Customer Table with State Table, Field which does not match will be blank. Example TOM
Does not exist in State Table so it will contain empty value.
4. Match the output of step 3 with Records of Step 1. Display final output, The fields for which
record does not match will hold empty value. Left Outer Join means all the records of Left table
match with right table. Means All records of Left table + Matching Records of Right Table.

Page 24 of 82
SAP ABAP on HANA – Ravi Anand

Right Outer Join ( Apposite of Left Outer Join – All records of Right Table +
Matching records of Left table).

Here all the records from State Table ( Its Right Table ) + Matching records of Left Table here its
Customer.

1. Collect all the records of State ( Which is Right Table) + Matching with customer table.
2. All the records from Sales Order Table ( Right Table ), + Matching records of Step 1.

Page 25 of 82
SAP ABAP on HANA – Ravi Anand

Full Outer Join

SQL in HANA

For commenting we can use –- <Comment>for single line and /* <Comment> */ For
multiple line.

Page 26 of 82
SAP ABAP on HANA – Ravi Anand

Now once data available in HANA System we can use Modeling.

There are four types of View exist in SAP HANA :

1. Attribute View
2. Analytical View
3. Procedure View
4. Calculation View.

If you are joining Tables of Master data Than Attribute views are good choice, Attribute views
uses Join Engine , This view does not support Transactional Data.

Page 27 of 82
SAP ABAP on HANA – Ravi Anand

If you are working with transactional Data and you wanted to work with Star Schema or data
aggregation than Analytic View is good choice. Its uses OLAP Engine.

If you are modeling with more complex data than calculation View are best choice. Its include
any combination of tables, column views, attributes views, and analytic views. Its uses the
calculation Engine.

We will create those views to get the required / requested data.

Attribute View
We can think Attribute view as a basic view which contain various table, which contain other
details. Exa. For getting details of Material Master we have several tables in SAP, MARA, MAKT,
MARM. Every table we can treat as Attribute. It is require to get complete details of an Business
object. Business Object Means Material , Customer, Plant, PO number, Sales Order Number Etc.
The best option to make a attribute of an object is to include all the check tables or use the
transaction code AOBJ in SAP.

Attribute view executed in Join Engine, since we are fetching data from various tables. Think
bellow diagram,

Attribute 1 Attribute 2

Fact Table

Attribute 4
Attribute 3

This is like a Star Schema, For getting the Fact data we need several other details. Attribute is a
Question table and Fact is Answer table. Fact table data only of measurable fields Exa. How
Many. We will create Attribute table and use those tables in Analytical view. In another words
Attributes Views are like INFOTYPE of an employee.

Page 28 of 82
SAP ABAP on HANA – Ravi Anand

Lets create an Attribute View. Attribute View created at Node Content. First we need to create
one Package where our View get stored.

Fill the details, Delivery Unit is like a Transport request.


We can keep similar objects into same delivery unit. Now the package will get created. You have
another option to create sub Package inside this package. Now we will create few Attribute
views inside this package.

Page 29 of 82
SAP ABAP on HANA – Ravi Anand

We have three type of attribute view.

1. Standard View : Generally we which we create.


2. Time View : View which store time related data, Exa. Fiscal Year Etc.
3. Derived View : Like KNA1 Main View -> Ship to / Bill To / Payer Etc. are derived views.
Making changes on main view reflect in Derived view, We do not need to make changes in
every view like copied view.

Lets create a time related view.

Save and activate it.

Page 30 of 82
SAP ABAP on HANA – Ravi Anand

View the output.

Click on Raw Data.

Page 31 of 82
SAP ABAP on HANA – Ravi Anand

Next Create a Derived View, It will ask from where( Which Attribute View) we have to derived .

Finish and save it.

Next create a Standard View.

Page 32 of 82
SAP ABAP on HANA – Ravi Anand

Every Attribute View have two parts.

1. Semantic Part : Contain Technical Details.


2. Data Foundation : Contain List of Tables.

Now which tables you want to use in your attribute.

Click on + Add Objects. It will show you list of tables available in database.

Page 33 of 82
SAP ABAP on HANA – Ravi Anand

Select the table which you want to use.

Now you will see list of fields of the table. Also on left side under output , you will see option Columns
and Calculated fields. Double click on fields which you want to see in outout.

Those fields will be available in output.

Page 34 of 82
SAP ABAP on HANA – Ravi Anand

Now Calculated fields means you want to add some custom fields. Click on New.

On the next screen provide the logic and other details of calculated fields.

At the bottom you will see list of fields which we can use to generate value of new fields. We have
Operators and functions. Now here we are adding Customer Number and Name to display as calculated
fields.

Click on check to see the logic is correct or not.

Save It. Calculated field appear.

Activate it and see the table content.

Page 35 of 82
SAP ABAP on HANA – Ravi Anand

In The Semantic part we have option Make a field as key field, We can change the label( Description ),
Hide, Etc.

Hierarchy have different and important role, if we want to see the data in more details. Lets take an
Example We have an attribute view where data is stored in date. Now in case of simple report every row
would be having one records, but suppose we want to see the report in First Year wise, next expanding
it to month level, next week Level than Hierarchy comes in Picture. The use of Hierarchy is in Analytical
View.

Next if you are adding two tables in a view you have option to make a relation between them. Here we
are making link between two tables common field Customer.

Page 36 of 82
SAP ABAP on HANA – Ravi Anand

Here is the output , 6th column is calculated field. Now when you are clubbing the records linking of
tables should be such that it will produce unique records , else if one records comes multiple times than
in analytical views its also comes multiple times and calculation will be wrong.

Restricted Measure : Restrict your output based on certain condition. Its like a filetr criteria to improve
performance.

Page 37 of 82
SAP ABAP on HANA – Ravi Anand

Available Aggregation types are : SUM / MIN/ MAX.

Calculated Measure : To make calculation on certain fields so that later on you can use Aggregation to
show report. It will improve the performance, For that create a new calculate fields and for aggregation
check the option Calculate Before Aggregation.

Page 38 of 82
SAP ABAP on HANA – Ravi Anand

In this example we have calculated the value of fields Total Sales Before aggregation ( SUM).

Next there are two types of filter to improve performance.

1. Constant filter, we apply it at time of table creation, The filter apply on the table before any
SQL, Its fast since SQL apply on filter data.
2. Using Where Clause : Its define during runtime. Its apply on the result of a SQL Query.

There are three types of SCHEMA in SAP HANA

1. User Defined Schema : These are created by User.


2. SLT Derived schema : When SLT is configured Its create Schema in SAP HANA. All the tables
replicated in HANA system are contained in this nSchema.
3. System Defined Schema : Its derived with SAP HANA Database and contain HANA system
information.Exa. _SYS_BI, _SYS_BIC, _SYS_REPO, _SY_STATISTICS Etc.

_SYS_BI C : This Schema contain all the column views of activated objects, When user
activate any Attribute Views, Analytic Views, Calculation Views, Procedure Etc, The respective
runtime objects are created under _SYS_BIC/Column Views.

_SYS_REPO : This Schema contain the list of Active Objects , Inactive Objects, Package
Details, and Runtime object information. We keep those objects here for which we want to do
modeling. _SYS_REPO user must have Select Privilege with grant option on the data schema.

_SYS_BI : This Schema contain all the metadata of created column views. Its contain the
tables for created variables , Time Data, Schema mapping and content mapping table.

Page 39 of 82
SAP ABAP on HANA – Ravi Anand

_SYS_STATISTICS : This Schema contain all the system configuration and parameters.

_SYS_REPO is a system user. Its schema is a system schema. You don't touch any of those. When you
create new application schemas in your security context, e.g. under your user, then it's necessary to
grant _SYS_REPO the SELECT WITH GRANT privilege on your schema, if you want to build and activate
models that read from your schema. Think of _SYS_REPO as "the activation guy". It takes your models
and creates the necessary runtime objects from them (_SYS_BIC schema, several BIMC_*-tables and
other places keep these runtime information). Now, after having activated all your models that access
data in your schemas, _SYS_REPO wants to give you (and probably other users) read access to the
activated models. Part of that is allowing read access to your data. That's what _SYS_REPO needs the
privilege for your schema for. Allowing others the access to your schema. Since not all schemas in the
database will be used in models, there is no automatic assignment of this privilege to _SYS_REPO.
As part of your security strategy you need to actively assing _SYS_REPOthe permission to every schema
you want to build models on.

Lets create an Analytical view.

Page 40 of 82
SAP ABAP on HANA – Ravi Anand

In Data Foundation we add the tables for which we have to do Analysis. It should contain Measurable
view.

In the Analytical view we have option to pass data either in form of Variable value or in form of Selection
Screen.

Now Variable is like selection screen field. Go to Semantic part and create a variable. When you execute
the view this variable will appear as selection option you can put some value and system will filter data
based on this input value.

Input Parameters works as a variable. We can put some value there either from table or from hard code,
during execution of view we can filter the data. To create it select Input Parameter and click on New.

Page 41 of 82
SAP ABAP on HANA – Ravi Anand

Both option works as place holder to pass the data as filter


criteria. For Analytical View one field from table must be of type Measurable else it give you error. In the
data foundation we provide name of transactional table. And in Join we provide name of attribute
views.

Page 42 of 82
SAP ABAP on HANA – Ravi Anand

Example of Analytical View.

First create two attribute view name : ZSALES and ZMAT.

Use Table VBRP as Foundation Table. We have to do analysis in this table. Link them based on key fields.

Below is the output.

Page 43 of 82
SAP ABAP on HANA – Ravi Anand

Calculation View
When working with multiple Facts table or when joins not give us proper result than go for Calculation
View there we have option to composite multiple view, Have power of SQL Script.

A Calculation View are :

1. A Column view which are visible to reporting tool.


2. When view is accessed , a function is implicitly executed ( SQL Script / Procedure).
3. There are two types of calculation view exist,
 Graphical : It can be created using Graphical Editor.
 Script based : are created using SQL Editor. Complex calculation which is not
possible using Graphical Approach can be created using SQL Script.
4. Calculation view are read only.

Page 44 of 82
SAP ABAP on HANA – Ravi Anand

Graphical Calculation Views :

1. No SQL Coding required.


2. Can consume other Analytical views, Attribute Views, Calculation Views and Tables.
3. Union / Join / Projection provided with existing view functionality.

Calculation Views are Composite views and can be used to combine other views . It can consume other
Analytical, Attribute and calculation views and Tables.

Create a new calculation view :

We have three tables

1. Product Master
2. Region Master
3. Sales Master,

The objective is to find out Sales Value of a particular reason, Sales Value of a particular product , Total
Sales for Product XXX in Region XXX.

First create the tables, We have created three tables.

Grant Access to _SY_REPO User.

Page 45 of 82
SAP ABAP on HANA – Ravi Anand

Deploy it. Now your tables are ready for modeling. Next Make a calculation View. Create a new
Calculation view, Following screen will appear.

Now click on Join and drag it to the below area.

Click on + sign and add table Region Master. Do the same thing for Sales Table.

Page 46 of 82
SAP ABAP on HANA – Ravi Anand

Now make a link between both the tables.

Double click on Join, here you can change the type of Join, Currently set it to Inner Join.

Select the output fields.

Page 47 of 82
SAP ABAP on HANA – Ravi Anand

Same way add Product table also.

With the help of arrow join both the join.

Select the Join 1 and select the Product ID, Link it with Product Master Table. Join 1 and Join 2 are now
linked. Select the join type as Inner Join. Select the output fields from Join1.

Add the Join2 Block to Aggregation using arrow. In Aggregation select all fields as output.

Page 48 of 82
SAP ABAP on HANA – Ravi Anand

Now select Semantics, We have to tell the system which are Attribute fields and which are Measurable
fields. Choose Auto Assign.

You can change the type of the fields.

Activate it and see the data Preview.

Page 49 of 82
SAP ABAP on HANA – Ravi Anand

Unions are used to combine the result set of two or more data source. Condition is missing here.
Structure should be same. For Exa. Clubbing Ship to Party Data, Ship to Party Data Etc. into single one.

Joins are used to query data from two or more data source, Based on some condition. For Exa. Select
data from two tables based on common attribute with some condition.

A Projection is used to filter or create a subset of required column of a table or View for creating a
model. Means we have a table or view having multiple column and we need only few of them, Create a
projection to select few from many. A Projection can only have one source means Single table or view.

Aggregation is used to summarize data using SUM, Min, Max., Average Etc. Like Projection it has also
only source. For Exa. Getting the Max. Score of Individual in a team, Or Total scored of a team Etc.

Screen will looks like that.

Page 50 of 82
SAP ABAP on HANA – Ravi Anand

Double click on Script View, Following screen will appear.

We have to write our code between BEGIN and END. VAR Out is a variable which keep output values
which you select in output. Select the output type from View. Be careful when you are giving view path
in FROM.

Page 51 of 82
SAP ABAP on HANA – Ravi Anand

PROCEDURE AND SQL Script


Creating a Procedure : You can call the procedure anywhere. It’s like a FM which can be used globally.

Click on New Procedure.

Fill the details.

Page 52 of 82
SAP ABAP on HANA – Ravi Anand

Following screen will appear. Select the input and output fields.

Click on New Output Parameter.

Create the output


fields. Same way create input parameter.

Page 53 of 82
SAP ABAP on HANA – Ravi Anand

After executing you will see the output. For executing it, Select the system and click on SQL, On the SQL
Editor Write the code. ? means NULL Input, means no Input parameter.

You will get the output.

CALCULATION ENGINE CE Function


Calculation engine is the execution engine for SQLScript. Calculation engine plan operators encapsulate
data-transformation functionality. It is an alternative to using SQL statements as their logic is directly
implemented in the calculation engine, i.e. the execution environment of SQLScript. Operator has been
categorized as Data Source Access and Relational.

1. CE_COLUMN_TABLE
OUTOUT = CE_COLUMN_TABLE (“MAST_TABLE”, [“FLD1”, “FLD2”, “FLD3”]);
This is equivalent to following SQL
OUTPUT = Select FLD1, FLD2, FLD3 from MAST_TABLE;
2. CE_JOIN_VIEW

OUTPUT = CE_JOIN_VIEW(“MAST_TABLE”,[“FLD1”, “FLD2”, “FLD3”]);

Page 54 of 82
SAP ABAP on HANA – Ravi Anand

This is equivalent to following SQL

OUTPUT = Select FLD1, FLD2, FLD3 from MAST_TABLE;

Its retrieve fields from Join View MAST_TABLE.

3. CE_OLAP_VIEW

OUTPUT = CE_OLAP_VIEW (“OLAP_VIEW”,[“FLD1”, “FLD2”]);

Equivalent to following SQL

OUTPUT = Select FLD1, SUM(FLD2) from OLAP_VIEW group by FLD1.

4. CE_CALC_VIEW

OUTPUT = CE_CALC_VIEW (“TAB_MAST”, [“FLD1”, “FLD2” ]);


Equivalent to select fld1, fld2 from TAB_MAST;
5. CE_JOIN

OUTPUT = CE_JOIN(:TAB1, :TAB2,[“FLD1”],[“FLD2”, “FLD3”,”FLD1”,”FLD4”]);

Equivalent to

Select FLD2, FLD3, A.FLD1 FLD4 FROM :TAB1 as A, :TAB2 as B

Where A.FLD1 = B.FLD1.

6. CE_PROJECTION
OUTPUT = CE_PROJECTION(:TAB1,[“FLD1”, “FLD2”, “FLD3”],”FLD5” >50);
Equivalent to Select FLD1, FLD2, FLD3 from TAB1 where FLD5 > 50;
7. CE_CALC
8. CE_AGREEGATION
OUTPUT = CE_AGREEGATION(:TAB1,[COUNT(“FLD1” ) as “COUNT”],[“YEAR”]);

Is equivalent to select count(FLD1) as “COUNT” from :TAB1 group by YEAR;


9. CE_UNION_ALL
OUTPUT = CE_UNION_ALL(:TAB1, :TAB2);
Is equivalent to select * from :TAB1 union all select * from :TAB2;

SQL Control Statement

Page 55 of 82
SAP ABAP on HANA – Ravi Anand

CURRENCY CONVERSION

Page 56 of 82
SAP ABAP on HANA – Ravi Anand

The Preferred way to define currency conversion for measure is to model in ANALYTIC VIEW. Some time
we can do it at Calculation View also.

Page 57 of 82
SAP ABAP on HANA – Ravi Anand

Page 58 of 82
SAP ABAP on HANA – Ravi Anand

Page 59 of 82
SAP ABAP on HANA – Ravi Anand

Page 60 of 82
SAP ABAP on HANA – Ravi Anand

Page 61 of 82
SAP ABAP on HANA – Ravi Anand

CE_CONVERSION can be use when we want to do currency conversion at Calculation View.

Analytic Privilege : Its like Autho. In Object in ECC. We can put it at View so that for every record it
will check if user have autho. To see the data or not. We can use it at Attribute and Analytical View Level
and not at Calculation View, It does not make any sense to apply at calculation level. We can create
multiple Analytical Privilege for the same view for OR condition.

Click on New Analytic Privilege,

Page 62 of 82
SAP ABAP on HANA – Ravi Anand

Click on Next.

Select the view and click on add.

Click Finish.

Next, Select the Validity Period / Field Name and Field Values.

Page 63 of 82
SAP ABAP on HANA – Ravi Anand

Activate it. Now our Analytic Privilege is created, next we have to assign it to user level. Go to User,

Page 64 of 82
SAP ABAP on HANA – Ravi Anand

Now for View ZRA_MARA user can only see the records for Material XXXX ( We set at Analytic Privilege ).

Decision Table : Decision table is a table where we make some decision and accordingly make some data
changes. Its like IF / ELSEIF Condition. Exa. When Material Group is XYZ give 10 % Discount on sales Etc.
In Background of Decision table one procedure get created , we can call the procedure anywhere with
call statement. It will be located in SYBIC folder.

There are two types of decision table

1. With Update value : Update value in HANA.


2. With Return Value : Do not make any up dation in database, just make a decision based on
calculated field.

Lets create a Decision table with Return Value :

Page 65 of 82
SAP ABAP on HANA – Ravi Anand

On the next screen select the table using which we want to make decision table. Action is only possible
from Table and not from attribute view.

Select the attributes ( Output fields ). Next for making decision table we need to populate two Nodes
one is Conditions and another is action. In condition we specify condition and on action whet need to
do. Here based on Material Group we are changing values of NETWR fields. Select Material Group and
assign it to condition.

Page 66 of 82
SAP ABAP on HANA – Ravi Anand

After doing that our Action and action nodes will get populated with attribute.

Next double click on Decision table.

On the next screen put the condition and actions.

Page 67 of 82
SAP ABAP on HANA – Ravi Anand

Select the values.

After activating one procedure get created in _SYS_BIC with same name.

CREATE PROCEDURE "_SYS_BIC"."BEST/ZRA_DECISION_TAB" LANGUAGE SQLSCRIPT AS


COUNT269283788016847697333815253131963989551 INT :=0 ;
BEGIN
UPDATE "BEST"."ZRA_VBAP" SET "NETWR"=
(CASE WHEN "MATKL" = '9013' THEN "NETWR"*100

ELSE "NETWR"
END
);

END;

You can call this procedure.

Before executing see the result of table. See the last row 9013.

Page 68 of 82
SAP ABAP on HANA – Ravi Anand

Now in Decision table we have changed the condition.

Execute the procedure again. And see the impact of last record. Its changed 10 to 1000.

Now when next time you select data from decision table you will get changed records. Check the
procedure its actually updating the table.

Now let’s make another decision table with return values. We will use the same table, steps are also
same.

Page 69 of 82
SAP ABAP on HANA – Ravi Anand

We have added the table and selected the fields.

Next in the parameter


create a new field which will be calculated fields.

Fill the details.

New field will be added. Now we will use this field as action and for condition we will use same field
Material Group. Now fields will be added as Action and as Condition.

Page 70 of 82
SAP ABAP on HANA – Ravi Anand

Set the condition and action values. And activate it.

Now see the procedure.

Its returning values and not updating any fields.

CREATE PROCEDURE "_SYS_BIC"."BEST/ZRA_DECISION_RET_VALUE"(OUT returned_tt


"_SYS_BIC"."BEST/ZRA_DECISION_RET_VALUE/TT") LANGUAGE SQLSCRIPT READS SQL
DATA WITH RESULT VIEW "_SYS_BIC"."BEST/ZRA_DECISION_RET_VALUE/RV" AS
BEGIN
returned_tt = SELECT "VBELN" AS "VBELN", "POSNR" AS "POSNR", "MATNR" AS
"MATNR", "CHARG" AS "CHARG", "MATKL" AS "MATKL", "NETWR" AS "NETWR", "KWMENG"
AS "KWMENG", CASE WHEN "MATKL" = '9066' THEN NETWR*100

Page 71 of 82
SAP ABAP on HANA – Ravi Anand

ELSE 1
END
AS "ZRA_NEW_CAL_FIELD" FROM "BEST"."ZRA_VBAP";

END;

Here is the output of procedure.

Partitioning Table

To Improve the performance if we feel data size is huge than we have option to portioning the table, In
which we keep similar data ( Based on Key Fields ) on one portion and rest on another partition. For.
Exa. For BSEG table based on fiscal year we can make partition so that for each fiscal year we have data
on separate plate so fetching would take less time. During the selection we do not need to separately
pass the partition name, system automatically recognize It.

For creating Partition go to Catalog->Table ->Show Table Distribution.

Page 72 of 82
SAP ABAP on HANA – Ravi Anand

Next select the table and click on Partition Table.

Select the details.

Page 73 of 82
SAP ABAP on HANA – Ravi Anand

Hash is Automatically Partition and Range , you can specified the criteria. First Lets select HASH Type,
Click Next, Select the column based on which you want to create Partition.

Click Finish.

Partition will get created.

Next do it with Range


Option.

Page 74 of 82
SAP ABAP on HANA – Ravi Anand

Now when select Range system ask the DATA Range based on which it should create Partition.

Select the details and click on finish.

Next Create an Index, Index is required when we want to create index based on two fields, Fields could
be anything.

Right click on table and click on new index. Select the fields based on which you want to create index.

Page 75 of 82
SAP ABAP on HANA – Ravi Anand

Execute it by pressing green Arrow, Index will get created in system.

Page 76 of 82
SAP ABAP on HANA – Ravi Anand

Consuming Procedures / Tables / Views in ABAP

Two ways exist based on System Config.

ECC System
Bottom UP Approach TOP Down Approach

Oracle Data Base HANA Data Base

Two case exist, 1. When HANA is your Primary Database and 2. When HANA is used as secondary
database.

Now in both the cases we can consume Views / Procedure created in Database using Connection string.
Connection string is database connection, so with SQL statement we have to pass the connection string
name so that system can understand where it has to be executed. In this case every statement will
executed as a loop and returning table is not possible. In this case only possible data types are :

1. Decimal
2. Float
3. NVARCHAR
4. DATE
5. Time.

Now here we are talking about when HANA is our main database. In Bottom up approach Create View in
HDB, Create same view in ECC with same structure, Logic does not required in ECC. Thank access the
Views in ECC. When creating Views in HDB same will not be replicated in ECC, we have to manually
create it in ECC System.

Page 77 of 82
SAP ABAP on HANA – Ravi Anand

In case of TOP Down approach we will create Views / Procedure in ECC and same will get replicated in
HDB System.

We have a Procedure written in HANA now we have to consume it in ABAP.

Here is the procedure with


input and output parameter.

Next Switch to the ABAP Development Tool.

Select Other ABAP Repository Object.

Create a new Database Procedure.

Page 78 of 82
SAP ABAP on HANA – Ravi Anand

Fill the details.

HANA Procedure is name of Procedure created in HANA. Interface is name of Interface which get
created in ECC System with Input and output parameter details, We have to use this interface to access
Procedure created in HANA. On Next Screen provide Transport Request number and than Finish.

Page 79 of 82
SAP ABAP on HANA – Ravi Anand

Now you can see the created database procedure.

Click on Interface to check the code.

Click on Synch. To Sync it with HANA.

Page 80 of 82
SAP ABAP on HANA – Ravi Anand

Save and Activate.

Now create an ABAP Program to consume Procedure.

Fill the details.

Add a Transport request and save it.

Write the following code.

When creating data type for import and export use the same data type which is used in Interface. Get
the reference.

Page 81 of 82
SAP ABAP on HANA – Ravi Anand

And pass it in Call Database procedure, Get the output in Internal table and Test.

Page 82 of 82

You might also like