ERPClimb logoERPClimb
AMDP
RAP / CDS / ODataintermediate 9 min read

AMDP Part 3: Procedures, Functions and Table Function Implementations

Preview · a free account unlocks the full lesson

Key takeaway

Know the three kinds of AMDP methods — procedures, scalar/table functions and CDS table function implementations — their syntax, how they are called, and when to use each.

In this lessonShow sections

Visual overview

AMDP Part 3: Procedures, Functions and Table Function Implementations — learning sheetIn one line: Know the three kinds of AMDP methods — procedures, scalar/table functions and CDS table function implementations — their syntax, how they are called, and when to use each.ERPClimb.com / RAP / LESSON 3/6 / LEARNING SHEETAMDP Part 3: Procedures, Functions and Table FunctionImplementations1 · IN ONE LINEKnow the three kinds of AMDP methods — procedures, scalar/table functions and CDS tablefunction implementations — their syntax, how they are called, and when to use each.2 · KEY IDEAS EXPLAINEDAMDP ProcedureSyntax: METHOD m BY DATABASE PROCEDURE FOR HDBLANGUAGE SQLSCRIPT [OPTIONS READ-ONLY] USING …Signature: IMPORTING and EXPORTING (and CHANGING)parameters, all passed BY VALUE; no RETURNING.AMDP Function (Scalar Or Table)Syntax: METHOD f BY DATABASE FUNCTION FOR HDBLANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING …Signature: IMPORTING parameters and a RETURNINGparameter (a table type or, for scalar functions,an elementary type).CDS Table Function ImplementationCLASS-METHODS m FOR TABLE FUNCTION ztf_… —signature comes from the CDS definition.Implemented BY DATABASE FUNCTION; returns the CDS"returns" structure.Which One?A result needed by an ABAP program only →procedure (or better: ABAP SQL/CDS).A result needed by CDS, services or analytics →CDS table function.3 · DO · AVOIDBest practice!Common mistakeProcedures for ABAP callers, functions forreuse, table functions for CDS consumers.READ-ONLY by default.List every used table, view and AMDP in USING.✕Trying to call an AMDP function directly fromABAP.✕Forgetting to list called AMDPs in USING.✕Using RETURNING in procedures or EXPORTING infunctions.4 · IN A REAL PROJECTThree AMDP procedures in a project each contained the same 30-line SQLScript block that determined "openitems per customer", with small differences that produced inconsistent numbers across reports. The blockwas extracted into one AMDP table function and called from the three procedures (listed in their USING…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

An AMDP procedure is called from ABAP like a method and can have several IMPORTING and EXPORTING parameters. An AMDP function, declared BY DATABASE FUNCTION, returns a single result and is meant to be called from other AMDPs rather than directly from ABAP. A FOR TABLE FUNCTION implementation backs a CDS table function and is consumed through that CDS entity. You can reuse SQLScript logic by calling AMDP functions or procedures inside other AMDPs, listing them in the USING clause.

Part 2 built a single procedure; AMDP actually offers three flavors, and picking the right one is what keeps the code reusable.

The AMDP procedure uses the syntax METHOD m BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT, optionally with OPTIONS READ-ONLY, followed by USING. Its signature consists of IMPORTING, EXPORTING and CHANGING parameters, all passed BY VALUE, with no RETURNING parameter. It's called from ABAP exactly like any static or instance method — zcl_x=>m( EXPORTING … IMPORTING … ) — and can read, and without READ-ONLY even write, database tables, though writing is rare and needs strong justification. A procedure can also call other AMDP procedures.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

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.