Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Sum for multiple field

former_member203806
Participant
0 Kudos
364

Hi Experts,

I have below internal table.

I need to get Date wise, Category wise total duration.

Thanks

3 REPLIES 3

DominikTylczyn
Active Contributor
0 Kudos
312

Hello pramod.pathirana

pramod.pathiranaHave a look at control level processing when working with internal tables:

Processing Table Entries in Loops

AT - Control Level Processing

Best regards

Dominik Tylczynski

Sandra_Rossi
Active Contributor
312

It could be something close to this:

itab_with_sum = VALUE #(
                FOR GROUPS <group> OF <line> IN source_itab
                GROUP BY ( category = <line>-category )
                ( category     = <group>-category
                  sum_duration = REDUCE #(
                                 INIT sum = VALUE decfloat16( ) IN
                                 FOR <line> IN GROUP <group>
                                 NEXT sum = sum + <line>-duration ) ) ).

or if you have HANA (simpler but should be slower):

SELECT category, SUM( duration ) AS sum_duration
FROM @source_itab
GROUP BY category
INTO TABLE @DATA(itab_with_sum).

Eduardo-CE
Active Participant
0 Kudos
312
LOOP.
  COLLECT wa INTO itab 
ENDLOOP.