xsharp.eu • Best Reindexing Routine
Page 1 of 2

Best Reindexing Routine

Posted: Sun Dec 26, 2021 7:54 pm
by hilberg.it
Hi,
I am quite new in the community. While I am porting an app from VO to X# and accessing the files at first through DBFCDX and VO and later with X# and finally with AXDBFCDX, I've noticed that I need to rebuild the indexes at some points. What might be the best routine to rebuild all indexes? Right now I am removing all CDX files from the disk and rebuilding it from scratch. Would DbReindex be just as good? How would a decent routine look like?

Maybe someone wants to share his/her routine or experience?

And last but not least, I am trying to figure out how reindexing could look like with ADS. I don't have access to the CDX files through the API. So there is probably another way.

Thank you very much.

Best Reindexing Routine

Posted: Sun Dec 26, 2021 10:45 pm
by robert
Moritz,
What the DbReindex code does exactly depends entirely on what the developer has chosen.
For the X# driver for example we are saving the index expressions and conditions, then we erase the file and recreate it.
It is very well possible that ADS does the same. But you can't be sure.
If you want to delete the CDX with ADS (especially when the file is on a remote machine), then the best approach is to delete each of the tags in the Cdx (with OrdDestroy). I know from experience that ADS will delete the CDX file when the last tag in it is deleted. After that you can recreate the tags one by one.

Robert

Best Reindexing Routine

Posted: Mon Feb 28, 2022 9:01 am
by hilberg.it
Hi,
I am trying my DBFCDX code on AXDBFCDX and having a hard time on reindexing and (re)creating DBF files. Right now my code to recreate the index files looks something like this:

Code: Select all

oServer:createOrder(cTagName, cFile, cKey, bKey, lUnique)
It throws an Unknown Error on AXDBFCDX. Also my routine to recreate DBF files checks if a file is existing. This will also not work on a remote server connection.

Is anyone from the community willing to share some pieces of code, on how to achieve reindexing, recreation of files on remote ADS? (If reindexing is possible through Advantage Data architect that would be also fine for now.)

Already a big thank you to you!

Best Reindexing Routine

Posted: Mon Feb 28, 2022 10:58 am
by wriedmann
Hi Moritz,
I'm using dictionary based file and order creating routines in both VO and X#.
I never use a packing routine as a problem there could damage the data, but I recreate the dbf table, copy all data and then do a rename.
For the reindexing routine I delete the CDX file and recreate all orders:

Code: Select all

    FOR nCounter := 1 UPTO ALen( _aOrders )
        oOrder      := _aOrders[nCounter]
        if Empty( oOrder:ForCondition )
	        oServer:SetOrderCondition( ,,,,{||ReIndexAppExec()},500,,,,,oOrder:Descending )
        ELSE
            cbCondition     := &("{||" + oOrder:ForCondition + "}")
            oServer:SetOrderCondition( oOrder:ForCondition, cbCondition,,,{||ReindexAppExec()},500,,,,,oOrder:Descending )
        endif
        cbExpression    := &("{||" + oOrder:IndexExpr + "}")
        if oServer:CreateOrder( oOrder:TagName,cFileName,oOrder:IndexExpr,cbExpression,false ) == false
            ErrBox( oWindow, "Fehler beim Erstellen des Orders  " + oOrder:TagName + "/" + self:Name )
			lSuccess	:= false
        endif
    NEXT
HTH
Wolfgang
P.S. this code is at least 20 years old, but it works in many different applications

Best Reindexing Routine

Posted: Mon Feb 28, 2022 12:48 pm
by hilberg.it
Thanks Wolfgang! Appreciate it.
Does this routine even work on a remote ADS Server? Because my call to 'CreateOrder' always returns false on the remote server, but seems to work on the local server. Is the call to 'ReIndexAppExec' something custom from your side or from VO/X#? And finally how would you delete CDX files on remote server? I could not find OrdDestroy call that Robert mentioned.
Thanks

Best Reindexing Routine

Posted: Mon Feb 28, 2022 1:22 pm
by wriedmann
Hi Moritz,
this code works on both local and remote ADS server and on both local and remote DBFCDX.
I'm using it regularly in VO, and the few times I've used it in X# it worked too, but I would have to recheck (had it working using the old SAP RDD).
Wolfgang

Best Reindexing Routine

Posted: Mon Feb 28, 2022 2:13 pm
by wriedmann
Hi Moritz,
I should read the entire message <g>.

Code: Select all

function ReindexAppExec()
	ApplicationExec( EXECWHILEEVENT )
	return true
And to delete the index I use the FErase() function (I have write access to the DBF folder, otherwise it would not work).
Wolfgang

Best Reindexing Routine

Posted: Tue Mar 01, 2022 9:51 am
by g.bunzel@domonet.de
...one note from me:

With a small extension, you can show a progress bar during creating that index:
IF Empty( oOrder:ForCondition )
oServer:SetOrderCondition( ,,,,{||ReIndexAppExec( oServer:OrderInfo(1805) )},500,,,,,oOrder:Descending )
ELSE
...

Function ReindexAppExec(nIndexbar)
// nIndexbar = 0-100 %
ApplicationExec( EXECWHILEEVENT )
RETURN TRUE

I use this eval-block to show a progress bar:
cbEval := { || oDlg:UpdateIndex (oServer:OrderInfo(1805)) }

From the ADS helpfile:
The cbEval code block passed to the DBServer:SetOrderCondition method will not be evaluated for every record the server processes. Instead, it will be evaluated about every two seconds while the index order is created.


HTH

Gerhard Bunzel

Best Reindexing Routine

Posted: Wed Mar 02, 2022 10:33 pm
by hilberg.it
Thanks for your input! :)

Best Reindexing Routine

Posted: Fri Mar 04, 2022 7:06 am
by hilberg.it
Out of curiosity: If I reindex my files with VO or X# using DBFCDX RDD it takes about 15 min for all files. But if I reindex wit X# and AXDBFCDX RDD it is done after 1-2 min!! It seems to work though. Now I am curios why there is such a big difference in time. Does anyone know why? Thanks!