ABAP On HANA Topics

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

1 ADT (ABAP Development Tool)

 Done

2 NEW ABAP Syntax and SCI


 Done

3 EPM Data Model


 Done

4 OIA(Open Item Analysis) Scenario Code in ABAP


 Done – Using Normal ABAP Code

5 Basics of Information Modeling in HANA


 Information Modeling
i. Views
1. Attribute View
2. Analytical View

6 Information Models in HANA


 Covered View
i. Views
1. Calculation View
2. Decision Table

7 OIA, ADBC and HTC with View Proxy


8 SQL Scripting
9 SQL Scripting DEEP Drive
10 SQL Script Advanced
11 ABAP Managed Data Procedure - OIA
12 ABAP on HANA VS S4HANA
13 CDS Views Basics
14 CDS Views Deep Dive
15 CDS View with Odata, Security, Table Function
16 CDS and BOPF Integration
17 BOPF Integration Deep Dive
18 ALV with IDA Access
19 HANA Full Text Search
4 OIA(Open Item Analysis) Scenario Code in ABAP

Open item Analysis is the requirement for one of the client.

The Accounts Receivable accountant is interested in Open orders —responsible


for cash management—typically searches, displays, and analyzes overdue orders
and orders that exceed a predefined and customizable amount. The Accounts
Receivable accountant also classifies buyers according to the risk of nonpayment.

As an Accounts Receivable accountant, you use OIA to perform the following tasks:
 Check sales orders with open status.
o Table
 SNWD_SO_INV_HEA
 PAYMEnt_STATUS <> ‘ ‘.

 Check open sales orders based on Buyer ID, Sales Order Number, and
Calendar days.
o Table
 SNWD_BPA
 BP_ID -> Business Partner ID
 COMPANY_NAME -> Company Name

 SNWD_SO_INV_HEAD
 CHANGED_AT -> Calendar Days

 Categorize buyers according to the time taken to clear a payment and


payment history (subsequent topic contains information about payment
history).
o Calculate Average number of days any summing invoice count.

 Perform Dunning Run (subsequent topic contains information about


Dunning Run).

 Check sales orders in common currency (This might be required if sales


order items are processed in different currency units).

 Check the payment history of a buyer.

 Check Dunning Level of open orders (subsequent topic contains information


about Dunning Level).
5 Basics of Information Modeling in HANA

Views: (External Views)


In information modeling different views are created.
 Why views are created in Information Modeling
 Sometimes non-technical users need have information on the data.
Since it is very difficult for them to combine different tables and pull
data they have created information modeling.
 This views are graphical representation of DB.
 When the views are created inside DB in the form of DB View.

Link: https://sapyard.com/view-the-hana-views-from-different-angles/

***How many Times views are there? And How what are they?

1. Attribute View
2. Analytical View
3. Calculation View
a. Graphical View
b. SQL Script
4. Decision Table
SQL Engine

SQL OPTIMIZER

CALCULATION ENGINE

CALCULATION VIEW
Calculation View are view with SQL Script inside
(with the calculation logic). It has Graphical &
Script based editor.

It can combine Attribute and Analytical view


and also another Calculation view can be
consumed (two or More Analytical view can be
used in calculation view)

Uses
Complex data modeling. Uses both Attribute and
Analytical views Characters to be seen

Example
Created Attribute and Analytical(two or more )
joined here.

OLAP ENGINE JOIN ENGINE

ANALYTICAL VIEW
Analytic view is typically used for analyzing ATTRIBUTE
ATTRIBUTE VIEW
VIEW
numerical data and figures. That is Numbers, Good
Good Performance
Performance JOIN
JOIN on
on Master
Master tables.
tables.
Quantities and Currencies.
Uses
Uses
Uses Only
Only Text
Text and
and Numeric
Numeric Characters
Characters to
to be
be
Whenever want to deal with Quantities, seen
seen
Price, Measures.
Example
Example
Example Join
Join on
on MARA
MARA and
and MAKT
MAKT
EKPO PO Quantity, Unit of Measure etc.
The SQL Optimizer decides the best way to call the engines depending on the involved
models and queries.
The SAP HANA architecture provides different types of engines:

 Join Engine: The Join Engine used to perform all type of joins.

 OLAP Engine: The OLAP Engine is used for calculation and aggregation ‚based
on star schema‛ or similar.

 Calculation Engine: The Calculation Engine is used on top of OLAP engine


and/or Join Engine for complex calculation which cannot be done by Join Engine
or OLAP Engine.

Few FAQs
 Q. Why should we link attribute view to transactional table (fact) to create
Analytic view? What is the advantage? Why not just join tables directly to
transactional table?
A. Yes, technically, we can join tables directly to fact tables. But creating Attribute
view has more advantages and HANA adovcates modelling objects like attribute views
instead of tables.
 Reasons:
i) Reusability: Attribute views are reusable building blocks and would be useful in
future developments. .
 ii) Maintenance: Any change in the dimension or characteristic of the field in
Attribute view would flow downstream to all developed objects and models. We do
not need to change/update each and every development.
 iii) Coherence : If we always use attribute view instead of adding the base tables,
we can ensure that all our developments are coherent.
 iv) Analysis: HANA does not have ‘where-used’ search to find the tables. But we can
do the ‘where-used’ of HANA modeling objects. So, it is easier to find the views and
then figure out the tables when we want to do some analysis or investigating
something.
 Q. Can there be calculative field/column in Analytical View or Attribute View?
A. Yes, we can. But any Attribute/Analytic View containing a calculation attribute
would automatically become a Calculation View.
 Q. Attribute Views do not store data, then how does it display the output?
A. When Attribute Views are called for output, the Join Engine takes care of
processing the data and providing the output.
 Q. Which engine is responsible for Analytic View?
A. OLAP (Online Analytical Processing) engine processes the Analytical View.
 Q. How does Calculation View work?
A. Once the Calculation view is successfully generated, a column view is generated in
_SYS_BIC Schema. This column view is available to HANA reporting tools.
 Q. Is Calculation View directly available for reporting?
A. No. But, Calculation view can be made available for reporting, by enabling
MultiDimensional Reporting under the Semantics section. Once it is enabled, the
execution occurs using CE (Calculation Engine) functions in the Index Server at the
database level.
 Q. Between Calculation View and Analytic View, which view has
better performance?
A. Analytic View. Calculation View is executed in CE (Calculation Engine) while
Analytic View in OLAP. Calculation View is not as fast as an Analytical View.
Please note:
Analytic views with calculated attributes and Calculation views both run in
Calculation Engine.
Analytic Views (without derived columns or calculated columns) use the OLAP Engine
 Q. Views analogy with SAP BW terminology
A. Attribute View is like BW Dimension which can be reused throughout the system
and not just one model.
Info Cubes or Info Sets in SAP BW are the closest cousins to Analytic View.
 Q. Analytic view can have attribute view. So will the join engine of attribute
would trigger or OLAP of analytic view?
A. During activation of the analytic views, the joins in the attribute views get
‘flattened’ and included in the analytic view run time object. Only the OLAP engine
will be used thereafter.

1. Attribute View
 An Attribute View can be created by taking data from one or more data
tables.
 The attribute shows relationships between different attributes. The
attributes can be Customers, Region, Product, Period etc. 
 In an Attribute View, joins can be made between two master data tables,
a text table, and a master data table, etc.

Example:
 MARA table Join with MAKT (Text Table of Material
Description)
 MARA table Join with MARD (Material Plant table)

Product Dimension
Customer Dimension
2. Analytical View
 Analytical Views are used to perform complex calculations and
Aggregations ie., SUM, COUNT, MAX, MIN etc.
 Analytical view is designed as star schema.
 Each analytical view will have one Fact table and surrounded by several
dimension tables.
 Fact table will contain primary key for each dimension table.

Dimension Table3 Dimension Table1

FACT Table

Dimension Table4 Dimension Table2

Example:

Data Foundation
Star Join

Semantic
3. Calculation View
It enables the user to perform the complex calculation logic.
It combines measures from more than one fact table. It enables to combine
attribute view, analytical view and tables (fact and dimension) tables.

It supports both:
 Graphical Calculation View.
 Scripted ( SQL Script ) Calculation View.

While creating calculation view there are other scenario panel for data
filterationa and data joining.
 Join
 A join option connects two source objects or tables into a single
object. It is also referred to as a join node in the view hierarchy.
The join types between two tables can be inner, left outer, right
outer and text join.
 Union
 The union option performs a full outer join on n number of source
objects and creates a single object by combining their contents.
 Projection
 The projection option projects the table in a certain way. You can
use it to filter the columns of a table or add some columns before
using it in other nodes like aggregation, rank, union, etc.
 Aggregation
 In the aggregation node, you can perform aggregation on selected
dimensions and measures.
 Rank
 This is used to rank the values based on a criterion. You can define
the order by clause and partition in this node based on the
modeling requirements.
4. Decision Tables

Decision tables are kind of ETL rules applied on a Column. So it a table with ETL
rules wrapped in ti with Conditions and Actions.
There are few information about Decision Table but we must know when we
need it and if at all we need How to do it. Below blog post Cleary illustrates the
creation and usage of DT in SAP HANA 2.0 SPS 04

Suppose Business want to plan discounts based on some products.

Before giving or declaring the discount the business want to analyze if we give
the discounts will it give us profit or loss etc. Decision table helps in directly
updating the value or it returns certain action on which business can decide on
further decisions.

in such cases it ideal to create a decision table.

Decision tables are of 2 types

1) Decision Table Update Value.( When the user want to change and update
the values in DB itself)

2) Decision table Return Value (If user want to add new field and change the
values).

Here example explained them in a Pictorial representations. Consider we are


giving 10 % discounts to all of our customer then what exactly both the decision
tables do to the data in a table in Database

Now let us create a decision table. For Every decision table we need to have a
condition and a action to the measure or the Key Figure KF.

I created two tables out of Sales Oder header and Item table as Below. HANA
provides excellent feature like Teradata to create a table on the fly same as a base
table. see Below : –
Create a decision table as Below : –

The first time when you create a decision table it looks like as below : –
Now add the ZVBAP_TEST table and I created that with the intention not to
affect the original VBAP table. ?

Added MATNR which is the material as the condition and NETWR to the
action as in above snapshot.

Now applying the logic of the discounts as in below snapshot. We can also
import the calculations from an excel file as well. Import from excel file I Will
cover letter.
Save Validate and Activate the data. By Default Decisions tables are created
under “_SYS_BIC” schema but we can create a decision table under any
schema if we have right previlage enabled for the Decision Table Object or
artifact.

we cannot see the data in a decision table directly in Data Preview just as we
do with a table or a CV. Whenever we create a decision table a Stored
procedure is also getting created under the “_SYS_BIC_” SCHEMA.

let us find the stored procedure and to the data in the DT we need to call the
procedure. A stored procedure is just like a function module or a executable
statement which can be used n number of times. we can call the procedure in
scripted CVS. Point to note here is that we cannot call the SP inside a TF as
Table functions are not allowed to modify database state, and stored
procedures are allowed to modify database state. Therefore, it is not
allowed to execute a stored procedure from within a function.
Now let us call the SP created for the Decision Table.

Once you call the SP you will see that data is getting updated to the base
NETWR value is DB.

Here as I had created the decision table on ZVBAP_TEST the NETWR


value is being updated to 10% or 15% or 20% for the material I choose
for the table ZVBAP_TEST.

You can choose a base table too when we are creating a decision table.
But ideally better not to choose the actual base table as the base table
may be used for other modelling purposes. Create a copy of the base
table and create decision table on top that. Depends on your business
scenario.

Now data in S/4 HANA Source OLTP system.


Data in ZVBAP_TEST(10%DiscountAppliedfortheMateria

ZDEC_TEST decision table is created under the “_SYS_BIC” as a Column View


which eventually is updating the ZVBAP_TEST via a stored procedure call.

We need to schedule the stored procedure based on the business


requirements so that data is getting updated for the selected materials. Say every 1
hour or 2 hour etc.

We can also feed the decision table to a calculation view and also we can use inside a
table function Node (HANA 2.0 SPS 04)

see below diagram


  

also we can return calculated attributes as below

These calculated attributes can only be added to a condition to a measure. Suppose


we want to again apply some kind of filters say Material Like “M-100%” etc then we
derive calculated attribute and apply the action on this condition on a different
Measure.

We can also parameterize the decision table with an IP parameters which can


further be passed to a CV or a TF.
Views are built based on Joins in SAP HANA
***How many types of joins are there in SAP HANA

There are 8(eight) types of joins:

1. Text Join
 Used when ever want to join Main table with text tables

2. Inner Join
 Join which is always performed between tables, records are fetched
when we have matching records in both the tables.

3. Left Outer Join


 Inner Join + Records from the left table are fetched. To that there is
no records in right table.

4. Right Outer Join


 Inner Join + Records from the right table are fetched corr. To that
even there is no records in left table.

5. Referential Join
 Referential join is the default join type in SAP HANA modeling.
 
 It is similar to inner join; evaluation of join depends on selection of
fields from view.

 Referential joins in SAP HANA are used whenever there is a


primary key and foreign key association between two
tables. And, referential integrity is when for every value in the
foreign key column, there is a reference value in the primary
key column of the master data table.

 These behavior depends on the view creation. In attribute view


referential join is always INNER JOIN. Where has if it is used in
Analytical view the behavior changes based on column selection
from attribute view and the tables selected from measures table.

 Example

Order Table
Customer Table and State Table

Create Attribute View for Customer and State -> JOIN is REFERENTIAL JOIN.
Output:

Create Analytical View for Order Table and Customer Table


Join  Use Attribute View Create Above (Customer + State)
Output is shown in below pic: Only Ord1, Ord2 and Ord3 are displayed in output: By
selection all the fields from both.(Attribute view (Customer + State) + Order + Customer)
Since here it behaves like INNER JOIN

Next Remove STATE and S Name column from attributes as OUTPUT.


Now Referential Join behaves like Left Outer Join can see ORD4 line item coming into
output.

Studio Modeling

JOIN IN ANALYTICAL VIEW


STATE and SNAME Selected for output
Output:

State and SNAME not Selected for output

Output from Modeling:


NOTE
 Referential joins should be used with caution since it assumes
that referential integrity is ensured. The only valid scenario for
the Referential Join is that (a) it is 110% guaranteed that for
each row in one table, there is at least one join partner in the
other table, and (b) that holds true in both directions (c) at all
times.
 If that is not the case then referential joins have the possibility
to give incorrect calculations if the referential integrity is not
met – meaning if a delivery header is created but the items is not
processed until a later stage then any calculations that use
referential joins will be incorrect.
 Referential Join cannot be used if a filter is set on a field in the
right table.

6. Temporal Join
 In HANA to join fact with time dimension

7. Spatial Join
 Co-ordinate join, used when Geo spatial analysis to be done in HANA.
 Example: Find the distance between the places., ie., Distance between
Bengaluru to Mumbai via Hyderabad.
 Co-ordinates are locations to find the distance

8. Star Join
 In Calculation view to join 2 star schemas.

Partner Master
Customer Master

FACT Table

Customer

Partner

Supplier

Quantity
Supplier Master

You might also like