LPARAMETERS lpcTable,lpcExport2TableName,m.lpcexportpath *lpcTable the table name e.g. dbname!tablename *lpcExport2TableName a free table name the exported *m.lpcexportpath the directory into which you want to save the exports LOCAL ARRAY a(1,16),captions(1) LOCAL lnLen,i,lcexportto,lcvalues,lcAlias,lcfield,lcfields *use the table name as alias name IF "!" $ m.lpcTable ; THEN m.lcAlias = GETWORDNUM(m.lpcTable,2,"!") ELSE m.lcAlias = JUSTSTEM(m.lpcTable) ENDIF * if table not open then open it IF NOT USED(m.lcAlias) ; THEN USE &lpcTable ENDIF *get the field names m.lnLen = AFIELDS(a,m.lcAlias) m.lcexportto = [] m.lcvalues = [] m.lcfields = [] *get the captions FOR i =1 TO m.lnLen DIMENSION captions(i) m.lcfield = m.lcAlias+'.'+a(i,1) m.lcfields = m.lcfields + [ALLTRIM(]+m.a(i,1)+[)+","] m.lcvalues = m.lcvalues + 'TRANSFORM('+m.lcfield+')' m.lcexportto = m.lcexportto + a(i,1)+' M' m.captions(i) = DBGETPROP(m.lcfield,"FIELD","CAPTION") IF i#m.lnLen ; THEN m.lcexportto = m.lcexportto + "," m.lcvalues = m.lcvalues + ',' m.lcfields = m.lcfields + '+' ENDIF NEXT m.lpcExport2TableName = JUSTSTEM(m.lpcExport2TableName) LOCAL lctemp,lctemp2,lcexported m.lctemp = ADDBS(m.lpcexportpath)+m.lpcExport2TableName *create the exported table, if it's there it might ask you to *replace it depending on set safety on or off CREATE TABLE &lctemp FREE ; (&lcexportto) *make the captions first record of the exporeted table INSERT INTO &lpcExport2TableName FROM ARRAY captions *then insert the values into exported table SELECT &lcAlias SCAN NOOPTIMIZE INSERT INTO &lpcExport2TableName ; VALUES (&lcvalues) ENDSCAN * there are records to export IF RECCOUNT(m.lpcExport2TableName)>0 ; THEN SELECT &lpcExport2TableName m.lctemp = ADDBS(m.lpcexportpath)+m.lpcExport2TableName m.lctemp2 = ["]+m.lctemp +[.csv"] m.lcexported = [] * create CSV SCAN NOOPTIMIZE m.lcexported = m.lcexported + &lcfields + CHR(13)+CHR(10) ENDSCAN IF NOT EMPTY(m.lcexported) ; THEN * save it to file STRTOFILE(m.lcexported,m.lctemp2) ENDIF ENDIFIf call the program export2.prg, then you can:
open database mydatabase do export2 with "mydatebase!table1","exported","c:\temp"Then in the c:\temp folder you should see exported.dbf,exported.fpt and exported.csv
"Do not let any unwholesome talk come out of your mouths,
but only what is helpful for building others up according to their needs,
that it may benefit those who listen."
- Ephesians 4:29-30 NIV
Dare to Question -- Care to Answer
Time is like water in a sponge, as long as you are willing you can always squeeze some.
--Lu Xun, Father of Modern Chinese Literature