CDS Table Function and AMDP framework Part 16 ABAP on HANA Course




@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 zcl_my_first_tab_fun DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.

    CLASS-METHODS: get_so_header
           FOR table FUNCTION Zddls_My_First_Cds_Table_Fun.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_my_first_tab_fun IMPLEMENTATION.
  METHOD get_so_header BY DATABASE FUNCTION
                        FOR HDB
                        LANGUAGE SQLSCRIPT
                        OPTIONS READ-ONLY
                        USING vbak.
   it_vbak = SELECT
       mandt as client,
                 vbeln
                 FROM vbak
                 WHERE mandt = :client1;

    RETURN :it_vbak;
  ENDMETHOD.

ENDCLASS.
**********************************************************************
*&---------------------------------------------------------------------*
*& Report y_cds_table_function
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT y_cds_table_function.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.

  METHOD main.
    DATA(lv_support_amadp) =  cl_abap_dbfeatures=>use_features(
                     EXPORTING
                      requested_features = VALUE #( ( cl_abap_dbfeatures=>amdp_table_function ) )
      ).
*   CATCH cx_abap_invalid_param_value.
    IF lv_support_amadp = 'X'.
      SELECT *
       FROM Zddls_My_First_Cds_Table_Fun
       USING CLIENT '800'
*       CLIENT SPECIFIED  yddls_table_function_01~client_element_name
       INTO TABLE @DATA(it_tab).
      IF sy-subrc IS INITIAL.
        DATA(lv_lines) = lines( it_tab ).
        cl_demo_output=>write( lv_lines ).
        cl_demo_output=>display( it_tab ).
      ENDIF.
    ELSE.
      RETURN.
    ENDIF.


  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

Comments

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