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: 

help to sum all the common fields

Former Member
0 Kudos

I have a report which needs to sum all the values of KONV-KBETR where KONV-kinak NE 'A'.

How do i write the code.

Can anyone help me in wrting the code..

This value i have to finally display in my internal table as one value.

i tried out with like this

LOOP AT it_konv INTO wa_konv WHERE knumv = wa_vbrk-knumv AND

kposn = wa_vbrp-posnr AND

kschl = wa_ztsd120_n-zlow

AND kinak NE 'A'.

l_kwert = wa_konv-kwert + l_kwert.( where DATA l_kwert LIKE wa_konv-kwert)

ENDLOOP.

wa_konv-kwert = l_kwert.

but its not working..

8 REPLIES 8

former_member386202
Active Contributor
0 Kudos

Hi,

Refer this code

*--Sort table by Personnel Number and Pay Scale Level

SORT it_final BY pernr endda begda.

LOOP AT it_final INTO wa_final.

lv_index = sy-tabix.

lv_index1 = lv_index - 1.

*--Clear

CLEAR : wa_final1.

READ TABLE it_final INTO wa_final1 INDEX lv_index1.

IF sy-subrc EQ 0 AND

wa_final1-pernr EQ wa_final-pernr.

wa_final-incre = wa_final-bet01 - wa_final1-bet01.

ENDIF.

MODIFY it_final FROM wa_final INDEX lv_index

TRANSPORTING incre.

*--Clear

CLEAR : wa_final,

wa_final1.

ENDLOOP.

Regards,

Prashant

JozsefSzikszai
Active Contributor
0 Kudos

hi Mona,

l_kwert = wa_konv-kwert + l_kwert.( where DATA l_kwert LIKE wa_konv-kwert)

replace witrh:

DATA l_kbetr LIKE wa_konv-kbetr

l_kbetr = wa_konv-kbetr + l_kbetr.

Former Member
0 Kudos

Hi Mona,

Why dont you use SUM(kbetr) in select statement it is vary easy with out write code for sum.

Plz Reward if useful,

Mahi.

Former Member
0 Kudos

Hi Prashant.

i was trying out your code and modified it like this.

data lv-index type sy-tabix.

data : wa_final1 like it_final.

loop at it_final into wa_final.

lv-index = sy-tabix.

lv-index = lv-index-1.

clear: wa_final1.

read table it_final into wa_final1 index lv-index1.

if sy-subrc = 0 and wa_final1-real = wa_final-real.

wa_final-real = wa_final-real + wa_final1-real.

endif.

modify it_final from wa_final index lv-index transporting real.

clear: wa_final, wa_final1.

endloop.

but i am getting an error saying " the data object lv-index has no structure and therefore no component called "1".

Can you help me further.

0 Kudos

hi Mona,

with my solution would have been much easier, of course it is your decision...

here you have to change:

lv-index

replace with

lv<b>_</b>index

'-' is not allowed in name of variables, of course you have to make this for all variables which are defined with '-'

hope this helps

ec

Former Member
0 Kudos

hi,

to sum up the values write like this...it worked for me well

SELECT MATNR SUM( LSMNG ) SUM( WEMNG )

INTO (V_MAT, V_LSMNG, V_WEMNG)

FROM S012

WHERE MATNR = WA_MAT-MATNR

GROUP BY MATNR.

Former Member
0 Kudos

HI Ec...

I am still getting the same error

0 Kudos

just revert to my first post in this thread, you only have to change one line in the coding (and the definition for the variable) it has to work.