Uploaded by saradhi.kommisetti

Code Push Down HANA AS Secondary DB

advertisement
Code Push Down ?
Code Push Down ?
• What is Code Push Down?
• One of the key differences for developing
applications in ABAP for HANA is that you can
push down data intense computations and
calculations to the HANA DB layer instead
bringing all the data to the ABAP layer and the
processing the data to do computations. This is
what is termed as Code-to-Data paradigm in the
context of developing ABAP applications
optimized for HANA.
Code Push Down ?
• Where does Code Push Down Start?
• It is a general misconception that if one wants
to do code push down in ABAP for HANA you
always need to either use HANA native SQL or
build complex HANA artefacts in order to
achieve this.
• But in reality the Code Push Down for
HANA from ABAP can very well start with
ABAP Open SQL. Let us see How and Why?
The New Enhanced Open SQL
• Support for arithmetic expressions and
computed columns in the projection list.
• Support for string expressions part of the
project list
• CASE – ENDCASE are allowed during
Selection
• Inline Declarations
The New Enhanced Open SQL
• Use aggregate functions where relevant instead of
doing the aggregations in the ABAP layer
• Use arithmetic and string expressions within Open SQL
statements instead of looping over the data fetched to
do the arithmetic and string operations
• Use computed columns in order to push down
computations that would otherwise be done in a long
loops
• Use CASE and/or IF..ELSE expressions within the Open
SQL in order embed the logic of conditional expression
which in the past would have been done after fetching
the results from the database.
What are the advantages of using Open SQL to
do code push down?
• Your ABAP code will remain database agnostic
and will run on any ABAP server independent
what is the underlying database
• You implicitly take advantage of all transparent
optimizations that have been achieved in the
Database Interface level
• All default performance optimizations like use of
buffer and house keeping activities like client
handling etc are automatically taken care of
HANA As Secondary DB(Side Car
Scenario) ?
• In order to leverage the performance advantage
of the SAP HANA database for existing ERP
customers without changing existing ERP
applications!
• Improving the few important reports
performance
• Access the aggregated (Where HANA is stronger
with the help of Calculation engine) data from
HANA Information Models
• Real time data analysis in OLTP system (HANA as
a Side-car approach)
Still Open SQL – Fail to provide?
• Unions & INTERSECTIONS
• Additional Join Types
– Cartesion
– Right Outer Join
– Full Outer Jon
And Functions like DAYS_BETWEEN ..
HANA As Secondary DB(Side Car
Scenario)
• Get Benefitted from HANA Native functions to
achieve Code down
HANA As Secondary DB
Side Car Scenario
HANA Views & Procedures
• The Data Intensive Logic/Calculations can be
implemented natively in HANA via Views ,
Procedures and
the Same can be accessed from the ABAP via
Native SQL technique.
HANA Views(Modelling)
• Views
• Modeling SAP HANA Information Views are important
for successfully exploiting the power of SAP HANA.
These views are classified as
• Attribute Views
• Analytic Views
• Calculation Views
• At run-time these views make implicit use of optimized
SAP HANA In-Memory calculation engines and thus
enable for best performance.
• HANA Data Modeling is only possible for Column
Tables i.e. Information Modeler only works with
column storage tables.
Attribute view
– Attribute views are dimensions, BW characteristics or master data.
– Attribute views are used to join to a dimension or attribute view.
– In most cases used to model master data like entities (like Product,
Employee, Business Partner)
– Highly re-used and shared in Analytic- and Calculation Views
•
Example : An attribute view "FLIGHT" can show together Airline
Code, Airline Connection Number and flight Date into one Object.
This attribute view can be used in analytic and calculation views
where entities are relevant.
Generally attribute views represent master data. But, however
technically there is no restriction and it's possible to make attribute
views on transaction data.
Attribute View
Analytic View
• Analytic views are star schemas or fact tables surrounded by
dimensions, calculations or restricted measures.
• In the language on SAP BW analytical views can be roughly
compared with Info Cubes or Info Sets.
• Analytic views are typically defined on at least one fact table that
contains transactional data along with number of tables or attribute
views.
• Analytic views leverage the computing power of SAP HANA to
calculate aggregate data, e. g., the number of bikes sold per
country, or the maximum power consumed per month.
• It is specifically designed to execute star schema queries
Analytic View
Calculation View
• Calculation views are composite views used on top of
analytical and attribute views.
• It can perform complex calculations not possible with other
views.
• It can be defined as either graphical views or scripted views
depending on how they are created. Graphical views can be
modeled using the graphical modeling features of the SAP
HANA Modeler. Scripted views are created as sequences of
SQL statements.
• Calculation views can be referred as combination of tables,
attributes views and analytical views to deliver a complex
business requirement. They offer to combine different
analytical views into one source of data for reporting.
SAP HANA Modeling View Processing:
ViewProcessing
View Processing
• Join Engine: Used for Attribute Views
OLAP Engine: Used for Analytic Views
(without calculated columns)
Calculation Engine: Used for Analytic views
with calculated attributes, Calculation views
Script based Calculation View
Data Preview
Stored/Database Procedures
• Are based on SAP HANA-Specific Language i.e
SQL Script, an extension to SQL
• Can have any no.of Scalar and Table like input
parameters
• Can have any no.of output parameters but
always Table type
• May contain Read/Write access to Datbase .
Stored/Database Procedures
Native SQL
• Native SQL from Can be implemented via
– Non-Object Oriented i.e EXEC SQL – ENDEXEC
– Object Oriented Via ADBC(ABAP Database
Connectivity)
Note : To Execute Native SQL of 2nd ry Database, in
both the approacheS, Database Connectivity is
required to the 2ndy Database.
Database Connection - DBACOCKPIT
Native SQL Via EXEC- ENDEXEC
• Every native SQL Statement must be within EXECENDEXEC and statements ends with no period, ;
…
• EXEC SQL.
connect to 'SYSTEM' as 'ADM'
ENDEXEC.
• EXEC SQL.
open dbcur for select kunnr,BELNR ,netpr,IDATE,PDATE,DPRTY, DAYS,interest fro
m _SYS_BIC."gagan/ZCUS_INVOICE"
ENDEXEC.
Native SQL Via EXEC- ENDEXEC
•
DO.
"No Space after Column for Fetch next
EXEC SQL.
fetch next dbcur into :LS_cus_inv
ENDEXEC.
IF sy-subrc NE 0.
EXIT.
ELSE.
APPEND LS_cus_inv TO lt_cus_inv.
ENDIF.
ENDDO.
Native SQL Via EXEC- ENDEXEC
• EXEC SQL.
close dbcur
ENDEXEC.
EXEC SQL.
disconnect 'ADM‘
• ENDEXEC.
Access HANA VIEW via EXEC-ENDEXEC
Access HANA DB Procedure via EXEC-ENDEXEC
• EXEC SQL.
open dbcur for CALL _SYS_BIC."gagan/ZCAL
_INVOICE"( NULL )
ENDEXEC.
• Rest of the steps like Open DB Connection ,
Disconnect and Fetch Cursor, next … are same
ADBC to access HANA Views and
Procedures
• Is an Object Oriented Approach
• cl_sql_connection=>get_connection
• cl_sql_statement
– Methods : Execute_Querry( v_querry )
• cl_sql_result_set
• cx_sql_exception
Access HANA Procedure Via ADBC
• lo_con = cl_sql_connection=>get_connection(
'SYSTEM' ).
CREATE OBJECT lo_sql
EXPORTING
con_ref = lo_con.
Access HANA Procedure Via ADBC
• lv_sql = | CALL _SYS_BIC."gagan/ZCAL_INVOIC
E"| && |( NULL ) |.
lo_result = lo_SQL->execute_query( lv_sql ).
• lo_result->set_param_table( lr_data ).
lo_result->next_package( ).
lo_result->close( ).
Access HANA Procedure Via ADBC
• After Closing and Within TRY-ENDTRY
• if lt_cus_inv is INITIAL.
MESSAGE 'Data Not Found' TYPE 'I'.
ELSE.
LOOP AT lt_cus_inv into ls_cus_inv.
write : / ls_cus_inv-kunnr, ls_cus_inv-belnr, ls_cus_invnetpr,ls_cus_inv-idate,ls_cus_inv-pdate,ls_cus_inv-days,ls_cus_invinterest.
ENDLOOP.
endif.
CATCH cx_sql_exception INTO lx_sql_exc. " Exception Class for SQL E
rror
lv_text = lx_sql_exc->get_text( ).
MESSAGE lv_text TYPE 'E'.
ENDTRY.
Access HANA Views via ADBC
• For View
• lv_sql = |SELECT KUNNR, BELNR , NETPR, IDATE, PDATE, DPRTY, DAYS,
INTEREST'| && | FROM _SYS_BIC."gagan/ZCUS_INVOICE" | .
• For Procedure Call
lv_sql = | CALL _SYS_BIC."gagan/ZCAL_INVOIC
E"| && |( NULL ) |.
Native SQL ABAP Programs
• Via ADBC
– REPORT ZGAGN_SEC_ACCES_VW_ADBC.
– REPORT ZGAGN_SEC_ACCES_PROC_ADBC.
• Via EXEX- ENDEXEC
– REPORT ZGAGN_SEC_ACCES_VW_NATIVE_SQL
Download