🛠️

Lecture on AMDP Table and Scalar Functions

Jul 17, 2024

Lecture on AMDP Table and Scalar Functions

Introduction

  • AMDP Framework: Manages database processors and functions from ABAP.
  • AMDP Procedure: Manages database procedures.
  • AMDP Functions: Manages database functions.

Types of AMDP Functions

  1. Scalar Functions: Return single elementary data type values.
  2. Table Functions: Return table type values.

AMDP Table Functions

  • Definition: Functions created to return table format data.
  • Categories:
    • For CDS table functions.
    • For calling inside another AMDP procedure or function.

Key Points About AMDP Table Functions

  • Always return a table.
  • Declaration involves importing and returning parameters.
  • Cannot be directly called in ABAP programs.
  • They are read-only; cannot change or update database data.
  • Can be called inside other AMDP functions/procedures.

Implementation Example

  • Procedure Name: get_scar_spfli_table_func
  • Database Options: Read-only.
  • Usage: Using selective import and export parameters.

Calling AMDP Table Functions

  • Cannot call directly in ABAP program; results in runtime error.
  • Can call inside another AMDP procedure using SQL script.

AMDP Scalar Functions

  • Definition: Functions that return single elementary type values (e.g., int, float).
  • Data Types: Fixed or variable length, cannot be structure, table, or reference types.

Key Points About AMDP Scalar Functions

  • Return value must be a simple, elementary data type.
  • Can be directly called in ABAP like a regular method.
  • Useful in where, having clauses, and within SQL script.
  • No changing or output parameters.

Implementation Example

  • Function Name: get_max_flight_time_func
  • Usage: Collect maximum flight time and return it as a scalar value.

Calling AMDP Scalar Functions

  • Can be called directly in ABAP program.
  • Can utilize in SQL script for more complex querying within procedures.

Practical Implementation

  1. Create AMDP Table Functions: Define table functions, declare parameters, and implement SQL script logic for data selection.
  2. Use within Procedures: Create a procedure that calls table functions using the SELECT SQL script statement to get required data.
  3. Calling Scalar Functions: Create scalar functions and utilize them for selective operations and where clauses.
  4. Example Data: SCAR and SPFLI tables for illustrating flight and carrier data.

Use Case Example

  • SPFLI Table: Flight details like carrier ID, connection ID, cities, timings.
  • SCAR Table: Airline carrier details like carrier ID, name, currency, and URL.
  • SQL Script: Demonstrating inner join, selecting fields, ordering data, declaring options and selecting data within procedures.

Conclusion

  • Review of Key Points: Creation and usage of table and scalar functions in AMDP.
  • Practical Scenarios: Examples and practical implementation in ABAP using SQL script.
  • Summary: Emphasizing the importance and methods of using AMDP functions effectively in SAP.

Hope you found this lecture informative and helpful in understanding the usage of AMDP table and scalar functions in SAP.