# Calculate SUM based in condition in iTAB

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.

##### Tags:

##### Former Member replied

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