Skip to Content
author's profile photo Former Member
Former Member

Sum

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

11 Answers

  • Posted on Oct 23, 2006 at 01:28 PM

    data: v_billamt(20).

    Loop at itab.

    at end of billamt.

    sum.

    v_billamt = itab-billamount.

    endat.

    endloop.

    write:/ v_billamt.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 01:28 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 01:38 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 01:50 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 01:55 PM

    try this

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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 02:04 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 02:10 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 02:12 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 02:19 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 08:28 AM

    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 .

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.