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: 

Sum

Former Member
0 Kudos

Hi,

I have one internal table.

in that itab i have one numberic fild as Billamount.

The sum of all the bill amt should be displayed in a textfield.

How to dot that.

I tried as

Loop at itab.

at end of billamt.

sum

endat.

endloop.

But how to place the sum in the text field.

Thanks & Regards,

Sumithra

12 REPLIES 12

former_member181962
Active Contributor
0 Kudos

data: v_billamt(20).

Loop at itab.

at end of billamt.

sum.

v_billamt = itab-billamount.

endat.

endloop.

write:/ v_billamt.

Former Member
0 Kudos

Loop at itab.

at end of <b>billno</b>.

sum

<b>write billamt to ltext.</b>

endat.

endloop.

<b>Please note the change in the above..previously it was billamt..hence it just showed the last billamt. if you wish to sum the amount at end of each bill or material or customer you can use the particular field. If you need the grand total than please use AT LAST.<b></b></b>

Message was edited by: Anurag Bankley

Former Member
0 Kudos

Hi Ravi & Anurag,

both are not working.

If I give itab-Billamt...its copying the last amt not the Sum

If igive "write to"..its not copying the Sum.

0 Kudos

Check Anurags last post. It will give you the required result.

Regards,

ravi

Former Member
0 Kudos

Hi Vasu,

Hope you are showing the Sum of amounts for some Document number. Keep your internal table with the Document number as first field. After populating data into the internal table, sort it by Document Number(First field). Then use the logic At end of Document Number... SUM... Move Amount field to text.

Former Member
0 Kudos

try this

data: v_billamt(20).
Loop at itab.
at end of billamt.
sum.
endat.
v_billamt = itab-billamount.
endloop.

write:/ v_billamt.

Former Member
0 Kudos

HI,

data v_sum(20) type c

Loop at itab.

at end of billamt.

sum.

v_sum = itab-qty.

condense v_sum.(remove leading spaces)

endat.

endloop.

write v_sum input.

Regards

amole

Former Member
0 Kudos

DATA : BEGIN OF ITAB OCCURS 0,

VBELN LIKE LIKP-VBELN ,

LFIMG LIKE LIPS-LFIMG,

END OF ITAB .

DATA: v_tot like lips-lfimg,

V_SUM like lips-lfimg.

SELECT VBELN LFIMG

INTO TABLE ITAB

FROM LIPS

WHERE VBELN = '0080576653'.

LOOP AT ITAB .

AT END OF VBELN .

SUM.

v_tot = v_tot + itab-lfimg.

move v_tot to v_sum.

clear v_tot.

ENDAT.

ENDLOOP.

WRITE:/ V_SUM.

delivery num i have two quantities 5 1nd 15

tot is 15.

When you use SUM in a LOOP with an explicitly specified output area, this output area must be compatible with the line type of the internal table.

When using LOOP to process a sorted extract (see SORT), the control total of f at the end of the group appears in the field SUM(f) - - if f is type I, F or P.

hope this helps ..

regards,

vijay.

Former Member
0 Kudos

Hi Sumi,

if you want the sum per billamt you have to make

an own sum-table.

data: begin of sum_table occurs 0,

bill like ...

billamout like ...

end sum_table.

*

loop at itab.

...

sum_table-bill = itab-bill.

sum_table-billamount = itab-billamount.

collect sum_table.

...

endloop.

at this code you don't need at end of bill.

Hope it helps.

regards, Dieter

Former Member
0 Kudos

Hi sumithra ,

like there is a possibility of sum_overflow if in ur itab structure a field is present say

begin of itab occurs 0

peinh like mbew-peinh

end of itab .

now peinh is price unit of length 5

but if do

loop at itab

sum .

endloop.

since peinh holds number value this also gets added

causing u r using sum in loop endloop.

and the whole value is added up cause of sum and if the value exceeds 99999 max for range of 5 digits

then it may result in sum over flow .

just remember this and do a cross check on ur itab ..

if u can send the code to us it will be easy for us to interpret .

regards,

Vijay

Former Member
0 Kudos

Hi sumithra ,

go through this sample code .

take a delivery number from ur lips table which is having some items and quanity and substitute that number in this code as WHERE VBELN = 'XXXXXXXXXX'.

*****************************************************

DATA : BEGIN OF ITAB OCCURS 0,

VBELN LIKE LIKP-VBELN ,

LFIMG LIKE LIPS-LFIMG,

END OF ITAB .

DATA: v_tot like lips-lfimg,

  • V_SUM like lips-lfimg.

v_sum(13) type c.

SELECT VBELN LFIMG

INTO TABLE ITAB

FROM LIPS

WHERE VBELN = '0080576653'.

LOOP AT ITAB .

AT END OF VBELN .

SUM.

  • move itab-lfimg to v_sum.

write itab-lfimg to v_sum.

ENDAT.

ENDLOOP.

WRITE:/ V_SUM.

*****************************************************

u can use move to v_sum and here the both data types should be equal ,

put in *

u can use write also ,, here v_sum declared as type c

note the difference .

just put a debugging point in the at end in ur code and see how this is fetching the value to the field .

regards,

VIjay.

kindly close the thread if ur query is solved .

Former Member
0 Kudos

Hi Sumi,

problem solved?

regards, Dieter