on 04-26-2006 11:38 AM
hi
i am facing a small problem
actually i used the below code for summing of all items coming into g_dmshb and g_mhngf.
but am not able to get get overall total am able to get only for last two items
can u suggest me whether the above code is correct or not
thank u
LOOP AT INTAB WHERE NAME = 'F150D-MHNGF' .
IF SY-SUBRC = 0.
MOVE INTAB-VALUE TO G_MHNGF1.
G_MHNGF1 = INTAB-VALUE .
ENDIF.
ENDLOOP.
G_TOT2 = G_DMSHB + G_MHNGF1.
DATA G_TOT3(15).
CLEAR OUTTAB.
READ TABLE OUTTAB WITH KEY NAME = 'G_TOT2'.
IF SY-SUBRC = 0.
WRITE G_TOT2 TO G_TOT3 CURRENCY 'GBP'.
OUTTAB-VALUE = G_TOT3.
CONDENSE OUTTAB-VALUE NO-GAPS.
MODIFY OUTTAB INDEX 1 TRANSPORTING VALUE.
ENDIF.
Shouldn't you statement G_TOT2 = G_DMSHB + G_MHNGF1. be inside the loop so that you get all the values to sun up.
Regards
Ravi
Note : Please mark all the helpful answers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi ravi
i used the below code and as u sugested i kept g_tot2 = g_dmshb +g_mhngf in the loop.still am not able to get the required sum result.
LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .
if sy-subrc = 0.
replace ',' in intab-value with '' .
condense intab-value no-gaps.
move intab-value to g_dmshb.
endif.
*g_tot1 = g_dmshb + intab-value.
g_tot2 = g_tot1 + intab-value.
reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.
IF SY-SUBRC = 0.
MOVE INTAB-VALUE TO G_MHNGF1.
*G_MHNGF1 = INTAB-VALUE .
ENDIF.
g_tot2 = g_dmshb + g_mhngf1.
endloop.
Thanks
Hi,
Try this.
LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .
clear : g_dmshb, g_mhgf1.
if sy-subrc = 0.
replace ',' in intab-value with '' .
condense intab-value no-gaps.
move intab-value to g_dmshb.
endif.
reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.
IF SY-SUBRC = 0.
MOVE INTAB-VALUE TO G_MHNGF1.
ENDIF.
g_tot2 = g_dmshb + g_mhngf1.
endloop.
Notice the clear statements inside the loop.
Regards,
Ravi
Note :Please mark all the helpful answers
Hi,
There is an error in your logic see my comments at the side of your code.
LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .
if sy-subrc = 0.
replace ',' in intab-value with '' .
condense intab-value no-gaps.
Here the value of intab-value is moved to g_dmshb
move intab-value to g_dmshb.
endif.
*g_tot1 = g_dmshb + intab-value.
g_tot2 = g_tot1 + intab-value.
reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.
IF SY-SUBRC = 0.
MOVE INTAB-VALUE TO G_MHNGF1.
*G_MHNGF1 = INTAB-VALUE .
ENDIF.
Now here you add it to g_tot2
g_tot2 = g_dmshb + g_mhngf1.
endloop.
In accumulating a value the logic shoud be like
Loop
a = a + b.
endloop.
So your code should look something like this
LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .
if sy-subrc = 0.
replace ',' in intab-value with '' .
condense intab-value no-gaps.
move intab-value to g_dmshb.
Here you add g_dmshb to g_tot2
add g_dmshb to g_tot2.
endif.
reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.
IF SY-SUBRC = 0.
MOVE INTAB-VALUE TO G_MHNGF1.
ENDIF.
Here you add g_mhngf1 to g_tot2 so you have the sum of
both for entries with name = MHND-DMSHB and F150D-MHNGF
g_tot2 = g_tot2 + g_mhngf1. "<- should be like this
endloop.
If you want an optimized code try this one below.
LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .
IF sy-subrc = 0.
REPLACE ',' IN intab-value WITH '' .
CONDENSE intab-value no-gaps.
MOVE intab-value TO g_dmshb.
ENDIF.
READ TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.
IF SY-SUBRC = 0.
MOVE intab-value TO g_mhngf1.
ENDIF.
Here you add g_mhngf1 to g_tot2 so you have the sum of
both for entries with name = MHND-DMSHB and F150D-MHNGF
code should be like this:
g_tot2 = g_tot2 + g_dmshb + g_mhngf1.
ENDLOOP.
HI
there is 7 line items which are taking from the MHND-DMSHB
and the last value in the line item are taking from the F150D-MHNGF.
it's taking sum from first line item MHND and from the Last line item F150D. passing sum to the G_tot2
and refreshing the valueG_TOT2,
next time it's talking value from second line item and from last, and refreshing the G_tot2.
so the entire process is like sum of 1st + last line item, next refreshing.
then 2nd + last line item taking sum and refreshing.
at last it's taking sum from the 7th line item + last line item, it's printing sum, but not summ all the 7 + last line item.
may be i need to pass these sum to one static variable.
how to do this.
Thanks
Hi,
I was able to see the screen shot, but that could not give the details I was looking for. I want to see the data in INTTAB table along with the columns.
Can you send me the data for INTTAB table which contains both the fields which you are summing.
Regards,
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
u are using where condition may be only those two records satisfies the condition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.