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

Consolidating the SELECT Statement --- ABAP

Former Member
0 Likes
687

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.

-


4 REPLIES 4
Read only

Former Member
0 Likes
631

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

Read only

Former Member
0 Likes
631

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.

Read only

0 Likes
631

Thanks Adarsh and Lalit for your inputs.....

Read only

Former Member
0 Likes
631

Closing the thread...