2011 Feb 11 1:10 AM
I have the following requirement
ITAB has fields
PO# PO_LINE# ............ PRICE
100 1 500
100 2 100
200 1 300
300 1 200
300 2 700
300 3 100
and my required output in ALV is
PO# PO_LINE# ............ PRICE
100 1 500
100 2 100
Total 600
200 1 300
Total 300
300 1 200
300 2 700
300 3 100
Total 1000
i want to compute the total price for each PO#.
Can someone please suggest how ?
Thank u so much.
2011 Feb 11 2:12 AM
ALV has the total and subtotal function,
why do you like this? may be you can use the idoc
2011 Feb 11 2:40 AM
Hello all,
Appreciate very much your responses...
but i have to also send this itab with total calculated via email as xls file. so i would want to do this at itab level and not for just alv display.
can i use any control break statements to achieve this ?
2011 Feb 11 3:17 AM
Yes, you can use the control break statements. First sort the internal table and then in the loop u can use on change of PO(also check at new). do the sum.
Thanks and Regards,
C Naresh
2011 Feb 11 8:58 AM
Hi,
Seems you are facing problem in using AT END on two fields since we cannot give AT END
on two fields in a single statement. If this is the case then you can use below approach.
Create another internal table and in this table give one column say KEY which will contain
concatenated value of fields PO# PO_LINE#. Sort internal table on this field KEY and
tThen loop this new table and Use AT END OK key(concatenated value of fields PO# PO_LINE#)
& SUM functinality.
Regards,
Pawan
2011 Feb 11 9:56 AM
HI,
I have one doubt whether total is field of itab or not?
Thanks
Arun
2011 Feb 11 12:24 PM
@Pawan - i can't use PO&POLINE# together as key as i want to add the net price for all the line items of same PO
@ Arun - itab doesn't actually have the field value. the total of price for each po has to be added and displayed in field PRICE before the next PO row is displayed.
2011 Feb 11 1:30 PM
If you want to add all line items of a PO then simply AT END of PO & SUM will do the job.
2011 Feb 14 5:06 AM
Hi,
I have given some sample code . Try this.
Data:ITTABfinal like ITTAB,
wa like line of ittab,
W_INDEX TYPE SY-TABIX,
w_flag type sy-tabix VALUE 1,
w_counter type sy-tabix VALUE 0.
data: w_total like wa-price.
ITTABfinal[] = ITTAB[].
loop at ittab into wa.
w_counter = w_counter + 1.
w_total = w_total + wa-price.
at end of po#.
clear wa.
wa-price = w_total.
w_INDEX = w_counter + w_flag.
insert wa into ittabfinal index W_INDEX.
w_flag = w_flag + 1.
CLEAR:w_total.
endat.
endloop.
Thanks
Arun