‎2007 Aug 24 4:48 PM
Hi gurus,
I have an internal table it_temp where I have the following fields:
custno.
material no.
volume
percentage
now I need to calculate percentage, and percentage is calculated as below:
unique id u01 u01
custno. 201 202
material no. 123 154
volume 200 500
percentage
so based on above example the percentage should be :
for cust no. 201 200/700
and for cust no. 202 500/700
now I need to post this percentage in my internal table it_temp, the key fields in the table are unique id, custno, and material no.
so can just help me out how to do it
Thanks
Rajeev Gupta
‎2007 Aug 24 4:56 PM
hi,
first get the sum of all the customers.
data : lv_sum like tab-volume.
loop at itab.
at last.
sum.
lv_sum = itab-volume.
endat.
endloop.
loop at itab.
itab-percentage = itab-volume / lv_sum.
modify itab index sy-tabix.
endloop.
‎2007 Aug 24 5:13 PM
Hi Mahesh,
I need to get the sum of the volume as per the unique id, and then I need to divide the volume of each customer id by the total volume of that unique id,
so for example if there are three customers in U01 with volume 100, 200, and 300
then I need to post the percentage of first customer as 100/600, second 200/600 and 300/600
and if there are two customers in U02 with volume 500 and 700
then I need to post percentage of first customer as 500/1200, second 700/1200
so can you please tell me how to achieve this.
Thanks
Rajeev Gupta
‎2007 Aug 24 5:49 PM
CHECK THIS CODE
REPORT ztestprg.
data : begin of itab occurs 0,
id(3) type c,
cust(10) type c,
volume type i,
percent type p decimals 2,
end of itab.
data : begin of Jtab occurs 0,
id(3) type c,
cust(10) type c,
volume type i,
percent type p decimals 2,
end of Jtab.
itab-id = 'U01'.
ITAB-CUST = 1000.
ITAB-VOLUME = 200.
APPEND ITAB.
itab-id = 'U01'.
ITAB-CUST = 2000.
ITAB-VOLUME = 200.
APPEND ITAB.
itab-id = 'U02'.
ITAB-CUST = 1000.
ITAB-VOLUME = 200.
APPEND ITAB.
itab-id = 'U02'.
ITAB-CUST = 2000.
ITAB-VOLUME = 200.
APPEND ITAB.
itab-id = 'U03'.
ITAB-CUST = 1000.
ITAB-VOLUME = 200.
APPEND ITAB.
START-OF-SELECTION.
JTAB[] = ITAB[].
SORT ITAB BY ID CUST.
LOOP AT ITAB.
AT END OF ID.
SUM.
LOOP AT JTAB WHERE ID = ITAB-ID.
JTAB-PERCENT = JTAB-VOLUME / ITAB-VOLUME.
MODIFY JTAB INDEX SY-TABIX.
ENDLOOP.
ENDAT.
ENDLOOP.
LOOP AT JTAB.
WRITE 😕 JTAB-ID, JTAB-CUST,JTAB-VOLUME,JTAB-PERCENT.
ENDLOOP.
tHANKS
MAHESH
‎2007 Aug 24 4:57 PM
Hi,
clear w_percentage.
Loop at it_temp.
w_percentage = w_percentage + it_temp-percentage.
endloop.
Loop at it_temp.
it_temp-percentage = w_percentage.
append it_temp.
endloop.
Regards,
Widad.