cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anything like Virtual elements in ABAP CDS Analytics

Former Member
0 Kudos

I have a requirement to do a complex calculation based on the value of a CDS column. I wanted to use virtual elements but it seems that only works with ODATA apps. Is there anything equivalent to it in the ABAP CDS world for analytics and SALV because IMHO such on the fly calculations are required every where why restrict it to Fiori or is it that I am unaware and there is some trick to get the same functionality. Please help me and thanks in advance for your help.

- Prasenjit

Here’s the sample code:



@AbapCatalog.sqlViewName: 'ZIXINGYTDVIR'

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: 'ZI_XING_YTD Virtual Element' define view ZI_XING_YTD_VIR_ELMNT

with parameters p_fromYear : abap.numc(4),

p_toYear : abap.numc( 4 )

as select from ZI_Xing_YTD( p_fromYear: $parameters.p_fromYear, p_toYear : $parameters.p_toYear )

{ key ROOK_DB_KEY, key Id,

IncidentCount,

IncGroup,

CreateDate,

YearofCreation,

MonthofCreation,

MonthName,

@ObjectModel.readOnly: false

@ObjectModel.virtualElement: true

@ObjectModel.virtualElementCalculatedBy: 'ABAP:ZCL_GRADE_CROSSING_CALC1'

cast( '' as abap.numc( 4 )) as PercentageImprovement,

fatality_ts, fatalitycount,

}

CLASS zcl_grade_crossing_calc1 DEFINITION.

PUBLIC SECTION.

INTERFACES if_sadl_exit .

INTERFACES if_sadl_exit_calc_element_read .

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.

CLASS zcl_grade_crossing_calc1 IMPLEMENTATION.

METHOD if_sadl_exit_calc_element_read~calculate.

CHECK it_original_data IS NOT INITIAL.

DATA: lt_calculated_data TYPE STANDARD TABLE OF zi_xing_ytd_vir_elmnt WITH DEFAULT KEY.

lt_calculated_data = CORRESPONDING #( it_original_data ).

LOOP AT lt_calculated_data ASSIGNING FIELD-SYMBOL(<lfs_calculated_data>).

<lfs_calculated_data>-PercentageImprovement = 10.

ENDLOOP.

ct_calculated_data = CORRESPONDING #( lt_calculated_data ).

ENDMETHOD.

METHOD if_sadl_exit_calc_element_read~get_calculation_info.

IF line_exists( it_requested_calc_elements[ table_line = 'PERCENTAGEIMPROVEMENT' ] ).

APPEND: 'YEAROFCREATION' TO et_requested_orig_elements,

'MONTHOFCREATION' TO et_requested_orig_elements.

ENDIF.

ENDMETHOD.

ENDCLASS.

AlexGourdet
Product and Topic Expert
Product and Topic Expert

Thank you for visiting SAP Community to get answers to your questions.

Since you're asking a question here for the first time, I'd like to recommend you with the following steps so you can get the most out of your community membership:

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

All the best,
-Alex

Accepted Solutions (0)

Answers (0)