2013 Mar 28 2:19 PM
Hi Experts,
I need a help with one BW Start Routine.
I´m extracting 52 weeks for a report.
In this report I have the stock for each week, and the stock cost for each week.
But, I may have more than one week with zero stock and zero stock cost, and I need to create an average stock for this 52 weeks, BUT excluding the weeks with zero stock.
So for an example, if I have 42 weeks with stock and 10 weeks without stock, I´ll have to add all the stock per week and than split by 42.
Can anyone help me, please?
Thanks in advance.
2013 Mar 28 3:25 PM
Insure that all the weeks are always transmitted in the same packet. Then, if required SORT the package, loop at the package and sum values and increment a counter when stock not zero, at end divide sum by counter and use a MODIFY itab lines statement.
Regards,
Raymond
Hi Experts,
I need a help with one BW Start Routine.
I´m extracting 52 weeks for a report.
In this report I have the stock for each week, and the stock cost for each week.
But, I may have more than one week with zero stock and zero stock cost, and I need to create an average stock for this 52 weeks, BUT excluding the weeks with zero stock.
So for an example, if I have 42 weeks with stock and 10 weeks without stock, I´ll have to add all the stock per week and than split by 42.
Can anyone help me, please?
Thanks in advance.
2013 Mar 28 2:47 PM
Hello,
Eduardo Carreira Martins Gonçalves wrote:
So for an example, if I have 42 weeks with stock and 10 weeks without stock, I´ll have to add all the stock per week and than split by 42.
can you describe this above line ???
Thanks
Sabyasachi
2013 Mar 28 3:05 PM
Ok, let´s make an example.
| Week | Stock | Stock Value |
| 1 | 4324 | $ 432.445,00 |
| 2 | 5050 | $ 9.876,00 |
| 3 | 4354 | $ 987,00 |
| 4 | 76476 | $ 9.876,00 |
| 5 | 64 | $ 88,00 |
| 6 | 764674 | $ 987,00 |
| 7 | 7645 | $ 567.654,00 |
| 8 | 0 | $ - |
| 9 | 467764 | $ 9.876,00 |
| 10 | 0 | $ - |
| 11 | 7647654 | $ 987.654,00 |
| 12 | 6457457 | $ 98.765,00 |
| 13 | 0 | $ - |
| 14 | 0 | $ - |
| 15 | 0 | $ - |
| 16 | 0 | $ - |
| 17 | 0 | $ - |
| 18 | 0 | $ - |
| 19 | 0 | $ - |
| 20 | 6543 | $ 5.467,00 |
| 21 | 653 | $ 4.567,00 |
| 22 | 653 | $ 644,00 |
| 23 | 653 | $ 67.546,00 |
| 24 | 653 | $ 456,00 |
| 25 | 653 | $ 5.467,00 |
| 26 | 653 | $ 87.654,00 |
| 27 | 653 | $ 7.654,00 |
| 28 | 653 | $ 7.654,00 |
| 29 | 0 | $ - |
| 30 | 0 | $ - |
| 31 | 0 | $ - |
| 32 | 0 | $ - |
| 33 | 9857654 | $ 876.556.789,00 |
| 34 | 98765 | $ 876.543,00 |
| 35 | 34567 | $ 54.387.564,00 |
| 36 | 8765 | $ 4.566.543,00 |
| 37 | 3456 | $ 546.765,00 |
| 38 | 0 | $ - |
| 39 | 0 | $ - |
| 40 | 0 | $ - |
| 41 | 0 | $ - |
| 42 | 0 | $ - |
| 43 | 9876 | $ 7.654.654,00 |
| 44 | 87634 | $ 367.989.876,00 |
| 45 | 3456 | $ 435.678.765,00 |
| 46 | 1234 | $ 45.677.654,00 |
| 47 | 5764 | $ 456.754,00 |
| 48 | 345 | $ 4.323.456,00 |
| 49 | 0 | $ - |
| 50 | 0 | $ - |
| 51 | 0 | $ - |
| 52 | 0 | $ - |
So in this case we have 30 weeks with stock and 22 weeks without stock.
And I need to add all the stock of this 30 weeks and split by the number of weeks with stock to have an average stock.
Total Stock:
| 25558745 |
Average Stock:
| 851958,2 |
2013 Mar 28 3:47 PM
Hello,
you have to use LOOP.......ENDLOOP statement.
if stock ne 0.
sum = stock + sum. sum is a variable.
endif.
at last, sum value is total stock 25558745.
for average : use: sum / 52.
Thanks
Sabyasachi
2013 Mar 28 4:05 PM
Hello,
at 1st try to enhance total stock and avg stock in datasource (rsa6) on selective datasource in ecc site, i think loading performence will be better then start routine execute in bi site. if it is not possible then try to use the code in start routine.
that means customizing datasource.
for loading pourpose in bw site use end routine for better perfomence.
Thanks
Sabyasachi
Message was edited by: Sabyasachi Karforma
2013 Mar 29 6:40 AM
Hi,
In the above code, you can include a statement after the line '
sum = stock + sum' as below.
sum = stock + sum
counter = counter + 1
average = sum / counter.
Dont forget to Initialize the variables in the beginning.
Hope this will help you better.
Thank you.
2013 Mar 28 2:52 PM
Hello,
start routine is mandatory or not for your case?
if not then we can try to solve this problem in different way
like in query design.
Thanks
Sabyasachi
2013 Mar 28 3:16 PM
Unfortunately, I have to do this loading data, because we are facing a very bad performance issue with this report.
It´s a sale and stock report, with one year of data. This report will be used in a universe for BO 3.1.
So, I have to do every calculation in loading time.
2013 Mar 28 3:25 PM
Insure that all the weeks are always transmitted in the same packet. Then, if required SORT the package, loop at the package and sum values and increment a counter when stock not zero, at end divide sum by counter and use a MODIFY itab lines statement.
Regards,
Raymond
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |