You are on page 1of 6

ABAP CDS Table Function Implemented by

AMDP
December 18, 2017 coderobbot HANA, Uncategorized One comment

ABAP CDS Table Function Implemented by AMDP

ABAP CDS Table Function defines table


function which are native to the database. 
 ->The CDS table function has a set of    input
parameters and a set of return  parameters .
The result is  is a TABULAR format with return
fields.
->Actual implementation happens in a   
AMDP method with a return value
-> Calling CDS Table Function to get the 
result

Step1. Create a DDL Source.


.....
Select Define Table Function with
Parameters.
-> Provide the Input parameter list
-> Provide the return field list
->Provide the [ AMDP ]
CLASS=>METHOD that implements  it. 
->Activate it.
@EndUserText.label: 'Flight CDS with Table Function'
define table function zdemo_flight_cds_tf
with parameters iv_carrid: s_carr_id
returns
{
mandt: s_mandt;
carrid: s_carr_id;
connid: s_conn_id;
countryfr: land1;
cityfrom: s_from_cit;
airpfrom: s_fromairp;
countryto: land1;
cityto: s_to_city;
airpto: s_toairp;
}
implemented by method zcl_demo_flight_calculation=>get_details;

->The method must specify for which


TABLE FUNCTION it is used.
->Implement the AMDP method with
RETURN.

CLASS zcl_demo_flight_calculation DEFINITION PUBLIC FINAL CREATE PUBLIC .


PUBLIC SECTION.Fsp
INTERFACES: if_amdp_marker_hdb.
CLASS-METHODS: get_details FOR TABLE FUNCTION ZDEMO_FLIGHT_CDS_TF.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS zcl_demo_flight_calculation IMPLEMENTATION.


METHOD get_details BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING spfli.
RETURN
SELECT mandt, carrid, connid,
countryfr, cityfrom, airpfrom,
countryto, cityto, airpto
FROM spfli WHERE carrid = iv_carrid;
ENDMETHOD.
ENDCLASS.

Calling the CDS Table Function from


PROGRAM/METHOD with addition :
##db_feature_mode[amdp_table_function]

SELECT *
FROM zdemo_flight_cds_tf( iv_carrid = 'LH' )
INTO TABLE @DATA(lt_flight)
##db_feature_mode[amdp_table_function].
cl_demo_output=>display_data( EXPORTING value = lt_flight ).

Output:
Rate this:

You might also like