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

SUM STATEMENT

HI GURU'S,

Please can anybody explains me

what is significance of using SUM statement inside the AT AND ENDAT statement.

what i understood about sum is: The statement SUM calculates the component total with the numeric data type (i, p, f)

of all rows in the current control level and assigns these to the components of the work area wa. In the control levels

FIRST, LAST, and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components

of all rows in the internal table.

but in below program which i did, its not doing that</b>

TYPES: BEGIN OF companies_type,

name(30),

product(20),

sales TYPE i,

SALES1 TYPE I,

END OF companies_type.

DATA: companies TYPE STANDARD TABLE OF companies_type WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,

wa_companies TYPE companies_type.

wa_companies-name = 'XYZ'.

wa_companies-product = 'SAP'.

wa_companies-sales = '1'.

wa_companies-sales1 = '1'.

APPEND wa_companies TO companies.

wa_companies-name = 'ABC'.

wa_companies-product = 'ABAP'.

wa_companies-sales = '4'.

wa_companies-sales1 = '4'.

APPEND wa_companies TO companies.

wa_companies-name = 'PQR'.

wa_companies-product = 'HR'.

wa_companies-sales = '3'.

wa_companies-sales1 = '3'.

APPEND wa_companies TO companies.

LOOP AT companies INTO wa_companies.

AT NEW name.

sum.

NEW-PAGE.

WRITE / wa_companies-name.

ENDAT.

WRITE: / wa_companies-product, wa_companies-sales,wa_companies-sales1.

AT END OF NAME.

SUM.

WRITE: / wa_companies-name, wa_companies-sales,wa_companies-sales1 .

ENDAT.

ENDLOOP.

Thanks

Priya

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 05:12 AM

    hi,

    Sum statement will give the sum of Sales and Sales1 field after end of the particular field, ie name. for using control break statement the internal table should be sorted .

    of eg.

    field1 field2

    ch 1

    ch 3

    sa 2

    sa 2

    at end of field1.

    sum statement will add the value 1 & 3 of first field1 and the 2 & 2 of 2nd field.

    regards,

    Santosh Thorat

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 05:21 AM

    Hi,

    Try using "collect" statement in your case...

    Reward points if usefull...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 05:37 AM

    Hi,

    The control statements should be used inside a loop, the internal table should be sorted before using the control statements.

    loop...

    At new name.

    sum.

    endat.

    endloop....

    Sum of the numeric values will be calculated when the name changes. At new is triggered at the begining itself.

    loop...

    At end of name.

    sum.

    endat.

    endloop....

    Sum of the numeric values will be calculated when the name changes .

    Just a simple example:

    ID no Name Salary.

    100 Ram 5000

    100 Ravi 6000

    200 Prajn 7000

    In this case.

    loop at itab.

    At new idno.

    sum

    write:/ itab-idno , itab-name, itab-salaty.

    Endat.

    endloop.

    O/p will be :

    100 Ram 11000

    The sum will trigger when the number idno is changing .

    Similarly AT end also works.

    Regards,

    Vani

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi vani,

      according to your explanation,I think in u need to write AT NEW NAME.

      Please correct me if i am wrong.

      Sum of the numeric values will be calculated when the name changes .

      Just a simple example:

      ID no Name Salary.

      100 Ram 5000

      100 Ravi 6000

      200 Prajn 7000

      In this case.

      loop at itab.

      At new idno. "AT NEW NAME.

      sum

      write:/ itab-idno , itab-name, itab-salaty.

      Endat.

      endloop.

      O/p will be :

      100 Ram 11000

      The sum will trigger when the number idno is changing .

      Similarly AT end also works.

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.