Teknik,
I didn't see in the thread anywhere, I can explain one part of you problem. The issue of re-query immediatly afterward returning so quickly is because the data you are fetching is already cached.
Now, your second issue, I'm going to assume a few things, but I think we might be able to speed this up. (Similar ideas from above, but I have a slightly weird view on these things that sometimes works...)
Based on your code below:
SELECT ACC.N_AC_HEAD, ACC.C_AC_NAME, ACC.N_MH, ACC.N_SH,;
FROM ACC, MH;
WHERE ACC.N_MH = MH.N_MH AND;
MH.C_MHTYPE = "DEBTORS";
INTO CURSOR TEMP
Now, try doing the following:
I'm assuming that the MH table is more significant, since that is where your "Criteria" really is. First, if it does not already exist, create the following index:
(With MH in the actively selected work area):
INDEX ON C_MHTYPE TAG C_MHTYPE
(With ACC in the actively selected work area):
INDEX ON N_MH TAG N_MH
(Don't mean to insult your intelligence, but ONLY do this once, from the command line, don't put it in your code, it will take unnecessary time.
Next, if I'm going to use a basic structure over and over again, I usually don't use CURSORS with select statments. Mostly, because if something else happens after the actual select, and it's a big one, I don't want to go through all that hassle again. Just a personal preference. In this case, we will not use SELECT anyway, to see if we can get better performance from 'Hack by hand'. To that end, create a table (I'd call it TDEBTORS, or something. Prefix T tells me, I can always use a ZAP command with confidence on a table, because it is strictly Temporary.) Make the table with the following fields: ACC.N_AC_HEAD, ACC.C_AC_NAME, ACC.N_MH, ACC.N_SH, and their appropriate types and size. Now, run this code:
IF NOT USED('TDEBTORS'
SELECT 0
USE TDEBTORS
ZAP
ENDIF
*
IF NOT USED('ACC')
SELECT 0
USE ACC
SET ORDER TO N_MH
ENDIF
*
IF NOT USED('MH')
SELECT 0
USE MH
SET ORDER TO C_MHTYPE
ENDIF
*
SELECT MH
SEEK 'DEBTORS'
IF FOUND()
DO WHILE MH.C_MHTYPE = 'DEBTORS'
SELECT ACC
SEEK MH.N_MH
*
IF FOUND()
SCATTER MEMVAR
SELECT TDEBTORS
APPEND BLANK
GATHER MEMVAR
ENDIF
*
SELECT MH
SKIP
ENDDO
ENDIF
In a database with only 20,000 records, with these indexes, (assuming I have what it is you are trying to capture correct from looking at your SQL code), this should run very, very fast. If this is being accessed across a Novell Network that is using a version of Netware 4.0 or higher on a 10Base-T connection... well, good luck. I have had HUGE problems getting things to work quickly across those networks, but usually on tables that have 1,000,000+ records. Please let me know if this helps.
-Scott