ERPClimb logoERPClimb
AMDP
RAP / CDS / ODataintermediate 8 min read

AMDP Part 1: SQLScript and Code Pushdown

Free sample lesson · open to everyone

Key takeaway

Understand AMDP and code pushdown: what an AMDP is, how it relates to CDS and ABAP SQL, when database procedures are justified, and which rules apply to every AMDP.

In this lessonShow sections

Expert visual walkthrough

RAP · CDS · ODATA ACADEMY · Integration pathERPClimb.com

SQLScript and Code Pushdown

AMDP · Chapter-specific technical teaching map

Integration path

1Concept

ABAP CDS consumer

2Concept

AMDP / table function

3Concept

HANA engine

4Concept

Result set

Tutor's chapter takeaway

Understand AMDP and code pushdown: what an AMDP is, how it relates to CDS and ABAP SQL, when database procedures are justified, and which rules apply to every AMDP.

In a real project

A project had a guideline "all reporting logic must be in AMDP for HANA performance". After a year there were 140 AMDP classes, most of them simple aggregations that no one outside two developers could maintain. A performance…

Watch out for

• Using AMDP for simple selects and aggregations. • Assuming AMDP is always faster than ABAP SQL or CDS. • Forgetting client handling in SQLScript. • Missing objects in the USING clause. • Putting ABAP-level logic…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a real project scenario

A project had a guideline "all reporting logic must be in AMDP for HANA performance". After a year there were 140 AMDP classes, most of them simple aggregations that no one outside two developers could maintain.
A performance review compared a sample of them with equivalent ABAP SQL and CDS versions: runtimes were the same within measurement noise for over 90% of cases. The guideline was changed to "ABAP SQL/CDS first, AMDP with justification", and simple AMDPs were gradually replaced during regular changes.

Explanation

This series covers AMDP across six parts: this lesson covers SQLScript and code pushdown; Part 2 creates a first AMDP method; Part 3 covers procedures, functions and table function implementations; Part 4 covers parameters, internal tables and client handling; Part 5 covers debugging, testing and performance; and Part 6 covers AMDP in clean core and ABAP Cloud. CDS Table Functions, covered elsewhere, are a CDS entity implemented through AMDP.

Code pushdown, in one sentence, means moving data-intensive work — filtering, aggregation, calculations over many rows — to the database, and transferring only the results to the application server.

There are three pushdown tools, used in a clear order of preference. ABAP SQL is modern SQL written directly in ABAP, covering joins, aggregations, CASE expressions, window-like features on newer releases, and CTEs with WITH; it's database-independent and the first choice in programs.

CDS view entities are reusable data models carrying semantics, associations and access control, and are the first choice for models used by several consumers, services and analytics tools. AMDP is SQLScript written in an ABAP method, reserved for logic that needs procedural steps, HANA-specific functions, or multi-step intermediate results.

An AMDP is, technically, a normal global ABAP class that carries the marker interface if_amdp_marker_hdb. One of its methods is implemented "BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT" (or "BY DATABASE FUNCTION" for functions), with a USING clause listing every database object the code reads. The ABAP runtime creates the procedure in HANA on first call or activation and keeps it synchronized with the ABAP source, so there are no manual database objects to manage — it's transported along with the class like anything else.

AMDP is justified for multi-step calculations with intermediate result sets that ABAP SQL or CDS would only express awkwardly or slowly, for HANA-specific functions such as special text, spatial or statistical functions, for implementing CDS table functions (covered in Part 3), and for performance gains that have actually been measured rather than just assumed.

It is not justified for simple selects, joins and aggregations, which belong in ABAP SQL or CDS instead; for logic that needs ABAP features like authorization checks, message handling, calling APIs, or RAP, which all have to stay in ABAP; or for anything that must run on non-HANA databases.

A few rules apply to every AMDP: declare all objects being read in USING; handle the client explicitly, since SQLScript does not do this automatically, as covered in Part 4; use OPTIONS READ-ONLY for read procedures; and keep the SQLScript set-based, avoiding loops and cursors wherever possible.

With this, AMDP can be placed correctly among the pushdown tools, and Part 2 goes on to create one.

Code example

ABAP Code
" ===== Pushdown decision: the same requirement three ways =====" Requirement: total net amount per customer for one company code " 1. ABAP SQL (first choice in a program) - database independentSELECT customer, SUM( net_amount ) AS amount  FROM zsales_item  WHERE company_code = @company_code  GROUP BY customer  INTO TABLE @DATA(totals). " 2. CDS view entity (first choice for a reusable model / service)" define view entity ZI_SalesTotals as select from zsales_item" { key company_code as CompanyCode, key customer as Customer,"   @Semantics.amount.currencyCode: 'Currency' sum( net_amount ) as Amount,"   currency as Currency }" group by company_code, customer, currency " 3. AMDP (only if multi-step / HANA-specific logic is needed)CLASS zcl_sales_amdp DEFINITION PUBLIC FINAL CREATE PUBLIC.  PUBLIC SECTION.    INTERFACES if_amdp_marker_hdb.                         " marks the class as AMDP    TYPES: BEGIN OF ty_total,             customer TYPE c LENGTH 10,             amount   TYPE p LENGTH 16 DECIMALS 2,           END OF ty_total,           tt_total TYPE STANDARD TABLE OF ty_total WITH EMPTY KEY.    CLASS-METHODS get_totals      IMPORTING VALUE(iv_company_code) TYPE char4      EXPORTING VALUE(et_total)        TYPE tt_total.ENDCLASS. CLASS zcl_sales_amdp IMPLEMENTATION.  METHOD get_totals BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT                    OPTIONS READ-ONLY                    USING zsales_item.                     " every read object listed    et_total = SELECT customer, SUM( net_amount ) AS amount                 FROM zsales_item                WHERE mandt        = SESSION_CONTEXT( 'CLIENT' )  " client: your job                  AND company_code = :iv_company_code                GROUP BY customer;  ENDMETHOD.ENDCLASS." -> for THIS requirement, options 1 or 2 are better: simpler, portable, testable

Watch out

Common mistakes

  • Using AMDP for simple selects and aggregations.
  • Assuming AMDP is always faster than ABAP SQL or CDS.
  • Forgetting client handling in SQLScript.
  • Missing objects in the USING clause.
  • Putting ABAP-level logic (authorization, messages) into SQLScript.

Do this

Best practices

  • Pushdown order: ABAP SQL/CDS first, AMDP by exception.
  • Justify every AMDP (logic or measured performance).
  • Keep SQLScript set-based and read-only where possible.
  • Handle client explicitly and declare USING completely.
  • Document the reason for AMDP in the class header.

In the interview

Interview angle

Questions: "What is AMDP?", "What is code pushdown?", "When would you choose AMDP over CDS?"
Strong answer: AMDP is an ABAP class method (class with if_amdp_marker_hdb) implemented in SQLScript and managed by the ABAP runtime; code pushdown moves data-intensive work to the database. Use ABAP SQL/CDS first and AMDP only for multi-step, HANA-specific or measured performance needs, or for CDS table function implementations; handle client and USING explicitly.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

A nightly ABAP job reads 30 million line items to the application server only to sum them per customer. What is the simplest improvement?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1A guideline requires all reporting logic in AMDP "for HANA performance". How do you respond?

2What is AMDP, and where does it fit among the code pushdown options?

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.