It's quite bad documented code there. I see my fear is fulfilled, you're not having any index on the cursors you create.
Also you do some GRoup By which wouldn't work since VFP8.
1. SELECT edwkey,ssn,Open_dt1,close_dt1,status FROM Tempo GROUP BY 1;
INTO CURSOR A1 READWRITE
What ssn,open_dt1,close_dt1, status values would you expect or need, if there are several records with the same edwkey? min, max, first, last, any?
2. SELECT * FROM A2 WHERE edwkey = Vedwkey ORDER BY open_dt1 ASC INTO CURSOR A3 READWRITE
same question, what values of other fields would you expect and need from all other fields?
3. misleading var names:
A2QTT = RECCOUNT("A1")
A1qtt = RECCOUNT("A3")
???
4. No need for a loop directly before Endfor
5. use EXIT instead of cuenta = A1QTT + 1 to end the loop
6. don't copy code, adjust your IF statement simply
Code:
If Tstatus = "C" Or Tstatus = "O" Then
If Between(TOpen,Vopen,Vclose) Then
If TClose > Vclose Then
Vclose = TClose
Endif
Else
If TOpen > Vclose Then
Vopen = TOpen
Vclose = TClose
Endif
Endif
If Tstatus = "O" Then
Exit
Endif
Endif
No wonder you can't improve that, it's a total mess.
Let's see what you end up with in Vopen and Vclose:
You change Vopen to Topen every time Topen>Vclose, that's interesting, I donÄt understand why. You change Vclose to TClose, everytime Tclose>Vclose, that's simply calculating Max(Tclose), but you also do so, if Topen>Vclose.
The catch is that during the life of the client doing business with the company they may be time when the client close all of the accounts and then came back later on, so the client since date that they want should be the open date of the first account since it last came onboard with the company
Rereading this you don't want simply Min(Open_dt1) and Max(Close_dt1). The time intervals regarding seperate accounts can overlap and there can be intervals without any account. Let's talk in examples here:
A client "client A" has account 1 from 01/01/1990 to 01/01/1995, account 2 from 01/01/1993 to 01/01/1998 and account 3 from 01/01/1999 to 12/31/9999 (no end yet).
What do you need in the final result
wither both client realtionships
client A, from 01/01/1990 to 01/01/1998
client A, from 01/01/1999 to 21/31/9999
or only the last clientship
client A, from 01/01/1999 to 21/31/9999
And do you set close_dt1 to 12/31/9999 like I did or do you leave it EMPTY() or even NULL if the account is not yet cloesd?
Bye, Olaf.