Hi Santosh,
With loops/whiles/curso you always will have a sequential execution of code.
In order to parallelize you need to rethink how you calculate the time status and imagine sets of data, join everything and compute at end. See a sample of idea without focusing on syntax just to quick expression and I hope understanding:
on this sample status are
01-creation
02-analyzed
03-closed
and figures will be difference between steps:
- time_of_analyzes (difference between 01 and 02)
- time_to_close (02 and 03)
- quote_life_time (01-03)
On this pseudo-code the idea of sequencial code is collect the figures and decide it later, ok?
select quote,date from quotes.
select status,timestamp from quotes_status where quote=quotes-quote.
if quotes_status-status = '01'.
lv_creation = quotes_status-timestamp.
elseif quotes_status-status = '02'.
lv_analyzed = quotes_status-timestamp.
elseif quotes_status-status = '03'.
lv_closed = quotes_status-timestamp.
endif
endselect.
var_out = select quotes-quote,quotes-date,
(:lv_analyzed-:lv_creation) as time_of_analyzes,
(:lv_closed-:lv_analyzed) as time_to_close,
(:lv_closed-:lv_creation) as quote_time_life from dummy
union select * from :var_out;
endselect.
To transpose this to "set" thinking, you should have at least:
- 4 projections (quotes, quotes_status_01, quotes_status_02, quotes_status_03)
- left outer join quotes with the other 3 views
At end you will have in hands:
- one view all fields you need for calculation
- do a projection and made the computation to collect the figures
** Probably your IF's aren't so simple like this, but it's the basic Idea, you can add the IF's adding more filters on each view or add more views with more information.
The important to understand is that you need to think in sets of data despite loop each row.
Regards, Fernando Da Rós