3. Optimizing your custom code


Prerequisites

Before you start reading this blog it is good to read the blog series.


  1. Introduction – Unleash the power of SAP HANA from your ABAP Custom Code –http://scn.sap.com/community/abap/hana/blog/2014/06/20/abap-custom-code-management–leverage-the-power-of-sap-hana-in-abap
  2. Unleash the power of SAP HANA from your ABAP Custom Code- Accelerate your custom reports like never before – Functional Correctness – http://scn.sap.com/community/abap/hana/blog/2014/06/20/unleash-the-power-of-sap-hana-from-your-abap-custom-code-accelerate-your-custom-reports-like-never-before–functional-correctness
  3. Unleash the power of SAP HANA from your ABAP Custom Code- Accelerate your custom reports like never before – Detect and Prioritize your Custom Code – http://scn.sap.com/community/abap/hana/blog/2014/06/27/unleash-the-power-of-sap-hana-from-your-abap-custom-code-accelerate-your-custom-reports-like-never-before–detect-and-prioritize-your-custom-code
  • NOTE: This blog contains information collected from various sources. The objective is give the the various custom code optimizations patterns available for each NW SPs and one example of custom code optimization


Introduction

Once the performance identifications are prioritized, the code needs to be corrected as per the suggestions from the tools (ATC and SWLT). To improve the performance SAP suggests to code pushdown. Code pushdown is nothing but moving data intensive business logic to SAP HANA database layer by means of any HANA artefacts.

There are several optimization patterns available to improve the performance of the custom code. It depends on the use case as well as the Customer system’s NW landscape. The image below is shows all the available SAP’s recommendations for optimizing the custom code.

/wp-content/uploads/2014/06/recommendations_485535.png

What is mean by “Code Pushdown” ?

Code pushdown is moving the data intense business logic as much as possible to data base layer by means of HANA artefacts or Advanced ABAP code pushdown concepts.

code pushdown.png

The above diagram depicts the code pushdown. When we talk about code pushdown there two approaches we suggest.

1. Top Down Approach

If the customer’s SAP NW SP is on 7.40 SP05 or above then this is the best suitable approach one should have. In Top down approach, there are three ways of code pushdown is possible.

/wp-content/uploads/2014/06/topdown_485560.png

If you choose top down approach, the code pushdown is possible via advanced open SQL, CDS views and ABAP Managed Database Procedures.

  1. Advanced Open SQL: Open SQL has come up with new data exchange protocol named “Fast Data Access Protocol” which has implicit transparent optimizations for SELECT and FOR ALL ENTRIES statements. Some notable changes in advance open SQL,
    1. ABAP variables (host variables) escaped with “@”
    2. Comma-separated column list
    3. Supports arithmetic and string expressions
    4. Supports conditional expressions (SQL CASE, COALESCE).

       

          Example:

    adv open sql.png

       2.   Advanced View Building (CDS): CDS simplifies and harmonizes the way you define and consume your data models, regardless of the consumption technology. Technically, it is an enhancement of SQL which provides you with a data definition language (DDL) for defining semantically rich database tables/views (CDS entities) and user-defined types in the database. The enhancements include:

      1. Annotations to enrich the data models with additional (domain specific) metadata
      2. Associations on a conceptual level, replacing joins with simple path expressions in queries
      3. Expressions used for calculations and queries in the data model

          CDS entities and their metadata are extensible and optimally integrated into the ABAP Data Dictionary and the ABAP language. CDS is supported natively in both the ABAP and the HANA Platforms! You can finally define and consume your data models in the same way (syntax, behavior, etc.) regardless of the SAP technology platform (ABAP or HANA).

          Example:

          CDS.png

   

       3.   ABAP Managed Database Procedures (AMDP): AMDPs enables you to create database procedures directly in ABAP using e.g. SQL Script and to seamlessly integrate it in modern ABAP development. An AMDP can be implemented using an ABAP method.

          Example:

          AMDP.png

      • AMDP can be defined as class method only on global classes
      • Implementation class should implement a marker interface IF_AMDP_HDB
      • Implementation contains only SQL Script code
      • ABAP literals can be passed as input / output parameters
      • Corresponding HANA artefacts (A database procedure) gets created upon the activation
      • No HANA Transport Container required. Life cycle becomes easy for developer

2. Bottom Up Approach

If customer’s SAP NW SP is below 7.40 SP05, the code pushdown is possible via creating HANA artefacts. There are four types of HANA artefacts can be created for code pushdown.


bottom up.png

If you choose bottom up approach, there are four ways of code pushdown are available.

  • Attribute View: For joining multiple tables with simple calculations.
  • Analytical View: For analytical application. Enabled with simple calculation with unit and currency conversions.
  • Calculation View:
    1. Graphical Mode: For aggregations and unions. Also enabled with calculated columns and measures.
    2. Script Mode: For complex use cases. SQL Script enabled to write the business logic. Also CE functions can be used.
  • Database Procedure: For more complex use cases. Also can be used for write scenarios and passing many input and output parameters.

The image below explains the consumption part of HANA artefacts in ABAP layer.

hana artefacts.png

ABAP consumption is possible by

  • External Views: The dictionary representation of HANA views in ABAP layer. These external views can be directly consumed via open SQL like tables.
  • Database Procedure Proxy: HANA Database Procedures can be exposed as Database Procedure Proxies on the ABAP dictionary layer. The new syntax “CALL DATABASE PROCEDURE” can be used to consume the database proxies.
  • NOTE: If the customer system’s NW SP is below 7.40, then only bottom up approach is suitable and consumption is only possible via native SQL.


Possible Approaches of NW SPs

SAP NW Release Possible Code Pushdown Approaches
NW 7.40 SP05 or above
  1. Advanced Open SQL
  2. CDS views
  3. ABAP Managed Database Procedures
Below NW 7.40 SP05
  1. HANA Views
    1. Attribute View
    2. Analytic View
    3. Calculation View
  2. HANA DB Procedures

NOTE: External Views or Database Procedure Proxies can be created to consume the HANA artefacts in ABAP Code.

Below NW 7.40 SPs [Ex: 7.31 SPs]
  1. HANA Views
    1. Attribute View
    2. Analytic View
    3. Calculation View
  2. HANA DB Procedures

NOTE: HANA artefacts can be consumed only via native SQL.


Follow Up Blog

There is a follow up blog which is explains a real time example of custom code optimization.

  1. Optimize the custom code – Example –


To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply