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 STATEMENT

Former Member
0 Kudos

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

5 REPLIES 5

Former Member
0 Kudos

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

0 Kudos

I am sorry santhosh, i am not gettng what ur sayng?

can u plz explain me in brief?

or can u tell me correction in my prog so that i will come to know correctly about SUM statement

Former Member
0 Kudos

Hi,

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

Reward points if usefull...

Former Member
0 Kudos

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

0 Kudos

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.