AMDP Part 1: SQLScript and Code Pushdown
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.
What this complete series covers
Learn ABAP Managed Database Procedures from architecture and the first SQLScript method through functions, client handling, debugging, performance and clean-core decisions.
- Who it is for
- Best for SAP consultants, developers, and learners who want a practical understanding of AMDP.
- Prerequisites
- Basic ABAP and ADT in Eclipse are recommended. The series explains the RAP/CDS/OData concepts as they are introduced.
- Final outcome
- By the end, you should be able to create and call AMDP methods, choose the correct AMDP pattern and justify database pushdown with evidence.
- Part 1: AMDP Part 1: SQLScript and Code Pushdown
Use ABAP Managed Database Procedures deliberately: understand how ABAP class methods are implemented as HANA SQLScript procedures/functions and when database-specific pushdown prov
- Part 2: AMDP Part 2: Create Your First AMDP Method
Create and call a real AMDP class method with SQLScript and understand every important clause.
- Part 3: AMDP Part 3: Procedures, Functions and Table Function Implementations
Distinguish AMDP procedure methods, database-function methods, and AMDP implementations of CDS table functions so you choose the correct contract for imperative processing versus c
- Part 4: AMDP Part 4: Parameters, Internal Tables and Client Handling
Write robust AMDP SQLScript by respecting host-variable syntax, table parameters, set operations, NULL semantics, and explicit client handling instead of assuming ABAP runtime beha
- Part 5: AMDP Part 5: Debugging, Testing and Performance Analysis
Operate AMDP safely with layered debugging, deterministic regression tests, SQLScript/database traces, and HANA execution-plan analysis tied back to the ABAP caller.
- Part 6: AMDP Part 6: AMDP in Clean Core and ABAP Cloud
Evaluate AMDP through the clean-core lens by separating the legitimacy of database pushdown from the release status of every consumed SAP object and the portability of HANA-specific logic.
System and release assumptions: Examples target recent SAP S/4HANA / ABAP Cloud capabilities. RAP, CDS, OData, and Fiori Elements syntax and tooling can differ by ABAP platform release.
Explanation
📌 KEY POINTS
✅ AMDP = an ABAP class method implemented in SQLScript and executed on SAP HANA.
✅ Pushdown order: ABAP SQL / CDS first, AMDP only for logic they cannot express efficiently.
✅ The ABAP runtime manages the procedure: created, transported and versioned like ABAP.
⚠️ AMDP is HANA-specific and bypasses some ABAP conveniences (client, buffering) — handle them yourself.
━━━━━━━━━━━━━━━━━━━━
▶ WHAT THIS SERIES COVERS
- Part 1 — SQLScript and code pushdown (this lesson)
- Part 2 — create your first AMDP method
- Part 3 — procedures, functions and table function implementations
- Part 4 — parameters, internal tables and client handling
- Part 5 — debugging, testing and performance
- Part 6 — AMDP in clean core and ABAP Cloud
Related: CDS Table Functions (an AMDP-implemented CDS entity).
━━━━━━━━━━━━━━━━━━━━
▶ CODE PUSHDOWN IN ONE SENTENCE
Move data-intensive work (filtering, aggregation, calculations over many rows) to the database, and transfer only results to the application server.
━━━━━━━━━━━━━━━━━━━━
▶ THE THREE PUSHDOWN TOOLS
- ABAP SQL — modern SQL in ABAP: joins, aggregations, CASE, window-like features in newer releases, CTEs (WITH). Database-independent. First choice in programs.
- CDS view entities — reusable data models with semantics, associations and access control. First choice for models used by several consumers, services and analytics.
- AMDP — SQLScript in an ABAP method, for logic that needs procedural steps, HANA-specific functions or multi-step intermediate results.
━━━━━━━━━━━━━━━━━━━━
▶ WHAT AN AMDP IS
- A normal global ABAP class with the marker interface if_amdp_marker_hdb.
- A method implemented "BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT" (or "BY DATABASE FUNCTION" for functions).
- A USING clause listing all database objects the code reads.
- The ABAP runtime creates the procedure in HANA on first call (or activation) and keeps it in sync with the ABAP source — no manual database objects, transported with the class.
━━━━━━━━━━━━━━━━━━━━
▶ WHEN AMDP IS JUSTIFIED
- Multi-step calculations with intermediate result sets that ABAP SQL/CDS would express only awkwardly or slowly.
- HANA-specific functions (e.g. special text, spatial or statistical functions).
- Implementations of CDS table functions (Part 3).
- Proven performance gains — measured, not assumed.
━━━━━━━━━━━━━━━━━━━━
▶ WHEN NOT
- Simple selects, joins and aggregations → ABAP SQL or CDS.
- Logic needing ABAP features: authorization checks, message handling, calling APIs, RAP — stays in ABAP.
- Anything that must run on non-HANA databases.
━━━━━━━━━━━━━━━━━━━━
▶ RULES FOR EVERY AMDP
- Declare all read objects in USING.
- Handle the client explicitly (SQLScript does not do it for you) — Part 4.
- Use OPTIONS READ-ONLY for read procedures.
- Keep SQLScript set-based; avoid loops and cursors.
✅ CHECKPOINT: you can place AMDP correctly among the pushdown tools. Part 2 creates one.
Code example
" ===== 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, testableReal 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.
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.
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.
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
1. A nightly ABAP job reads 30 million line items to the application server only to sum them per customer. What is the simplest improvement?
2. Which interface marks an ABAP class as an AMDP container for SAP HANA?
3. When is AMDP most justified?
Interview questions
1. A guideline requires all reporting logic in AMDP "for HANA performance". How do you respond?
Answer it in your own words first, then compare.
2. What is AMDP, and where does it fit among the code pushdown options?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.