‎2010 Jul 22 10:41 PM
Hi
I have following query & calculation in part-1. I want to change part-1 so that i could achieve the same by Part-2. I know Part-2 is not syntactically good, but any suggestion how to make Part-1 as Part-2. Thanks...
Part-1)
-
SELECT Creation_Date
Rcvd_Date
FROM ZPURCHASE
INTO CORRESPONDING FIELDS OF TABLE ITAB
UP TO 3 ROWS
WHERE Customer = '3000'
ORDER BY Rcvd_Date DESCENDING.
LOOP AT ITAB INTO WA.
WRITE:/ WA-Creation_Date,
WA-Rcvd_Date.
ENDLOOP.
v_sumDays = 0.
v_counter = 0.
LOOP AT ITAB INTO WA.
v_noOfDays = WA-Rcvd_Date - WA-Creation_Date.
v_sumDays = v_sumDays + v_noOfDays.
v_counter = v_counter + 1.
ENDLOOP.
v_leadTime = v_sumDays / v_counter.
-
Part-2)
-
SELECT SUM ( Creation_Date - Rcvd_Date ) / COUNT(*)
FROM ZPURCHASE
INTO CORRESPONDING FIELDS OF TABLE ITAB
UP TO 3 ROWS
WHERE Customer = '3000'
ORDER BY Rcvd_Date DESCENDING.
-
‎2010 Jul 23 5:26 AM
Hi
select creation_date Rcvd_date from ZPURCHASE into table itab up to 3 rows where Customer = 3000.
v_sumDays = 0.
v_counter = 0.
loop at itab into wa sort by Rcvd_date descending.
v_noOfDays = WA-Rcvd_Date - WA-Creation_Date.
v_sumDays = v_sumDays + v_noOfDays.
v_counter = v_counter + 1.
ENDLOOP.
I think you cannot do calculations in Select statement as you have declared in PART2.
Aggregate functions can be performed on one field or cannot do calculation other than their own functionality.
to achieve your requirement you need to do your own calculations, As you have done in your part1.
Please check the above code its almost dimilar to your code
But do not use move corresponding.
hope it make you clear.
Thanks
Lalit Gupta
‎2010 Jul 23 6:55 AM
Hello,
Code written in part 2 will not work, you have to do your own calculation like you have done in part 1.
Also your addition to select query 'into corresponding fields of table' can be avoided and you should check v_counter is initial or not before calculating v_leadTime.
Hope this helps.
‎2010 Jul 23 2:24 PM
‎2010 Jul 23 2:25 PM