Application Development and Automation 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: 
Read only

Get Sum for multiple field

former_member203806
Participant
0 Likes
1,492

Hi Experts,

I have below internal table.

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

Thanks

3 REPLIES 3
Read only

Dominik_Tylczynski
SAP Champion
SAP Champion
0 Likes
1,440

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

Read only

Sandra_Rossi
Active Contributor
1,440

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).
Read only

Eduardo-CE
Active Participant
0 Likes
1,440
LOOP.
  COLLECT wa INTO itab 
ENDLOOP.