Posts

Showing posts from April, 2023

When to use CDS table function?

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

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

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

CDS Unit and Currency Conversion Function Part 15 ABAP on HANA Course

Image
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Left outer join cardinality' @Metadata.ignorePropagatedAnnotations: true @ObjectModel.usageType:{     serviceQuality: #X,     sizeCategory: #S,     dataClass: #MIXED } define view entity ZDDLS_SAMPLE_04   as select from vbak   association [0..1] to vbap as _item    on vbak.vbeln = _item.vbeln   with default filter _item.netwr > 500 {   key vbak.vbeln as so,       @EndUserText.label: 'Customer'       @EndUserText.quickInfo: 'Customer Info'       vbak.kunnr,       vbak.waerk,       vbak.vkorg,       vbak.vbtyp,       @Semantics.amount.currencyCode: 'waerk'       vbak.netwr,                        _item.posnr,       _item.matnr, ...

Path Expression in CDS association PART 12 ABAP on HANA Course

Image
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'path expresson' @Metadata.ignorePropagatedAnnotations: true @ObjectModel.usageType:{     serviceQuality: #X,     sizeCategory: #S,     dataClass: #MIXED } define view entity ZDDLS_SAMPLE_06   as select from vbak   association [1..*] to vbap as _item on vbak.vbeln = _item.vbeln   association [1..1] to kna1 as _cust on vbak.kunnr = _cust.kunnr   association [1..*] to makt as _matdesc on $projection.matnr = _matdesc.matnr   association [0..*] to vbfa as _docflow on vbak.vbeln  = _docflow.vbelv {   key vbeln as so,       kunnr,       _item.posnr,       _item.matnr,       _cust[inner].name1,       _docflow,       _matdesc        } /* source._assoc1[parameter/properties]._assc2.field cardinality join filter condit...

Association to Inner Join CDS PART 11 ABAP on HANA Course

Image
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Inner join' @Metadata.ignorePropagatedAnnotations: true @ObjectModel.usageType:{     serviceQuality: #X,     sizeCategory: #S,     dataClass: #MIXED } define view entity ZDDLS_SAMPLE_05   as select from ZDDLS_SAMPLE_04._item as item   association[*] to makt as _matdesc      on item.matnr = _matdesc.matnr   association[*] to vbfa as _docflow      on item.vbeln = _docflow.vbelv      and item.posnr = _docflow.posnv      and _docflow.vbtyp_v = 'C'      and _docflow.vbtyp_n = 'M'   {       vbeln,  posnr,  matnr,  _matdesc[spras = 'E'].maktx,  _docflow[inner].vbeln as invoice,  _docflow[inner].posnn } where vbeln = '0000000149' or       vbeln = '0000000011'      

Cardinality left outer join CDS Part 8 ABAP on HANA Course

Image
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Left outer join cardinality' @Metadata.ignorePropagatedAnnotations: true @ObjectModel.usageType:{     serviceQuality: #X,     sizeCategory: #S,     dataClass: #MIXED } define view entity ZDDLS_SAMPLE_04   as select from vbak   association [0..1] to vbap as _item    on vbak.vbeln = _item.vbeln   with default filter _item.netwr > 500 {   key vbak.vbeln as so,       @EndUserText.label: 'Customer'       @EndUserText.quickInfo: 'Customer Info'       vbak.kunnr,       vbak.waerk,       vbak.vkorg,       vbak.vbtyp,       @Semantics.amount.currencyCode: 'waerk'       vbak.netwr,                        _item.posnr,       _item.matnr, ...

CDS View entity with join and literals Part 6 ABAP on HANA Course

Image
*&---------------------------------------------------------------------* *& Report z_cds_cunsumption *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT z_cds_cunsumption. SELECT *  FROM zcds_sample_01  INTO TABLE @DATA(it_result). IF sy-subrc IS INITIAL.   cl_demo_output=>display( it_result ). ENDIF. *cl_salv_gui_table_ida=>create_for_cds_view( *  EXPORTING *    iv_cds_view_name      = 'ZDDLS_SAMPLE_04' **    io_gui_container      = **    io_calc_field_handler = **  RECEIVING **    ro_alv_gui_table_ida  = *)->fullscreen( )->display( ). *CATCH cx_salv_ida_contract_violation.. *CATCH cx_salv_db_connection. *CATCH cx_salv_db_table_not_supported. *CATCH cx_salv_ida_contract_violation. *CATCH cx_salv_function_not_supported. *cl_dd_ddl_annotation_service=>g...

◾CDS view entities vs DDIC-based CDS views Part 4 ABAP on HANA Course

Image
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Define view entity' @Metadata.ignorePropagatedAnnotations: true @ObjectModel.usageType:{     serviceQuality: #X,     sizeCategory: #S,     dataClass: #MIXED } define view entity ZDDLS_SAMPLE_02   //with parameters   //                @Environment.systemField: #SYSTEM_DATE   //                 p_date : abap.dats   as select from vbak as head   association [1..*] to vbap as _item on head.vbeln = _item.vbeln {   key head.vbeln as so,       head.vkorg as sales__org,       head.vkgrp,       head.vbtyp as doc_type,       head.erdat,       head.bstnk,       @Semantics.amount.currencyCode: 'waerk'       head.netwr,       head.w...

SAP CDS Introduction Part 2 - ABAP on HANA Course

Image
Code :- @AbapCatalog.sqlViewName: 'ZVSQL_SAMPLE_01' @EndUserText.label: 'This is my fist DDIC based CDS' @AbapCatalog.preserveKey: true @AbapCatalog: {     buffering: {         status:#SWITCHED_OFF,         type: #NONE,         numberOfKeyFields: 000     },     viewEnhancementCategory: [#PROJECTION_LIST,#UNION],     compiler: {         compareFilter: true     },     dataMaintenance: #RESTRICTED } @AccessControl.authorizationCheck: #CHECK @ClientHandling: {     type: #INHERITED,     algorithm:#SESSION_VARIABLE } define view zcds_sample_01 --( SO, Kunnr, curr,netwr,clnt,sydate,syslang)   as select from vbak   association [1..*] to vbap as _item on vbak.vbeln = _item.vbeln {   key   vbeln                    as so,         kunnr  ...

CTE( Common Table Expressions) in ABAP SQL -Open SQL Enhancement ABAP o...

Image
*&---------------------------------------------------------------------* *& Report zr_opensql_26_cte *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_26_cte. *◾A common table expression creates a temporary tabular result *set, which can be accessed during execution of the WITH statement. *Common table expressions can therefore be thought of as temporary views, *which only exist for the duration of the database access *CTE create tabular result set via subquery *which can be used in subsequent queries *When subtotal require ++ instead of GTT we can use *Name should start with + *Optional name list WITH +aggr( mark,so,cust_id,curre,net_amount,so_count ) AS (                  SELECT                  FROM vbak                 ...

Union and Union all in Select - Open SQL Enhancement ABAP on HANA - Part 13

Image
*&---------------------------------------------------------------------* *& Report zr_opensql_20_unioon_grp_by *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_20_having_union. SELECT  FROM vbak AS so  INNER JOIN kna1 AS cust  ON so~kunnr = cust~kunnr  FIELDS so~kunnr AS cust_id,         cust~name1 AS customer,         so~waerk AS curre,         SUM( so~netwr ) AS tot_netprice,         AVG( so~netwr ) AS net,         MAX( so~netwr ) AS max,         MIN( so~netwr  ) AS min,         COUNT( so~netwr ) AS count,         'Importet CUSSTOMER' AS cat_cust  GROUP BY so~kunnr,so~waerk,cust~name1  HAVING SUM( so~netwr ) > 10000 UNION  SELECT  FROM vbak AS s...

Having Clause in Select - Open SQL Enhancement ABAP on HANA - Part 12

Image
*&---------------------------------------------------------------------* *& Report zr_opensql_20_unioon_grp_by *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_20_having_union. SELECT  FROM vbak AS so  INNER JOIN kna1 AS cust  ON so~kunnr = cust~kunnr  FIELDS so~kunnr AS cust_id,         cust~name1 AS customer,         so~waerk AS curre,         SUM( so~netwr ) AS tot_netprice,         AVG( so~netwr ) AS net,         MAX( so~netwr ) AS max,         MIN( so~netwr  ) AS min,         COUNT( so~netwr ) AS count,         'Importet CUSSTOMER' AS cat_cust  GROUP BY so~kunnr,so~waerk,cust~name1  HAVING SUM( so~netwr ) > 10000 UNION  SELECT  FROM vbak AS s...

COALESCE function in Select - Open SQL Enhancement ABAP on HANA - Part 7

 *&---------------------------------------------------------------------* *& Report zr_opensql_11_coalesce_t *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_11_coalesce_t. SELECT  FROM vbak AS so  LEFT OUTER JOIN vbfa AS flow  ON flow~vbelv = so~vbeln  AND flow~vbtyp_v = 'C'  AND flow~vbtyp_n = 'M'  LEFT OUTER JOIN vbrk AS inv   ON inv~vbeln = flow~vbeln   FIELDS so~vbeln AS sales_order,          so~netwr AS so_amount,          inv~netwr AS inv_amount,          CASE WHEN inv~netwr IS NOT NULL  THEN  inv~netwr          ELSE so~netwr          END AS amount_net,          COALESCE( inv~netwr , so~netwr ) as amount_co   INTO TABLE @DATA(it_result). ...

Case statement in Select - Open SQL Enhancement ABAP on HANA - Part 6

 *&---------------------------------------------------------------------* *& Report zr_opensql_10_case_t *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_10_case_t. SELECT  FROM vbak  FIELDS vbeln AS sales_order,         CASE vbtyp            WHEN 'C' THEN 'Order'            WHEN 'B' THEN 'Quotation'            WHEN 'H' THEN 'Returns'            ELSE 'Other Docs'            END AS document_category,            netwr AS net_amount,         CASE          WHEN netwr > 1000 THEN 'Higher amount document'          WHEN ( netwr > 500 AND netwr < 1000 ) THEN 'Medium amou...

String Operation in Select - Open SQL Enhancement ABAP on HANA - Part 5

 REPORT zr_opensql_18_sql_fun_string. *CONCAT,CONCAT_WITH_SPACE 3,length,instr,left,right,lpad3,rpad3,ltrim,rtrim *replace,lower,upper,substring3 *demo_expressions CLASS demo DEFINITION.   PUBLIC SECTION.     CLASS-METHODS main. ENDCLASS. CLASS demo IMPLEMENTATION.   METHOD main.     DELETE FROM demo_expressions.     INSERT demo_expressions FROM TABLE @( VALUE #( (  id = 1 char1 = ' 0123' char2 = 'aAaA ')  ) ).     SELECT      FROM demo_expressions      FIELDS char1 AS text1,             char2 AS text2,             concat( char1, char2 ) AS concat,             concat_with_space( char1, char2 , 1 ) AS concat_with_space,             length( char1 ) AS length,             instr( char1, '12' ) AS instr,             left(...

Aggregation expression in Select - Open SQL Enhancement ABAP on HANA - Part 4

 *&---------------------------------------------------------------------* *& Report zr_opensql_01_aggregation_t *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_01_aggregation_t. *Use case only n select list *Use case in select list and grp by SELECT  FROM vbak AS so  INNER JOIN vbap AS item  ON so~vbeln = item~vbeln  INNER JOIN kna1 AS cust  ON so~kunnr = cust~kunnr  FIELDS so~kunnr AS cust_id,         cust~name1 AS customer,         item~waerk AS curre,         ( item~netpr + 1 )  AS two,         SUM( item~netpr ) AS tot_netprice,         AVG( item~netpr ) AS net,         MAX( item~netpr ) AS max,         MIN( item~netpr  ) AS min,         COUNT( i...

Arithmetic expression in Select - Open SQL Enhancement ABAP on HANA - Part 3

 *&---------------------------------------------------------------------* *& Report zr_opensql_04_arith_express_t *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_04_arith_express_t. *sql_exp - sql_num_func *,CEIL , Floor ,abs,round(2),DIV,MOD DATA : lv_discount TYPE p DECIMALS 1 VALUE '0.8'. SELECT  FROM vbak AS so  INNER JOIN vbap AS item  ON so~vbeln = item~vbeln  INNER JOIN kna1 as cust  on so~kunnr = cust~kunnr  FIELDS so~vbeln AS sales_order,         so~kunnr as cust_id,         cust~name1 as customer,         item~posnr AS sales_item,         item~netpr AS net_price,         item~netpr * @lv_discount AS net_discounted,         ceil( item~netpr ) AS ceil,         floor( ite...

Literals in select field list - Open SQL Enhancement ABAP on HANA - Part 2

 *&---------------------------------------------------------------------* *& Report zr_opensql_02_literals_t *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_02_literals_t. DATA: lv_matnr TYPE matnr. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.   SELECT-OPTIONS: s_matnr FOR lv_matnr. SELECTION-SCREEN END OF BLOCK b1. *SFDC* DATA: lr_matnr  TYPE RANGE OF matnr,       lt_matnr2 TYPE RANGE OF matnr,       ls_matnr  LIKE LINE OF lr_matnr. ls_matnr-sign = 'I'. ls_matnr-option = 'CP'. ls_matnr-low = 'SFDC*'. APPEND ls_matnr TO lr_matnr. SELECT 'I' AS sign,        `EQ` AS option,         1 as number,        matnr AS low,        ' '  AS high  FROM mara  INTO TABLE @data(lt_matnr3)  UP TO 10 ROWS...

Open SQL Enhancement ABAP on HANA - Part 1

 *&---------------------------------------------------------------------* *& Report zr_opensql_00_syntax_t *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zr_opensql_00_syntax_t. TYPES: BEGIN OF ty_so_amount,          so_id           TYPE snwd_so-so_id,          currency_code   TYPE snwd_so-currency_code,          gross_amount    TYPE snwd_so-gross_amount,          delivery_status TYPE snwd_so-delivery_status,        END OF ty_so_amount. DATA lt_so_amount TYPE STANDARD TABLE OF ty_so_amount. * **"using the "old" Open SQL syntax SELECT so_id        currency_code        gross_amount        delivery_status   FROM snwd_so   ...