on 04-20-2022 6:24 PM
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.
User | Count |
---|---|
101 | |
12 | |
10 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.