S/4HANAadvanced

ABAP Managed Database Procedures (AMDP)

Writing native HANA SQLScript logic callable directly from ABAP for maximum performance code pushdown.

AMDP lets you write a method whose body is HANA SQLScript instead of ABAP. It is the deepest level of code pushdown available.

A CDS view is like a well-defined recipe card the kitchen can follow declaratively; AMDP is handing the kitchen a fully procedural cooking show script with loops and conditional steps, because some dishes genuinely need more elaborate step-by-step logic than a static recipe card alone can express, and you still want it all done in the kitchen (HANA) rather than shipping raw ingredients to the dining room (ABAP layer) to be cooked there.

Key Concepts

1
    CLASS zcl_margin DEFINITION.
      PUBLIC SECTION.
        INTERFACES if_amdp_marker_hdb.
        CLASS-METHODS calculate
          IMPORTING VALUE(iv_year) TYPE gjahr
          EXPORTING VALUE(et_result) TYPE ty_t_margin.
    ENDCLASS.
2
    METHOD calculate BY DATABASE PROCEDURE FOR HDB
                     LANGUAGE SQLSCRIPT
                     USING acdoca.
      et_result = SELECT ... FROM acdoca WHERE gjahr = :iv_year ...;
    ENDMETHOD.
3
The caller invokes it like any other method and never knows the difference.
4
When it is worth it. CDS views cover declarative work: select, join, aggregate, filter. AMDP is for logic that is genuinely procedural — loops, intermediate results, branching — that cannot be written as one declarative statement.
5
Typical cases: complex valuation or margin calculations, statistical forecasting, and iterative algorithms such as a bill-of-material explosion with cycle detection.
6
Why it is fast. The logic runs inside HANA. No rows travel to the application server.
7
    ABAP loop:  4 million rows -> app server memory -> loop -> 40 results
    AMDP:       runs in HANA -> 40 results returned
8
On large volumes that is the difference between minutes and seconds, and between needing a large application server and not.
9
Table functions. An AMDP can be exposed as a CDS table function, so its result is usable in further Open SQL and CDS views — combining procedural logic with the declarative layer.
10
The honest trade-offs, which is what a senior answer includes.
11
It is a different language. SQLScript is not ABAP. Different syntax, different idioms, and debugging happens with HANA tooling rather than the ABAP debugger.
12
It is tied to HANA. Open SQL and CDS run on any supported database; an AMDP does not. For S/4HANA that is academic, since HANA is required anyway — but it matters for code meant to be portable.
13
It is harder to test and maintain. Fewer people on a team can read it, and it does not benefit from ABAP's static checks in the same way.
14
So it is a last step, not a default. Open SQL for ordinary access, CDS views for reusable models and aggregation, AMDP only when profiling shows a genuinely heavy computation that neither expresses well. Reaching for AMDP first produces code that is fast, unusual, and a burden on whoever inherits it.
15
What the interviewer is probing.1. "When would you use AMDP over a CDS view?" Probing: the fit. Stalls: "They are the same." Moves up: when the logic needs imperative SQLScript — loops, temporary tables, procedural steps — that a CDS view cannot express.
16
2. "What is the portability cost?" Probing: the trade. Stalls: "None." Moves up: it contains native HANA SQLScript, so it ties the code to HANA — the class declares the database explicitly for that reason.
17
3. "How is it managed as a repository object?" Probing: the advantage. Stalls: "It is not." Moves up: the procedure lives in an ABAP class method and is created in the database on first call, so it transports like normal ABAP.
18
4. "What is hard about debugging one?" Probing: honesty. Stalls: "Nothing." Moves up: the ABAP debugger cannot step into it — you need SQLScript debugging in ADT or logging to a table.