Application Development and Automation 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: 
Read only

SUM

Former Member
0 Likes
769

Dear All,

I have the internal table like this. I want total for DMBTR, based on BELNR, EBELN.

BELNR EBELN LIFNR DMBTR BUDAT

1500000018|4500002958|ROYAL | 500.00 |20080512

1500000018|4500002957|ROYAL | 5000.00 |20080512 1500000018|4500002957|ROYAL | 6000.00 |20080512

1500000018|4500002558|ROYAL | 5000.00 |20080512

1500000018|4500002958|ROYAL | 500.00 |20080512 1500000019|4500002958|ROYAL | 500.00 |20080512

1500000019|4500002958|ROYAL | 1500.00 |20080512

I WANT OUTPUT LIKE

BELNR EBELN LIFNR DMBTR BUDAT

1500000018|4500002558|ROYAL | 5000.00 |20080512

1500000018|4500002957|ROYAL |11000.00 |20080512

1500000018|4500002958|ROYAL | 1000.00 |20080512

1500000019|4500002958|ROYAL 2000.00 |20080512

Which is the suitable code for above output??

Thanks and Regards

Suresh

6 REPLIES 6
Read only

Former Member
0 Likes
743

Use collect while passing the same records to another internal table.

or use control break statements.

Try it it will work.

Regards,

madan.

Read only

Former Member
0 Likes
743

Hi,

1. First sort the internal table ascending by BELNR and EBELN.

Sort itab by belnr ebeln ascending.

2. Loop at itab into ls_itab.

at end of ebeln.

sum.

append ls_itab to itab1.

endat.

endloop.

3. loop at itab1.

        • print on the screen****

endloop.

Thank you.

Reward points if found useful.

Read only

Former Member
0 Likes
743

BELNR EBELN LIFNR DMBTR BUDAT

1500000018|4500002558|ROYAL | 5000.00 |20080512

1500000018|4500002957|ROYAL |11000.00 |20080512

1500000018|4500002958|ROYAL | 1000.00 |20080512

1500000019|4500002958|ROYAL 2000.00 |20080512

Hi,

Loop at table.

at end of lifnr.

move belnr ebeln lifnr to new table.

append to some other table.

clear amt.

endat.

amt = amt + table-amt.

endloop.

Read only

Former Member
0 Likes
743

Declare Itab1 which is of the same type as Itab.

Sort itab by BELNR EBELN.

LOOP AT itab.

COLLECT itab INTO itab1.

ENDLOOP.

Read only

Former Member
0 Likes
743

Hi,

declare

a variable l_EBELN

a flag type i value 0

sum like DMBTR.

First sort the internal table by 'BELNR' 'EBELN'. then loop at the table into an workarea (wa).

Apply the following logic.......

if l_ebeln <> wa-ebeln and flag = 1 (it not the first record).

print data.

l_ebeln = wa-ebeln.

sum = wa-DMBTR.

else

flag = 1.

l_ebeln = wa-ebeln.

sum =sum + wa-DMBTR.

endif

Read only

Former Member
0 Likes
743

Hi Friend,

While useing inner join u can use like this.

as shown below.

SELECT abelnr aebeln a~lifnr

SUM( bdmbtr ) abudat

INTO some itab

it will show sum of ur field dmbtr

Reward points if usefull.