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

Summing

raguraman_c
Active Contributor
0 Likes
541

Hi Experts,

I have an internal table with fields category, amt1,amt2,amt3...amt100,city1 say with 100 rows and 10 category.

I want to sum amt1...amt100 for each category So the result would be in 10 rows.

Points gauranteed.

--Ragu

4 REPLIES 4
Read only

Former Member
0 Likes
520

Hi Raguraman,

Use the Collect stmt to group all the related category fields along with the internal table.

Hope this resolves your query.

Reward all the helpful answers.

Regards

Read only

alex_m
Active Contributor
0 Likes
520

Sort itab by category.

Looop at Itab.

AT end of itab1-category.

Collect itab1.

endat.

Endloop.

Message was edited by:

Alexander

Read only

former_member673464
Active Contributor
0 Likes
520

hi,

You can use following code to resolve the your problem.

*" Data declarations...................................................

"----


  • Data declaration of the structure to hold material information *

"----


data:

begin of fs_material,

material(7) type c, " Material

purchase(4) type c, " Purchase order

podate like sy-datum, " Po date

quantity type i, " Quantity

unit(2) type c, " Unit

end of fs_material.

*" Data declarations...................................................

"----


  • Data declaration of the structure to hold units details *

"----


data:

begin of fs_unit,

quantity type i, " Quantity

unit(2) type c, " Unit

end of fs_unit.

*" Data declarations...................................................

"----


  • Work variables *

"----


data:

w_material(7) type c. " Material

"----


  • Internal table to hold material information *

"----


data:

t_material like

standard table

of fs_material

with non-unique key material.

"----


  • Internal table to hold material information *

"----


data:

t_unit like

standard table

of fs_unit

with non-unique key unit.

clear fs_material .

fs_material-material = 'MAT_001'(001).

fs_material-purchase = '6001'(002).

fs_material-podate = '20020304'(003).

fs_material-quantity = '10'.

fs_material-unit = 'EA'(004).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_001'(001).

fs_material-purchase = '6002'(005).

fs_material-podate = '20021901'(006).

fs_material-quantity = '5'.

fs_material-unit = 'CA'(007).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_003'(008).

fs_material-purchase = '6003'(009).

fs_material-podate = '20021901'(006).

fs_material-quantity = '20'.

fs_material-unit = 'EA'(004).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_001'(001).

fs_material-purchase = '6004'(010).

fs_material-podate = '20021005'(011).

fs_material-quantity = '15'.

fs_material-unit = 'EA'(004).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_003'(008).

fs_material-purchase = '6005'(012).

fs_material-podate = '20020805'(013).

fs_material-quantity = '6'.

fs_material-unit = 'CA'(007).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_002'(014).

fs_material-purchase = '6006'(015).

fs_material-podate = '20023001'(016).

fs_material-quantity = '40'.

fs_material-unit = 'EA'(004).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_003'(008).

fs_material-purchase = '6007'(017).

fs_material-podate = '20022402'(018).

fs_material-quantity = '10'.

fs_material-unit = 'CA'(007).

append fs_material to t_material.

clear fs_material .

fs_material-material = 'MAT_002'(014).

fs_material-purchase = '6008'(019).

fs_material-podate = '20022402'(018).

fs_material-quantity = '5'.

fs_material-unit = 'EA'(004).

append fs_material to t_material.

clear fs_material .

write:'Material'(020).

uline at /(8).

write: /20 'Purchase Order'(021),

35 'P O Date'(022),

50 'Quantity'(023),

65 'Unit'(024).

uline : /20(14),35(8),50(10),65(5).

sort t_material by material.

loop at t_material into fs_material.

fs_unit-unit = fs_material-unit.

fs_unit-quantity = fs_material-quantity.

collect fs_unit into t_unit.

if w_material ne fs_material-material.

w_material = fs_material-material.

write:/ w_material.

endif. " IF W_MATERIAL NE FS_MATERIAL..

write:/25 fs_material-purchase,

35 fs_material-podate,

45 fs_material-quantity,

65 fs_material-unit.

at end of material.

skip .

write: / 'Total quantity ordered'(025).

loop at t_unit into fs_unit.

write:45 fs_unit-quantity ,

65 fs_unit-unit,/.

endloop. " LOOP AT T_UNIT INTO FS_UNIT

clear t_unit[].

skip 2.

endat. " AT END OF MATERIAL

endloop. " LOOP AT T_MATERIAL INTO ....

regards,

veeresh

Read only

Former Member
0 Likes
520

Hi...

you can acheive that using the following example...

apply it to your problem

REPORT ZYH642_TEST_2.

data:

sum type i,

tsum type i.

data:

begin of itab occurs 0,

c1 type c,

f1 type i,

f2 type i,

f3 type i,

f4 type i,

end of itab.

do 10 times.

itab-c1 = 'A'.

itab-f1 = sy-index.

itab-f2 = sy-index.

itab-f3 = sy-index.

itab-f4 = sy-index.

append itab.

enddo.

do 10 times.

do 4 times varying sum from itab-f1 next itab-f2.

tsum = tsum + sum.

enddo.

write: / tsum.

clear tsum.