ABAP CDS Table Function Implemented by AMDP

light111ABAP 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.

1

. . . . .

Select Define Table Function with Parameters.

2

-> Provide the Input parameter list

-> Provide the return field list

->Provide the [ AMDP ] CLASS=>METHOD that implements  it. 

->Activate it.

3


 @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.

4


 CLASS zcl_demo_flight_calculation DEFINITION PUBLIC FINAL CREATE PUBLIC .
 PUBLIC SECTION.
 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]

5


 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:

6


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s