Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index file repeatedly disappears/deleted

Status
Not open for further replies.

breezett93

Technical User
Jun 24, 2015
128
US
Hello.

So I have a program that reads in a CSV file and copies its contents into a DBF. After some minor formatting is done, the table is then copied into the final DBF file.


This process used to work smoothly, but recently, the .CDX that is located with the final DBF file disappears every time the program is run which then causes the accounting software to error out because the required index is missing/wrong. I can manually recreate the index just fine, but then I'll run the program, and it disappears. I've also tried creating the index within the program which does work. However, the accounting software still errors out about an index issue.

To get a better visual, this is the whole program. Not much to it.

Code:
CLOSE ALL DATABASES
SET EXCLUSIVE ON
SET SAFETY OFF

*Convert CSV to DBF
SELECT A
USE f:\directory1\Data\PRXPST02

SET EXCLUSIVE OFF

APPEND FROM f:\directory2\PRXPST02.CSV DELIMITED

*Remove first line
DELETE For Xseqno = 'xseqno' 
PACK

*Send it to SBT
COPY TO f:\directory3\prxpst02.DBF

*Clear out file
ZAP

*Create index

*SELECT B
*USE f:\directory3\prxpst02.DBF
*CD f:\directory3
*INDEX ON Xseqno TO PRXPST02.CDX

QUIT
RETURN

Thank you.
 
You are overwriting a DBF that has a CDX with one that doesn't. You are not "copying to" -- you are replacing.

I don't see how this ever could have worked. This will preserve your index though:

Code:
Use f:\directory3\prxpst02.DBF Exclusive
Zap
Append from f:\directory1\Data\PRXPST02
 
Indeed you could copy over data and index if you COPY TO ... WITH CDX, but that would require f:\directory1\Data\PRXPST02.DBF to have a CDX in the first place.
If f:\directory1\Data\PRXPST02.DBF has no CDX then it doesn't matter, if there is a CDX file f:\directory3\prxpst02.CDX, it's not associated with the DBF you copy there and just because there is a CDX it also isn't updated with the COPY TO, that would just be the case with an APPEND FROM f:\directory1\Data\PRXPST02.DBF, not with a COPY TO.

Also, if you want to have an index tag in the prime CDX file of a CDX, you INDEX ON Xseqno TAG Xseqno and don't specify TO some.CDX, that alone makes it a secondary CDX file (I think, not 100% sure), even though it is named as the primary.


The way I'd do that is

Code:
CLOSE ALL DATABASES

*Create empty import cursor
SELECT * FROM f:\directory3\prxpst02.DBF WHERE .F. ;
   INTO Cursor crsImport READWRITE

*Convert CSV to DBF
APPEND FROM f:\directory2\PRXPST02.CSV DELIMITED
INDEX ON Xseqno TAG Xseqno

*Send it to SBT excluding header row
COPY TO f:\directory3\prxpst02.DBF WITH CDX FOR RECNO()>1

QUIT
 
I'd also use APPEND FROM f:\directory2\PRXPST02.CSV TYPE CSV, as that will remove the first line anyway.

Whether that works only depends on the field names being as in the CSV (haven't tried differing names, though). If you have your own names, then the same structure of data with just differing names can be imported with DELIMITED for sure, so that's OK and no big thing to change, but you have the additional header line in your data (as far as fields can import text values at all).

Bye, Olaf.
 
Thank you for the replies. I'll update if the testing doesn't work out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top