AMDP
RAP / CDS / ODataadvanced

AMDP Part 5: Debugging, Testing and Performance Analysis

Key takeaway

Troubleshoot AMDP across two runtimes: debug SQLScript in ADT, analyze runtime errors, test AMDP logic with ABAP Unit, and find performance bottlenecks with SQL trace and HANA plan analysis.

Explanation

📌 KEY POINTS
✅ ADT has an AMDP debugger: set a breakpoint in the SQLScript and inspect table variables.

✅ Runtime errors surface in ABAP as CX_AMDP_* exceptions / dumps with the database error text.

✅ Test AMDP through its ABAP interface with ABAP Unit and controlled data.

💡 Performance: ST05 for time, PlanViz/explain plan for the costly operator.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Parts 1–4 built correct AMDPs. When something goes wrong, you work across ABAP and HANA. This part gives the method and tools.

━━━━━━━━━━━━━━━━━━━━
▶ 1. THE AMDP DEBUGGER

  • Open the AMDP class in ADT and set a breakpoint on a line inside the SQLScript (the debugger must be enabled for AMDP in your user settings/system — ADT asks on first use).
  • Run the ABAP caller; the debugger stops in SQLScript.
  • Inspect scalar variables and table variables (lt_items) — row counts and content.
  • Step through statements to see which step produces unexpected data.

━━━━━━━━━━━━━━━━━━━━
▶ 2. RUNTIME ERRORS

  • Errors in SQLScript (division by zero, conversion errors, missing objects) raise exceptions such as CX_AMDP_EXECUTION_ERROR in ABAP; uncaught, they dump (ST22) with the HANA error text.
  • Catch them in the caller where meaningful, and log with context (input parameters).
  • Activation errors (syntax, USING missing, type mismatch) appear directly in ADT.

━━━━━━━━━━━━━━━━━━━━
▶ 3. TESTING

  • Test the AMDP through its ABAP method with ABAP Unit.
  • Isolate data: depending on release, test doubles for AMDP dependencies are limited; practical options are dedicated test data in a test client, or wrapping the logic in a CDS table function and testing via the CDS Test Double Framework (CDS Table Functions Part 5).
  • Compare with a reference: run an ABAP SQL version of the same logic on the same data and compare results.
  • Cover: empty input, NULL handling, client isolation, boundary values.

━━━━━━━━━━━━━━━━━━━━
▶ 4. PERFORMANCE ANALYSIS

  • ST05 (SQL trace): the call of the procedure and its statements, runtime and rows.
  • SAT (ABAP profiling): share of time in the AMDP vs ABAP.
  • HANA PlanViz / explain plan: which operator (join, window function, aggregation) costs most, and row counts at each step.
  • Typical fixes: filter earlier, avoid loops/cursors, reduce columns, avoid functions on join columns, check that input tables are small.

━━━━━━━━━━━━━━━━━━━━
▶ 5. A REPEATABLE INCIDENT METHOD

  1. Capture the input parameters of the failing call.
  2. Reproduce in DEV/QAS with the same input.
  3. Debug SQLScript step by step or trace performance.
  4. Fix, add a unit test for the case, re-measure.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Set a breakpoint in totals_for_customers and inspect lt_items.
  2. Force a division by zero; catch CX_AMDP_EXECUTION_ERROR in the caller.
  3. Write an ABAP Unit test comparing AMDP and ABAP SQL results.
  4. Trace one call with ST05 and note the runtime.

✅ CHECKPOINT: you can debug, test and profile AMDP code.

Code example

ABAP Code
" ===== 1. Catch AMDP runtime errors in the caller =====TRY.    zcl_sales_amdp=>totals_for_customers(      EXPORTING it_customers    = customers                iv_company_code = company_code      IMPORTING et_totals       = DATA(totals) ).  CATCH cx_amdp_execution_error INTO DATA(amdp_error).    " log with context - the text contains the HANA error message    DATA(text) = amdp_error->get_text( ).    " e.g. write to application log with company_code and number of customersENDTRY. " ===== 2. ABAP Unit: compare AMDP result with an ABAP SQL reference =====CLASS ltc_totals DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.  PRIVATE SECTION.    METHODS amdp_matches_abap_sql FOR TESTING.ENDCLASS. CLASS ltc_totals IMPLEMENTATION.  METHOD amdp_matches_abap_sql.    DATA(customers) = VALUE zcl_sales_amdp=>tt_customers( ( customer = 'C100' ) ).     zcl_sales_amdp=>totals_for_customers(      EXPORTING it_customers = customers  iv_company_code = '1010'      IMPORTING et_totals    = DATA(amdp_result) ).     SELECT SUM( net_amount ) FROM zsales_item      WHERE customer = 'C100' AND company_code = '1010'      INTO @DATA(reference).     cl_abap_unit_assert=>assert_equals(      act = amdp_result[ 1 ]-amount      exp = reference      msg = 'AMDP total differs from ABAP SQL reference' ).  ENDMETHOD.ENDCLASS." (runs on the test data of the client - keep dedicated, stable test data) " ===== 3. Debug & performance tools =====" ADT: breakpoint inside SQLScript -> inspect :lt_items (rows, values)" ST22: dumps with CX_AMDP_* and HANA error text" ST05: SQL trace of the procedure call (time, rows)" SAT : share of runtime in AMDP vs ABAP" PlanViz / explain plan: most expensive operator

Real project scenario

A nightly job calling an AMDP dumped once a week with a conversion error. The dump showed only the HANA message. The team captured the input parameters in an application log before the call and reproduced the failing case in QAS within an hour.
In the AMDP debugger, the table variable showed one item with a malformed date string from a data migration. The SQLScript was hardened with a safe conversion and a filter, a unit test was added for the case, and the migration team corrected the data.

Common mistakes

  • Debugging only on the ABAP side.
  • Not logging input parameters of failing AMDP calls.
  • Letting CX_AMDP exceptions dump without context.
  • No automated tests for AMDP logic.
  • Performance tuning without traces or plans.
  • Testing only with tiny data sets.

Best practices

  • Use the ADT AMDP debugger and inspect table variables.
  • Catch and log AMDP exceptions with input context.
  • Test AMDP via ABAP Unit, compare with ABAP SQL references.
  • Analyze performance with ST05, SAT and PlanViz.
  • Add a test for every fixed incident.

Interview angle

Questions: "How do you debug an AMDP?", "How do you handle AMDP runtime errors?", "How do you test and tune AMDP?"
Strong answer: set breakpoints in SQLScript with the ADT AMDP debugger and inspect table variables; catch CX_AMDP_EXECUTION_ERROR (and related) in the caller and log inputs; test through the ABAP method with ABAP Unit and stable test data or via CDS table functions and test doubles, comparing with ABAP SQL references; tune using ST05, SAT and PlanViz/explain plan.

Practice this lesson

Quick check

1. A month-end job spends 40 minutes in one AMDP. What is the best first analysis step?

2. In the method implementation of an AMDP, how is the target database procedure language declared in the method signature?

3. Which statement best describes debugging support for AMDP methods executed on SAP HANA?

Interview questions

1. How do you test and tune AMDP code?

Answer it in your own words first, then compare.

2. A nightly job calling an AMDP dumps occasionally with a database error. How do you analyze it?

Answer it in your own words first, then compare.

Practice more with Interview AI →

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.

More lessons in this topic

Interview questions on this topic

Related SAP topics