Application Development and Automation 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: 
Read only

SELECT SUM fileds?

Former Member
0 Likes
830

Hi,

How to SUM fields when using select statement from database table.

This is table I use: COSP

These are the fields that need to be SUM:

WKG001

WKG002

WKG003

WKG004

WKG005

WKG006

WKG007

WKG008

WKG009

WKG010

WKG011

WKG012

WKG013

WKG014

WKG015

WKG016

INTO wa_alv_sum

tnx, Adibo.

Hi,

How to SUM fields when using select statement from database table.

This is table I use: COSP

These are the fields that need to be SUM:

WKG001

WKG002

WKG003

WKG004

WKG005

WKG006

WKG007

WKG008

WKG009

WKG010

WKG011

WKG012

WKG013

WKG014

WKG015

WKG016

INTO wa_alv_sum

tnx, Adibo.

5 REPLIES 5
Read only

Former Member
0 Likes
773

loop at internaltabler into workarea.

collect internal from workarea.

endloop.

Read only

Former Member
0 Likes
773

hi,

u write like this.

select WKG001 WKG002...........

wa_alv_sum = WKG001 +WKG002 + ...

a<logic>

endselect.

<REMOVED BY MODERATOR>

regards,

chandu

Edited by: Alvaro Tejada Galindo on Apr 25, 2008 1:32 PM

Read only

Former Member
0 Likes
773

Hi..

You can take one same internal structure and do like this...

T1_FINAL IS WHICH YOU HAVE VALUES .

T3_FINAL IS SAME STRUCTURE BUT NO VALUES IN THAT TABLE....

LOOP AT T1_FINAL INTO WA1_FINAL.

READ TABLE T3_FINAL INTO WA3_FINAL WITH KEY MENGE = WA1_FINAL-MENGE.

IF SY-SUBRC = 0.

WA3_FINAL-MENGE = WA3_FINAL-MENGE + WA1_FINAL-MENGE.

MODIFY TABLE T3_FINAL FROM wa3_FINAL TRANSPORTING MENGE.

CLEAR WA1_FINAL.

ELSE.

append wa1_FINAL to T3_FINAL.

ENDIF.

ENDLOOP.

Regards,

Rahul

Read only

Former Member
0 Likes
773

Hi,

I wouldnt Suggest you sum up all those fields while selecting the data from the Table..reason being you probably will have performance issues.

I suggest you add then in your internal tables.

Loop At ITAB Into WA.

WA-TOTAL = WA-F1 + WA-F2....

Modify ITAB From WA Transporting TOTAL Index Sy-Tabix.

EndLoop.

santhosh

Read only

Former Member
0 Likes
773

Hi,

Create a structure with your fields:

Types: begin of t_struc

field1 type WTGXXX

field2 type WTGXXX

field31 type WTGXXX

field41 type WTGXXX

etc. etc......

end of t_struc.

data: w_struc type t_struc.

data: v_sum type WTGXXX.

field-symbols : <fs_amount> type any (or type WTGXXX).

select your record from COSP

move corresponding fields to w_struc.

do.

assign component sy-index from structure w_struc to <fs_amount>.

if sy-subrc ne 0.

exit.

else.

add <fs_field> to v_sum.

endif.

enddo.

Hope this helps.

Kind Regards

Edited by: Raymond Friston on Apr 25, 2008 3:33 PM