Sunday, 12 January 2020 11:51

Using Virtual Elements with CDS in Fiori elements

Written by
Rate this item
(1 Vote)
calculation. (Calculate field values using Abap resources one of them read text belongs to material or orders etc.).

In this case, we can use the CDS with Virtual Element.

What are the Virtual Elements and Why we use that?

Sometimes when we make a report, we need calculations for fields and we can not easily make calculations with CDS so that their values can be calculated directly on SAP HANA. Virtual elements represent temporary fields in applications. They are defined consumption CDS view with annotations within the SELECT list. However, the field calculations display by Abap classes that implement the specific code exit interfaces provided for this purpose.

The code exit class for virtual elements. We should implement suitable interfaces according to the use case;

You can find more information about Virtual Element with Sap standard documents link.

Implementation Steps:


  1. Use Eclipse for creating CDS View. Use Virtual element in CDS with annotations.

You can find more information about create the CDS View for beginners.

CDS View;

@AbapCatalog.sqlViewName: 'ZI_V_GOODPACK' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Goodpack Series No - Basic View' @OData: { publish: true } @UI.headerInfo:{ typeNamePlural: 'GoodPack'} defineview ZI_GOODPACK   asselectfrom    likp             as l1     innerjoin      lips             as l2 on  l2.vbeln = l1.vbeln and l2.pstyv = 'ZPAC'     leftouterjoin kna1             as k1 on k1.kunnr = l1.kunnr     leftouterjoin vbfa             as v1 on  v1.vbelv   = l1.vbeln and v1.vbtyp_n = '8'     leftouterjoin vttk             as v2 on v2.tknum = l1.vbeln     leftouterjoin /scdl/db_proch_o as t1 on t1.docno = l1.vbeln     leftouterjoin /scwm/huref      as t2 on t2.docid = t1.docid     leftouterjoin /scwm/hu_ident   as t3 on  t3.guid_hu = t2.guid_hu and t3.idart   = 'Y'     leftouterjoin lips             as l3 on l3.vbeln = l1.vbeln     leftouterjoin vbrp             as v4 on  v4.vgbel = l1.vbeln and v4.vgpos = l3.posnr     leftouterjoin vbrk             as v5 on  v5.vbeln = v4.vbeln and sfakn    = '' {       @UI: { lineItem: [ { position: 10, label: 'Delivery'} ]}   key l1.vbeln,       @UI.hidden: false       @UI.selectionField: [{ position: 10 }]       @Consumption.valueHelpDefinition:[{entity:{name:'ZI_VKORGSH',element:'vkorg'}}]       @Consumption.filter : { selectionType : #RANGE, multipleSelections : true, defaultValue : '1250'}       l1.vkorg,       @UI.hidden: false       @UI.selectionField: [{ position: 20 }]       @Consumption.valueHelpDefinition:[{entity:{name:'ZI_WERKSSH',element:'werks'}}]       l1.werks,       @UI: { lineItem: [ { position: 20, label: 'Customer'} ]}       @UI.selectionField: [{ position: 30 }]       @Consumption.valueHelpDefinition:[{entity:{name:'ZI_KUNNRSH',element:'kunnr'}}]       l1.kunnr,       @UI: { lineItem: [ { position: 30, label: 'Customer Name'} ]}       concat( concat( k1.name1, ' '), k1.name2 )as name1,       @UI: { lineItem: [ { position: 40, label: 'Delivery Note'} ]}       l1.xblnr,       @UI: { lineItem: [ { position: 40, label: 'Container ID'} ]}       v2.signi,       @UI: { lineItem: [ { position: 50, label: 'Actual Goods Movement Date'} ]}       l1.wadat_ist,       @UI: { lineItem: [ { position: 60, label: 'Material Number'} ]}       l2.matnr,       @UI: { lineItem: [ { position: 70, label: 'Short text for sales order item'} ]}       l2.arktx,       @UI: { lineItem: [ { position: 80} ]}       v1.vbeln                                   as vbfa_vbeln,       @UI: { lineItem: [ { position: 90} ]}       t4.konsimento_tarih,       @UI: { lineItem: [ { position: 100} ]}       t4.konsimento_no,       @UI: { lineItem: [ { position: 110, label: 'Virtual Element'} ]}       @ObjectModel.virtualElement: true       @ObjectModel.virtualElementCalculatedBy: 'ZCL_DEMO_CDS_CALC'       cast( ''  asabap.char(255))               as note }groupby   l1.vbeln,   l1.vkorg,   l1.werks,   l1.kunnr,   k1.name1,   k1.name2,   l1.xblnr,   l1.wadat_ist,   l2.matnr,   l2.arktx,   v1.vbeln,   v2.signi,   t2.guid_hu,   t3.huident,   t4.konsimento_tarih,   t4.konsimento_no

Define relationship with CDS, ODATA and Custom Class.

2. Create custom class and implement intarface ‘IF_SADL_EXIT_CALC_ELEMENT_READ’.   Implement both methods ‘GET_CALCULATE_INFO’ and ‘CALCULATE’.

  • Method GET_CALCULATION_INFO is used to provide the list of fields which is required for the calculation.
  • Method CALCULATE is actual method where we implement the custom logic.

  • Implementation Step 1 : We called custom class in CDS view.
 @ObjectModel.virtualElement: true @ObjectModel.virtualElementCalculatedBy: 'ZCL_DEMO_CDS_CALC'  cast( ''  asabap.char(255))  as note 
Use the CALCULATE method for utilizing ABAP resource.

3. Use SAP Web IDE for creating List Reporting App.

You can find detail information about List Reporting App.



In this blog, we learn how we can utilize the CDS virtual elements. I welcome all suggestions for improvement or questions. Thanks for reading.


Canan Özdemir.

Read 3476 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.