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: 

How to sum numeric values of fields of dynamic Internal Table?

Anuragshriv
Explorer
0 Kudos

Hi,

I have created dynamic internal table which having 6 fields with TYPE P, I want to do the sum of each amount fields and stored into the work area with similer type ,Please let me know how to do sum of amount values of dynamic internal table?

Anurag Shrivastava

7 REPLIES 7

raymond_giuseppi
Active Contributor
0 Kudos

[LOOP|http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB.htm] [ASSIGNING|http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_RESULT.htm] and [ASSIGN|http://help.sap.com/abapdocu_70/en/ABAPASSIGN.htm] [COMPONENT|http://help.sap.com/abapdocu_70/en/ABAPASSIGN_MEM_AREA.htm#&ABAP_ALTERNATIVE_7@7@], what did you try and where did you look ?

Regards,

Raymond

0 Kudos

I assigned work area to the internal table , but at the end of loop I want sum of all the P type fields total ,what we can achieved by SUM in the control break statement,but SUM is not working in Dynamic internal table.

0 Kudos

Hi,

You will need a second working area to store the summarized values. In your loop assign each component and summarize them in your new wa. you will need two field symbols to do the sum... also , forget about the sum statement...

Kr,

Manu.

italo_naia
Participant
0 Kudos

Try:

Do.

Assign component sy-index of structure xxxx ....

if sy-subrc ne 0.

exit.

endif.

DESCRIBE FIELD <fs> type typ.

if typ = <numeric>

sum

endif.

enddo.

I'm not sure if its work.

0 Kudos

Hi I.B.N, welcome to scn!

Since there is a LOOP assigning <fs>, even if the SUM do works, that will update row(s) of itab with summarized values, not only the header... don't think this is quite convenient...

Kr,

Manu.

0 Kudos

Thanks Manu...

sorry at the SUM line I wanted to mean Add <fs> to variable...

not the SUM command.....

But how i said.... I not sure it's works

Edited by: I.B.N. on Nov 24, 2011 8:54 PM

Former Member
0 Kudos

Have you tried to use "collect" to transfer the numeric fields to a work area? Try this inside loop assign.

Alysson Dias