You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CLASSzcl_itab_aggregation DEFINITION PUBLIC FINAL CREATE PUBLIC .
PUBLIC SECTION.
TYPESgroup TYPE cLENGTH1.
TYPES: BEGIN OF initial_numbers_type,
group TYPEgroup,
number TYPE i,
END OF initial_numbers_type,
initial_numbers TYPE STANDARD TABLE OF initial_numbers_type WITHEMPTY KEY.
TYPES: BEGIN OF aggregated_data_type,
group TYPEgroup,
count TYPE i,
sum TYPE i,
min TYPE i,
max TYPE i,
average TYPE f,
END OF aggregated_data_type,
aggregated_data TYPE STANDARD TABLE OF aggregated_data_type WITHEMPTY KEY.
METHODS perform_aggregation
IMPORTING
initial_numbers TYPE initial_numbers
RETURNINGVALUE(aggregated_data) TYPE aggregated_data.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASSzcl_itab_aggregation IMPLEMENTATION.
METHODperform_aggregation.
DATA: lv_group_average TYPE f.
LOOP AT initial_numbers ASSIGNINGFIELD-SYMBOL(<lfs_init_number>)
GROUPBY ( key=<lfs_init_number>-group
count=GROUPSIZE )
ASSIGNINGFIELD-SYMBOL(<lfs_group>).
DATA(lv_group_sum) =REDUCE i( INIT lv_sum TYPE iFOR ls_group_sum INGROUP<lfs_group>NEXT lv_sum += ls_group_sum-number ).
DATA(lv_group_min) =REDUCE i( INIT lv_min ='99999'FOR ls_group_min INGROUP<lfs_group>NEXT lv_min =nmin( val1 = lv_min
val2 = ls_group_min-number ) ).
DATA(lv_group_max) =REDUCE i( INIT lv_max TYPE iFOR ls_group_max INGROUP<lfs_group>NEXT lv_max =nmax( val1 = lv_max
val2 = ls_group_max-number ) ).
APPENDVALUE #( group=<lfs_group>-key
count=<lfs_group>-count
sum= lv_group_sum
min = lv_group_min
max = lv_group_max
average = ( lv_group_sum /<lfs_group>-count ) ) TO aggregated_data.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Not sure what is wrong here. Things look fine to me.
The text was updated successfully, but these errors were encountered:
Exercise code -
Not sure what is wrong here. Things look fine to me.
The text was updated successfully, but these errors were encountered: