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

subtotal in internal table

Former Member
0 Likes
1,471

I have one internal table.

its fields are

vbeln

posnr

brgew

gewei

volum

voleh

defined internal table as

DATA : BEGIN OF itab5 OCCURS 0,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

brgew LIKE vbap-brgew,

gewei LIKE vbap-gewei,

volum LIKE vbap-volum,

voleh LIKE vbap-voleh,

END OF itab5.

after some oerations on internal table i get some records in itab5

for each vbeln there may be motre than one posnr

for all posnr of one vbeln

i want subtotal of the field brgew and volum

i have coded this way

but it gets total of all vbelns

sort itab5 by vbeln .

loop at itab5.

on change of itab5-vbeln.

loop at itab5 where vbeln = itab5-vbeln.

sum.

endloop.

endon.

endloop.

pls suggest me the changes.

points will be rewarded to each.

I have one internal table.

its fields are

vbeln

posnr

brgew

gewei

volum

voleh

defined internal table as

DATA : BEGIN OF itab5 OCCURS 0,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

brgew LIKE vbap-brgew,

gewei LIKE vbap-gewei,

volum LIKE vbap-volum,

voleh LIKE vbap-voleh,

END OF itab5.

after some oerations on internal table i get some records in itab5

for each vbeln there may be motre than one posnr

for all posnr of one vbeln

i want subtotal of the field brgew and volum

i have coded this way

but it gets total of all vbelns

sort itab5 by vbeln .

loop at itab5.

on change of itab5-vbeln.

loop at itab5 where vbeln = itab5-vbeln.

sum.

endloop.

endon.

endloop.

pls suggest me the changes.

points will be rewarded to each.

4 REPLIES 4
Read only

Former Member
0 Likes
731

hi,

try this:

sort itab5 by vbeln posnr.

loop ...

at end of posnr.

collect...

endat.

endloop.

Read only

Former Member
0 Likes
731

Hello,

Do this,


data:
  itab5_aux like itab5.

loop at itab5.
  collect itab5 to itab5_aux.
endloop.

.

itab5_aux will have the sum.

Regards,

Read only

Former Member
0 Likes
731

collect will work. but it has some restrictions(chck sap docu for this)..

effective solution for this is.

declare an internal itab and itab_fin table with fields:

vbeln

brgew

volum

loop at itab5.

move itab5-vbeln to itab-vbeln.

move itab5-brgew to itab-brgew.

move itab5-volum to itab-volum.

append itab.

endloop.

loop at itab.

collect itab into itab_fin.

endloop.

reward points if useful.

Thanks-

Harmeet.

Read only

Former Member
0 Likes
731

This message was moderated.