When to use CDS table function?





@EndUserText.label : 'Employee table'
@AbapCatalog.enhancementCategory : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zemployee_ram {
  key client : mandt not null;
  key id     : zid not null;
  name       : zname;
  age        : zage;

}


@EndUserText.label : 'Employee table'
@AbapCatalog.enhancementCategory : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zemployee_salary {
  key client : abap.clnt not null;
  key id     : int4 not null;
  @Semantics.amount.currencyCode : 'zemployee_salary.curky'
  salary     : abap.curr(10,2);
  curky      : abap.cuky;

}


@EndUserText.label: 'ZDdls_sample_08_cds_tab_fun'
define table function Zddls_Sample_08_Cds_Tab_Fun
with parameters 
   @Environment.systemField: #CLIENT
   client : abap.clnt
returns {
  client : abap.clnt;
  id      :char10;
  name       : char50;
  age        : zage_r;
  salary     : abap.curr(10,2);
  curky      : abap.cuky;
}
implemented by method Zddls_smple_08_tab_fun=>emp_detail;


//@AbapCatalog.viewEnhancementCategory: [#NONE]
//@AccessControl.authorizationCheck: #NOT_REQUIRED
//@EndUserText.label: 'ZDdls_sample_08_cds_tab_fun'
//@Metadata.ignorePropagatedAnnotations: true
//@ObjectModel.usageType:{
//    serviceQuality: #X,
//    sizeCategory: #S,
//    dataClass: #MIXED
//}
//define view entity ZDdls_sample_08_cds_tab_fun
//  as select from zemployee_salary as sal 
//  association [1] to zemployee_ram as emp 
//  on emp.id = $projection.sal_id
//{
//  key cast( sal.id  as abap.char(20) ) as sal_id,
//    @semantics.amount.currencyCode: 'Curky'
//      sal.salary as Salary,
//      sal.curky as Curky,
//      emp
//  
//
//
//}






















//define view entity ZDdls_sample_08_cds_tab_fun
//  as select from  zemployee_salary as sal
//  association [1] to  zemployee_ram as emp
//         on emp.id =  $projection.sal_id
//{
// key cast ( sal.id as abap.char( 20 ) ) as sal_id,
//     sal.id as Id,
//     @Semantics.amount.currencyCode: 'Curky'
//     sal.salary as Salary,
//     sal.curky as Curky,
//     emp
//
//
//}

//define view entity ZDdls_sample_08_cds_tab_fun
//  as select from zemployee_ram as emp
//  association [1] to zemployee_salary as _sal
//         on emp.id =  $projection.sal_id
//{
// key emp.id as Id,
// emp.name as Name,
// emp.age as Age,
// _sal
//
//}



CLASS zddls_smple_08_tab_fun DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.
    CLASS-METHODS emp_detail
        FOR TABLE FUNCTION zddls_sample_08_cds_tab_fun.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zddls_smple_08_tab_fun IMPLEMENTATION.
  METHOD emp_detail BY DATABASE FUNCTION
                    FOR HDB
                    LANGUAGE SQLSCRIPT
                    USING
                    zemployee_salary
                    zemployee_ram.
    it_result =  select zemployee_ram.client ,
                        zemployee_ram.id,
                        name  ,
                        age,
                        salary,
                        curky
                  from zemployee_ram
                  inner join zemployee_salary
                  on  zemployee_ram.client = zemployee_salary.client
                  and zemployee_ram.id = zemployee_salary.id;

  RETURN :it_result;


  endmethod.

ENDCLASS.

Comments

Post a Comment

Popular posts from this blog

AMDP ( ABAP Managed Database Procedure ) Part - 1

Backup all ADT Objects & Other queries RAP Part 10.1

SAP CDS Introduction Part 2 - ABAP on HANA Course