Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
canan_zdemir
Participant

Overview


In this post you will learn, how we can use ‘READ_TEXT’ function for Fiori elements application. Consumption CDS is generating the Fiori elements application but sometimes we need Abap Logic 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.

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.51.7/en-US/a7fc007921d44263b09ccc0923...

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.51.6/en-US/8cbf576babc348668d00b93387...

 

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.

https://blogs.sap.com/2019/11/07/developing-app-with-sap-fiori-elements-list-report-page-object-page...

 

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'}

define view ZI_GOODPACK


  as select from    likp             as l1

    inner join      lips             as l2 on  l2.vbeln = l1.vbeln and l2.pstyv = 'ZPAC'

    left outer join kna1             as k1 on k1.kunnr = l1.kunnr

    left outer join vbfa             as v1 on  v1.vbelv   = l1.vbeln and v1.vbtyp_n = '8'

    left outer join vttk             as v2 on v2.tknum = l1.vbeln

    left outer join /scdl/db_proch_o as t1 on t1.docno = l1.vbeln

    left outer join /scwm/huref      as t2 on t2.docid = t1.docid

    left outer join /scwm/hu_ident   as t3 on  t3.guid_hu = t2.guid_hu and t3.idart   = 'Y'

    left outer join lips             as l3 on l3.vbeln = l1.vbeln

    left outer join vbrp             as v4 on  v4.vgbel = l1.vbeln and v4.vgpos = l3.posnr

    left outer join 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( ''  as abap.char(255))               as note


}

group by

  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( ''  as abap.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.

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/1709%20000/en-US/8dec506e13f949c2a82e8c...

Output



Conclusion


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


References


http://sapabapcentral.blogspot.com/2019/04/fiori-elements-utilizing-cds-with.html

https://blogs.sap.com/2019/04/26/fiori-elements-utilizing-cds-with-virtual-elements

 

Canan Özdemir.
59 Comments
pr285443
Explorer
0 Kudos
Hi cnnozdemir

 

thank you for sharing above information.

Just a quick query, is there any performance degradation if we use Virtual Elements to calculate field value on the fly? Because the calculation logic will be at ABAP Layer(Presentation layer) and not in DB Layer. So, I want to know is it good practise to use Virtual Element or it should be used at extreme scenarios.

Kindly clarify.

 

Regards,
Prince
former_member603752
Discoverer
0 Kudos

If the function takes some parameters, how to implement that? I am trying to use the UKM_COMMTS_BUPA_DISPLAY function in CDS to get the credit exposure value, but can't solve it.

ankit_gusain
Explorer
0 Kudos
What about input field? I want to get this virtual element as an input field.
ratnakarj
Newcomer
0 Kudos
Hi

Can u please suggest on fiori list report how label/text can be added to aggregated value :

bhaskar_nagula
Participant
0 Kudos
Thank You canan.zdemir for your explanation.

Could you please let me know how to debug this? for me the class is not getting triggered.
irfan_gokak
Contributor
0 Kudos
Hi cnnozdemir

 

Thanks for the blog. Is it possible to read text more than 1333 length. Because char type is not allowing to read text with length more than 1333. Any suggestion please?

Regards,
Irfan G
trusadi
Participant
0 Kudos

Hi,

Thanks for this great blog.

I have tried this by following the steps above. But I realized that the virtual element field will always be a "Read only" field.

Just want to know if possible to use this virtual element to input new data and save it into custom table during saving for that particular entity data.

 

Thanks

TJ

saudshaikh
Explorer
0 Kudos

@Sandra_Rossi, in your suggested code for GET_CALCULATION_INFO, element SPRAS is added to method parameter 'et_requested_orig_elements'. Won't this result into a Runtime Error as the respective Entity ZI_GOODPACK does not have this element?

mathieu_l1
Participant
0 Kudos

I've tried to extend CDS view C_JournalEntryItemBrowser with a virtual element, as described in this blog post, but the code calculating the virtual element is not called.

Is there any CDS annotation preventing code execution ? The OData service is published and active.

Labels in this area