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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to Text file

Status
Not open for further replies.

1962dez

Programmer
Nov 20, 2008
6
CV
Good afternoon,
I need to create a text file like the one attached, with data from a cursor. What command should I use to put the data in the text file and how to respect the columns of each piece of information?
I appreciate any help.
 

Attachments

  • ERP0605C.txt
    136.5 KB · Views: 32
copy to ERP0605C.txt sdf

This is just a simple fixed field text file. If you only want certain fields you can include the "FIELDS ..." switch.
 
Viewing this without automatic line breaks, I see a long record structure which is of the type SDF. At least from line 6 onwards. The clues are defined column widths without delimiters, neither tabs nor commas.

To give an example of producing such a line here's the output of a cursor with 3 char(10) fields:
Code:
Create Cursor crsExport (c1 C(10), c2 c(10), c3 c(10))
Insert into crsExport values ("aaaaaaaaaa","bbbbbbbbbb","cccccccccc")
Insert into crsExport values ("dddddddddd","eeeeeeeeee","ffffffffff")
COPY TO demo.sdf TYPE SDF
Modify File demo.sdf
You can also give it the file extension txt, VFP is not needing the file extension but the TYPE SDF option is outputting the way you need. Ther are still a lot of details to fiddle with, when it comes to fields of other types like numbers, dates, etc., but you get the gist, all it needs is mainly a COPY TO... TYPE SDF.
 
As for the "header" part in your file, you could code like this after you created the CSV file:

Code:
cHeader = "CBLLP10.03" + CHR(13) + "GCPLP10.03" + REPL( CHR(13),4)
StrToFile( cHeader + FileToStr("YourFile.txt"), "YourFile.txt")
 
I guess you'll need several iterations and have other detail problems than getting the first few lines added. Indeed one thing is unfortunate about COPY TO TYPE SDF, it doesn't allow to append to an existing file. You could also always use FilToStr to create the file line by line, aas that function also allows to append to an existing file, you can obviously also use FOPEN/FWRITE/FCLOSE and there's Textmerge to a file available. It's always possible to create any file you want and that doesn't only apply to ASCII/ANSI, none of the file output functions limit you to printable characters.

I guess you asked for the simplest command doing things as concentrated as you can, COPY TO TYPE SDF is that answer, but it may take some preparing work to get the cursor as it needs to be to create the same output, think alone of the right aligned numeric columns or any other detail. In he end it can also be simpler to work with FWRITE or FILETOSTR, that's depending on what data you have in which form already.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top