mrfitness


Is it possible to copy a cursor to a text with the headings showing
The code below gives me a text file with only values:

a = alltrim(contractno)
b = a + ".txt"
select * ... into cursor curTest
copy to &b sdf





Re: Copying a cursor to a text file with headers

Naomi Nosonovsky


See my reply in your other thread. I suggested to use STRTOFILE/FILETOSTR as one of the possible ways to solve the problem.




Re: Copying a cursor to a text file with headers

hangover

I don't think that there is any straightforward way of doing it. You could achieve the result through creating a low-level file and populating it through code. However, it would probably be best to use a delimited format (such as tab-delimited - see example below) rather than SDF because the field names will not necessary fit into the same width as the field contents.

Code Snippet

LOCAL lnFileHandle

* Create low-level file

lnFileHandle = FCREATE (lcFilename)

* Insert field names

FOR lnField = 1 TO FCOUNT()

IF lnField = FCOUNT ()

= FPUTS (lnFileHandle, FIELD (lnField))

ELSE

= FWRITE (lnFileHandle, FIELD (lnField) + CHR (9))

ENDIF

ENDFOR

* Insert Values

SCAN ALL

FOR lnField = 1 TO FCOUNT()

leValue = EVALUATE (FIELD (lnField))

IF VARTYPE (leValue) <> "C"

leValue = TRANSFORM (leValue)

ENDIF

IF lnField = FCOUNT ()

= FPUTS (lnFileHandle, leValue)

ELSE

= FWRITE (lnFileHandle, leValue + CHR (9))

ENDIF

ENDFOR

ENDSCAN

= FCLOSE (lnFileHandle)







Re: Copying a cursor to a text file with headers

CetinBasoz

Code Snippet

lcFileName = alltrim(contractNo)+".txt"

select ... into cursor curTest

copy to (m.lcFileName) type csv





Re: Copying a cursor to a text file with headers

Tamar E. Granor

How about the LIST command:

USE MyFile
LIST ALL OFF TO FILE (m.ResultFile)

Tamar