
TYPES:
BEGIN OF ty_s_collect,
carrid TYPE s_carr_id,
paymentsum TYPE s_sum,
seatsmax_b TYPE s_smax_b,
seatsocc_b TYPE s_socc_b,
seatsmax_f TYPE s_smax_f,
seatsocc_f TYPE s_socc_f,
END OF ty_s_collect,
ty_t_collect TYPE SORTED TABLE OF ty_s_collect
WITH NON-UNIQUE KEY carrid,
BEGIN OF ty_s_sum,
paymentsum TYPE s_sum,
seatsmax_b TYPE s_smax_b,
seatsocc_b TYPE s_socc_b,
seatsmax_f TYPE s_smax_f,
seatsocc_f TYPE s_socc_f,
END OF ty_s_sum.
DATA:
tl_collect TYPE ty_t_collect.
LOOP AT t_flights ASSIGNING FIELD-SYMBOL(<fs_key>).
DATA(wl_collect) = CORRESPONDING ty_s_collect( <fs_key> ).
COLLECT wl_collect INTO tl_collect.
ENDLOOP.
*******************************************************************
tl_collect = VALUE ty_t_collect(
FOR GROUPS carrier OF <fs_flight> IN t_flights
INDEX INTO l_tabix
GROUP BY ( carrid = <fs_flight>-carrid )
LET wl_sum = REDUCE ty_s_sum(
INIT calc TYPE ty_s_sum
FOR r IN GROUP carrier
NEXT calc-paymentsum = calc-paymentsum + r-paymentsum
calc-seatsmax_b = calc-seatsmax_b + r-seatsmax_b
calc-seatsocc_b = calc-seatsocc_b + r-seatsocc_b
calc-seatsmax_f = calc-seatsmax_f + r-seatsmax_f
calc-seatsocc_f = calc-seatsocc_f + r-seatsocc_f )
IN
( carrid = carrier-carrid
paymentsum = wl_sum-paymentsum
seatsmax_b = wl_sum-seatsmax_b
seatsocc_b = wl_sum-seatsocc_b
seatsmax_f = wl_sum-seatsmax_f
seatsocc_f = wl_sum-seatsocc_f ) ).
CLASS lcl_reduce DEFINITION CREATE PUBLIC.
PUBLIC SECTION.
METHODS: start.
ENDCLASS.
CLASS lcl_reduce IMPLEMENTATION.
METHOD start.
TYPES:
BEGIN OF ty_s_collect,
carrid TYPE s_carr_id,
paymentsum TYPE s_sum,
seatsmax_b TYPE s_smax_b,
seatsocc_b TYPE s_socc_b,
seatsmax_f TYPE s_smax_f,
seatsocc_f TYPE s_socc_f,
END OF ty_s_collect,
ty_t_collect TYPE SORTED TABLE OF ty_s_collect
WITH NON-UNIQUE KEY carrid,
BEGIN OF ty_s_sum,
paymentsum TYPE s_sum,
seatsmax_b TYPE s_smax_b,
seatsocc_b TYPE s_socc_b,
seatsmax_f TYPE s_smax_f,
seatsocc_f TYPE s_socc_f,
END OF ty_s_sum.
DATA:
tl_collect TYPE ty_t_collect,
lv_sta_time TYPE timestampl,
lv_end_time TYPE timestampl,
lv_diff TYPE p DECIMALS 5.
SELECT * FROM sflight
INTO TABLE @DATA(t_flights)
ORDER BY PRIMARY KEY.
GET TIME STAMP FIELD lv_sta_time.
LOOP AT t_flights ASSIGNING FIELD-SYMBOL(<fs_key>).
DATA(wl_collect) = CORRESPONDING ty_s_collect( <fs_key> ).
COLLECT wl_collect INTO tl_collect.
ENDLOOP.
GET TIME STAMP FIELD lv_end_time.
lv_diff = lv_end_time - lv_sta_time.
WRITE: /(50) 'COLLECT - LOOP GROUP BY...LOOP AT GROUP', lv_diff.
cl_demo_output=>display( tl_collect ).
FREE tl_collect.
GET TIME STAMP FIELD lv_sta_time.
tl_collect = VALUE ty_t_collect(
FOR GROUPS carrier OF <fs_flight> IN t_flights
INDEX INTO l_tabix
GROUP BY ( carrid = <fs_flight>-carrid )
LET wl_sum = REDUCE ty_s_sum(
INIT calc TYPE ty_s_sum
FOR r IN GROUP carrier
NEXT calc-paymentsum = calc-paymentsum + r-paymentsum
calc-seatsmax_b = calc-seatsmax_b + r-seatsmax_b
calc-seatsocc_b = calc-seatsocc_b + r-seatsocc_b
calc-seatsmax_f = calc-seatsmax_f + r-seatsmax_f
calc-seatsocc_f = calc-seatsocc_f + r-seatsocc_f )
IN
( carrid = carrier-carrid
paymentsum = wl_sum-paymentsum
seatsmax_b = wl_sum-seatsmax_b
seatsocc_b = wl_sum-seatsocc_b
seatsmax_f = wl_sum-seatsmax_f
seatsocc_f = wl_sum-seatsocc_f ) ).
GET TIME STAMP FIELD lv_end_time.
lv_diff = lv_end_time - lv_sta_time.
WRITE: /(50) 'COLLECT - FOR GROUPS... REDUCE[FOR IN GROUP]... ', lv_diff.
cl_demo_output=>display( tl_collect ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
NEW lcl_reduce( )->start( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
21 | |
8 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |