0% found this document useful (0 votes)
70 views

How To Use AMDP in CDS Table Function

AMDP stands for ABAP Managed Database Procedure, which allows creating and executing database code in ABAP. CDS table functions can use AMDP functions as their implementation. An example shows defining a CDS table function that uses an AMDP function to query data from three tables and return the results.

Uploaded by

1nonlypriyo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

How To Use AMDP in CDS Table Function

AMDP stands for ABAP Managed Database Procedure, which allows creating and executing database code in ABAP. CDS table functions can use AMDP functions as their implementation. An example shows defining a CDS table function that uses an AMDP function to query data from three tables and return the results.

Uploaded by

1nonlypriyo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sure, I can help you with that.

AMDP stands for ABAP Managed Database


Procedure, which is a way to create and execute database-specific code in
ABAP . AMDP functions are implemented as methods of a global class and can
be used to define CDS table functions .
CDS table functions are a type of CDS entity that allow you to define a table-
valued function using an AMDP function as the implementation . CDS table
functions can be consumed by other CDS views or by ABAP programs .
Here is an example of how to use AMDP in CDS table function:
@ClientHandling.type: #CLIENT_DEPENDENT
define table function DEMO_CDS_GET_SCARR_SPFLI_INPCL
with parameters carrid : abap.char(3)
returns {
key carrid : abap.char(3);
key connid : abap.char(4);
key fldate : abap.dats;
key price : abap.curr(15,2);
key currency : abap.cuky(5);
key planetype : abap.char(10);
key seatsmax : abap.int4;
key seatsocc : abap.int4;
key paymentsum : abap.curr(15,2);
}
implemented by method ZCL_DEMO_AMDP=>GET_SCARR_SPFLI_FOR_CDS;
This CDS table function uses the AMDP function
ZCL_DEMO_AMDP=>GET_SCARR_SPFLI_FOR_CDS as the implementation,
which is defined as follows:
CLASS zcl_demo_amdp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb.

CLASS-METHODS get_scarr_spfli_for_cds
FOR TABLE FUNCTION demo_cds_get_scarr_spfli_inpcl
IMPORTING
VALUE(carrid) TYPE /dmo/carrid
EXPORTING
VALUE(result) TYPE /dmo/tt_scarr_spfli_inpcl.

ENDCLASS.

CLASS zcl_demo_amdp IMPLEMENTATION.


METHOD get_scarr_spfli_for_cds BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING /dmo/scarr /dmo/spfli /dmo/sbook.

result = SELECT scarr.carrid, spfli.connid, spfli.fldate,


spfli.price, spfli.currency, spfli.planetype,
spfli.seatsmax, spfli.seatsocc,
SUM( sbook.paysum ) AS paymentsum
FROM /dmo/scarr AS scarr
INNER JOIN /dmo/spfli AS spfli
ON scarr.carrid = spfli.carrid
LEFT OUTER JOIN /dmo/sbook AS sbook
ON spfli.carrid = sbook.carrid
AND spfli.connid = sbook.connid
AND spfli.fldate = sbook.fldate
WHERE scarr.carrid = :carrid
GROUP BY scarr.carrid, spfli.connid, spfli.fldate,
spfli.price, spfli.currency, spfli.planetype,
spfli.seatsmax, spfli.seatsocc;

ENDMETHOD.

ENDCLASS.
This AMDP function uses SQLScript to query data from three tables
(/dmo/scarr, /dmo/spfli, and /dmo/sbook) and returns the result as a table
parameter. The function takes one input parameter (carrid) which is used to
filter the data.
To consume the CDS table function, you can use the following syntax:
"AMDP table function selected via CDS entity
SELECT * FROM demo_cds_get_scarr_spfli_inpcl (carrid = @carrid)
INTO TABLE @DATA (result2) ##db_feature_mode
[amdp_table_function].
ASSERT result1 = result2.
cl_demo_output=>write (result1).
This code snippet selects data from the CDS table function using the input
parameter carrid and stores the result in an internal table result2. The
##db_feature_mode pragma is used to indicate that the CDS entity is an
AMDP table function .
I hope this example helps you understand how to use AMDP in CDS table
function. For more information, you can refer to the following links:
: AMDP Function and CDS Table function | SAP Blogs : AMDP, AMDP Functions
- ABAP Keyword Documentation - SAP Online Help : Table Functions and
AMDP | SAP Help Portal : Consume CDS View inside CDS Table Function by
using AMDP

You might also like