CDS Views: Table Functions with Example
1.Which supports the additional functionalities which are not supported by CDS.
2.SQL statements will written and will use SQL functions and methodologies.
3.Table function has optional input parameters and return parameters.
4.Needs class and method to define. -Class:Public, Method:Static
5.The statement Interface:IF_AMDP_MARKER_HDB must be use.
1.Creation of Table Function:
Create a Data Definition and select template 'Define Table Function with Parameters'
@EndUserText.label: 'Prod Order TF'
define table function ZVB_TF_PROD_ORD
//with parameters parameter_name : parameter_type
returns {
client : abap.clnt;
Prod_order : aufnr;
order_type : auart;
}
implemented by method zvb_class_tf=>get_ord_details;
2.Creation of Class:
CLASS zvb_class_tf DEFINITION PUBLIC .
PUBLIC SECTION.
CLASS-METHODS:get_ord_details FOR TABLE FUNCTION ZVB_TF_PROD_ORD.
INTERFACES:IF_AMDP_MARKER_HDB.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zvb_class_tf IMPLEMENTATION.
METHOD get_ord_details BY DATABASE FUNCTION FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING AUFK.
return SELECT mandt as client,aufnr as prod_order,auart as order_type from aufk;
ENDMETHOD.
ENDCLASS.
3.Calling Table Function in CDS View:
@AbapCatalog.sqlViewName: 'ZVB_PROD_DET'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Call Table function'
define view ZVB_CALL_TF as select from ZVB_TF_PROD_ORD as a
inner join afko as b on a.Prod_order = b.aufnr
{
a.Prod_order,
a.order_type,
b.aufpl
}
Output:
jjj
3.Calling Table Function in Report Program:
REPORT ZVB_TF_PROGRAM.
SELECT * FROM ZVB_TF_PROD_ORD
INTO TABLE @DATA(LT_ORD)
UP TO 10 ROWS.
cl_demo_output=>display_data( name = 'Student Details' value = lt_ord ).
Comments
Post a Comment