OK - here's the code that I wrote...it works, but I've only tested it with the first two files created...I will have to keep a close eye on it for the first few weeks, to make sure that there aren't any structures that I haven't allowed for.
*************************************************************************************************
*************************************************************************************************
***
*** CDR Import
*** 12/04/2008 David Blum DMKB Consulting Corp
***
*** This program will look for all ".TXT" files in the startup folder, and attempt to import them
*** into the CDRWhole table.
***
*** The expected structure is a two-line format, where line 1 contains the record type, date, time
*** and duration, and the line 2 conains the Caller ID and DNIS information.
***
*** By APPENDing FROM the file as SDF, and including an appropriate FOR clause, I could split the
*** .TXT file in two, JOIN them with a SQL statement, then APPEND the resulting TABLE into the
*** master table, CDRWhole.
***
*** This HEAVILY relys on the fact that the records will be RIGHT NEXT TO EACH OTHER and that there
*** won't be any jumbling of the data.
***
*** Additionally, I had to STRTRAN the file's contents due to the propensity for the CDR output to
*** insert random NULL values in the data in unpredictable locations.
***
***
PARAMETERS llDebug
PUBLIC lcOrigCDRFile, lcFixedCDRFile, laCDR [1], liCDRFiles, liCurrCDR
IF TYPE ([llDebug]) = [L]
llDebug = IIF (llDebug, [Y], [N])
ENDIF
IF UPPER (llDebug) = [Y]
SET STEP ON
ELSE
SET STEP OFF
ENDIF
CLOSE DATABASES ALL
SET EXCLUSIVE OFF
SET SAFETY OFF
WAIT WINDOW NOWAIT NOCLEAR [Locating CDR Files to Import...]
m.liCDRFiles = ADIR (laCDR, [*.TXT])
IF m.liCDRFiles = 0
WAIT WINDOW NOWAIT [No files found to import, exiting...] TIMEOUT 5
RETURN
ENDIF
USE CDRLine1 EXCLUSIVE IN 0
USE CDRLine2 EXCLUSIVE IN 0
USE CDRWhole SHARED IN 0
FOR liCurrCDR = 1 TO m.liCDRFiles
WAIT WINDOW NOWAIT NOCLEAR [Importing ] + laCDR [liCurrCDR, 1] + [...]
DO ImpCDR WITH laCDR [liCurrCDR, 1], DATETIME()
NEXT liCurrCDR
WAIT CLEAR
WAIT WINDOW [Done!] TIMEOUT 5
RETURN
***
***
*************************************************************************************************
*************************************************************************************************
*************************************************************************************************
*************************************************************************************************
***
***
PROCEDURE ImpCDR
PARAMETERS lcSelCDRFile, ltStamp
PRIVATE lcFixedCDR, lcCDRContents, lcCDRFixedContents
lcFixedCDR = STUFF (lcSelCDRFile, AT ([.], lcSelCDRFile), 0, [-fixed])
lcCDRContents = FILETOSTR(lcSelCDRFile)
lcCDRFixedContents = STRTRAN (lcCDRContents, CHR(0))
?STRTOFILE (lcCDRFixedContents , lcFixedCDR)
SELECT CDRLine1
ZAP
APPEND FROM (lcFixedCDR) type SDF FOR LEFT(CDRLine1.rectype ,1)<>[ ]
REPLACE ALL CDRLine1.linenum WITH RECNO(), CDRLine1.imp_stamp WITH ltStamp
SELECT cdrline2
ZAP
APPEND FROM (lcFixedCDR) type SDF FOR LEFT(CDRLine2.fd, 1)=[ ] AND cdrline2.chginfo<>[ ]
REPLACE ALL CDRLine2.linenum WITH RECNO()
SELECT * FROM cdrline1 LEFT JOIN cdrline2 ON cdrline1.linenum = cdrline2.linenum INTO TABLE CDRImported
SELECT cdrwhole
APPEND FROM CDRImported
USE IN CDRImported
DELETE FILE CDRImported.DBF
RENAME (lcFixedCDR) TO ([Imported\] + lcFixedCDR)
RENAME (lcSelCDRFile) TO ([Imported\] + lcSelCDRFile)
RETURN
***
***
*************************************************************************************************
*************************************************************************************************
Anyway - any feedback will be greatly appreciated!