09-15-2008 8:02 PM
Hi all,
I have the ITAB as follows.
wa_mseg-mblnr = '5000000130'.
wa_mseg-mjahr = '2008'.
wa_mseg-bwart = '901'.
wa_mseg-dmbtr = '00000005000'.
wa_mseg-bpmng = '00000000100'.
wa_mseg-ebeln = '1059200855'.
wa_mseg-ebelp = '00010'.
APPEND wa_mseg to itab_mseg.
wa_mseg-mblnr = '5000000131'.
wa_mseg-mjahr = '2008'.
wa_mseg-bwart = '902'.
wa_mseg-dmbtr = '00000002500'.
wa_mseg-bpmng = '00000000050'.
wa_mseg-ebeln = '1059200855'.
wa_mseg-ebelp = '00010'.
APPEND wa_mseg to itab_mseg.
wa_mseg-mblnr = '5000000132'.
wa_mseg-mjahr = '2008'.
wa_mseg-bwart = '901'.
wa_mseg-dmbtr = '00000002500'.
wa_mseg-bpmng = '00000000050'.
wa_mseg-ebeln = '1059200855'.
wa_mseg-ebelp = '00010'.
APPEND wa_mseg to itab_mseg.
now i want to add the BPMNG for the BWART = 901
DMBTR for the BWART = 901
ans same thing for the BWART = 902.
how do i calculate the SUM based on condition.
09-15-2008 8:54 PM
now i want to add the BPMNG for the BWART = 901
DMBTR for the BWART = 901
ans same thing for the BWART = 902.
how do i calculate the SUM based on condition.
Hi, you can loop de internal table and do a control cut by "bwart". For doing that the order of the fields of your internal table must change.
If you have:
1st.mblnr
2nd.mjahr
3rd.bwart
you have to change to:
1st.bwart
2nd.mblnr
3rd.mjahr
So in the loop you will can do like this.
loop at itab.
aux_sum = itab-BPMNG + aux_sum.
at end of bwart.
* Here you will have de SUM for BWART.
* Then you clear aux_sum for the next different BWART.
endat.
endloop.
hope this help you.
Andrew83
09-15-2008 8:09 PM
Explore the help on the COLLECT statement.
You can take a temporary table with the required field and use the COLLECT to get the SUM.
Regards,
Naimesh Patel
09-15-2008 8:54 PM
now i want to add the BPMNG for the BWART = 901
DMBTR for the BWART = 901
ans same thing for the BWART = 902.
how do i calculate the SUM based on condition.
Hi, you can loop de internal table and do a control cut by "bwart". For doing that the order of the fields of your internal table must change.
If you have:
1st.mblnr
2nd.mjahr
3rd.bwart
you have to change to:
1st.bwart
2nd.mblnr
3rd.mjahr
So in the loop you will can do like this.
loop at itab.
aux_sum = itab-BPMNG + aux_sum.
at end of bwart.
* Here you will have de SUM for BWART.
* Then you clear aux_sum for the next different BWART.
endat.
endloop.
hope this help you.
Andrew83
09-16-2008 11:09 AM
BWART must be the first col. of itab_mseg.
code:
sort itab_mseg by BWART.
loop at itab_mseg.
at end of bwart.
SUM.
WRITE: / 'BWART:', itab_mseg-BWART,
'BPMNG:', itab_mseg-BPMNG,
'DMBTR:', itab_mseg-DMBTR,
endat.
endloop.
09-16-2008 11:15 AM
Hi,
Try this.
sort the table by key field and bwart.
loop at itab into wa.
s_bpmng = s_bpmng + wa-bpmng.
s_dmbtr = s_dmbtr + wa-dmbtr.
at end of bwart.
<sum of bpmng for a particular bwart will be there in s_bpmng
sum of dmbtr for a particular bwart will be there in s_dmbtr>
<here do the logic according to ur requirement.>
clear: s_bpmng, s_dmbtr.
endat.
endloop.
Sharin.
09-16-2008 11:18 AM
09-16-2008 11:19 AM
Hi...
after populating the ITAB sort the table by bwart
then
loop at ITAB into wa_mseg.
v_sum = v_sum + wa_mseg-bpmng .
v_DMBTR = v_DMBTR + wa_mseg-DMBTR.
write : /
wa_mseg-mblnr
wa_mseg-mjahr
wa_mseg-bwart
wa_mseg-dmbtr
wa_mseg-bpmng
wa_mseg-ebeln
wa_mseg-ebelp .
at end of bwart.
write:/ v_sum, v_DMBTR
endat.
endloop.
Edited by: Subhankar Garani on Sep 16, 2008 12:20 PM
09-16-2008 11:25 AM
09-18-2008 12:37 PM
Hi,
You do like this.
data : sum type i,
sum1 type i.
loop at it_mseg into wa_mseg where bwart = '901'.
sum = sum + wa_mseg-bpmng.
sum1 = sum1 + wa_mseg-dmbtr.
endloop.
Thanks.
09-18-2008 12:38 PM
09-18-2008 12:55 PM