cancel
Showing results for 
Search instead for 
Did you mean: 

Sumarise table

Former Member
0 Kudos

Hi

I have one internal table its structure

BEGIN OF wa_data OCCURS 0,

ename LIKE pa0001-ename, 'Sales Id

mmyyyy(8) TYPE c, " Month Year

bezei LIKE tvaut-bezei, " REason

netwr LIKE vbak-netwr, "Net Value of SO inDoc Currency

pernr TYPE pa0001-pernr, "Sales ID

lcamt LIKE vbak-netwr, "Net Value of SO Local Currency

nos TYPE i,

audat LIKE vbak-audat, "Document date

vkbur LIKE vbak-vkbur,

vkorg LIKE vbak-vkorg,

END OF wa_data.

I needed to make a internal table with sum of amount for each employee for each month for each reason.

emp id Reason monthyear amount

1 aaa JAN09 1100.00

2 aaa JAN09 1200.00

3 aaa JAN09 1400.00

4 BBB JAN09 1300.00

How to get a sum from the a details table. detail table having so many records for each employee for for each reason for each month

Regards

Sebastian JOhn

Accepted Solutions (1)

Accepted Solutions (1)

alex_m
Active Contributor
0 Kudos

Use COLLECT statement.

Answers (5)

Answers (5)

Former Member
0 Kudos

Thanks

Former Member
0 Kudos

hello Sebastian John ,

You can also use the AT END OF,

LOOP AT i_tab.

AT END OF emp id

SUM.

""Write ur fields which u want to sum""""

APPEND i_itab.

CLEAR : i_itab

ENDAT.

ENDLOOP.

Regards,

vanu.

Former Member
0 Kudos

hi john,

use COLLECT statement OR

loop the internal table and add the fields based on the key.

regards,

venkat.

Former Member
0 Kudos

Hi ,

You can use the COLLECT statement .

Or you can use the if condition inside the loop of the 1st table and there you can add

and and append in the second table. Following code might help you - -

DATA : t_sflight LIKE TABLE OF sflight,
       fs TYPE sflight,
       BEGIN OF fs_final,
         carrid TYPE spfli-carrid,
         price TYPE sflight-price,
       END OF fs_final,
       t_final LIKE TABLE OF fs_final.
DATA : w_carrid TYPE s_carrid,
         w_price TYPE sflight-price.
SELECT * FROM sflight INTO TABLE t_sflight.

SORT t_sflight.
LOOP AT t_sflight INTO fs.
  IF fs-carrid EQ w_carrid or sy-tabix eq 1. " IF condition
    w_price = fs-price + w_price.  " Adding
  ELSE.
    fs_final-carrid = w_carrid.
    fs_final-price = w_price.
    APPEND fs_final TO t_final.  " Appending to final table
    CLEAR w_price.
  ENDIF.
  w_carrid = fs-carrid.
ENDLOOP.

fs_final-carrid = fs-carrid.
fs_final-price = w_price.
APPEND fs_final TO t_final.

Regards

Pinaki

Former Member
0 Kudos

Hi,

Try using COLLECT statement or you can try using Internal table events for getting the sum from the Details table.