Skip to Content
avatar image
Former Member

help with sum

hi

what is the best way to do sum

i have like that ex.

reg_field sum field

100 100

200 300

300 600

tankes i reward

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 19, 2007 at 09:39 AM

    Hi

    SOrt the internal table and then use the Control break statements and do the sum

    see the following

    All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

    FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

    Some time you will get * when mopving data from this int table to other table using these commands

    so you have to use

    READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

    DATA: sflight_tab TYPE SORTED TABLE OF sflight

    WITH UNIQUE KEY carrid connid fldate,

    sflight_wa LIKE LINE OF sflight_tab.

    SELECT *

    FROM sflight

    INTO TABLE sflight_tab.

    LOOP AT sflight_tab INTO sflight_wa.

    AT NEW connid.

    WRITE: / sflight_wa-carrid,

    sflight_wa-connid.

    ULINE.

    ENDAT.

    WRITE: / sflight_wa-fldate,

    sflight_wa-seatsocc.

    AT END OF connid.

    SUM.

    ULINE.

    WRITE: / 'Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    SKIP.

    ENDAT.

    AT END OF carrid.

    SUM.

    ULINE.

    WRITE: / 'Carrier Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    NEW-PAGE.

    ENDAT.

    AT LAST.

    SUM.

    WRITE: / 'Overall Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    ENDAT.

    ENDLOOP.

    <b>Reward points for useful Answers</b>

    Regards

    Anji

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 19, 2007 at 09:33 AM

    Hi,

    if you need sum in internal table, then in loop of that table code "sum". it will sum entire column and keep in header row.

    or use ADD <FIELD_NAME> TO MTOT.

    If you clear your question, I can give solution exactly.

    Regards

    Rajiv singh.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      chek this out it wil solve ur prob

      data: begin of it occurs 3,

      a type i,

      b type i value 0,

      end of it.

      it-a = 100.

      it-b = 0.

      append it.

      it-a = 200.

      it-b = 0.

      append it.

      it-a = 300.

      it-b = 0.

      append it.

      data a type i.

      loop at it.

      "it-a.

      it-b = a + it-a.

      a = it-b.

      write: / it-a, it-b.

      endloop.

      reward if useful

      Fresher