Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Append from text file delimited
Message
De
29/05/2003 07:08:03
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00793848
Message ID:
00793855
Vues:
39
This message has been marked as a message which has helped to the initial question of the thread.
>Hi All
>For data manipulation I have to import fixed width text files to VFP free table. It works ok when the each row width in the text file is less than 255 (CH). I use an empty table with single field 254 CH and then I use APPEND FROM textfile DELIMITED and then I use SUBSTR() to get the required fields to append another table. The example of prg file is as follows.
>
>LOCAL lcdesc,lcitemno,lnqty,lnprice
>IF ...
>create table junkpos.dbf(allfields c(254))
>ENDIF
>SELECT 1
>USE junkpos
>SELECT 2
>USE pos
>SELECT 1
>append from pos.txt delimited
>go top
>do while .not. eof()
>	lcdesc=SUBSTR(allfields,1,50)
>	lcitemno=SUBSTR(allfields,60,8)
>	.......
>	SELECT 2
>	APPEND BLANK
>	replace itemno WITH lcitem, itemdesc WITH lcitemdesc
>	SELECT 1
>	skip
>	loop
>ENDDO
>
>When the row width in the text file is more than 254 Ch then I can not get complete line of the text due to field width 254 CH. I want to save each text file line in a single record with more than 254 Ch.
>Is there any help?
>Regards,
>Zaheer

Zaheer,
You say "fixed width text files". If so then directly create your target cursor/table and apend from ... type SDF. That would eliminate the use of substr().
ie:
	lcdesc=SUBSTR(allfields,1,50)
	lcitemno=SUBSTR(allfields,60,8)
	.......
	SELECT 2
	APPEND BLANK
	replace itemno WITH lcitemno, itemdesc WITH lcdesc
Would become :
create cursor myCursor (itemdesc c(50), myField c(9),itemno c(8))
append from mytextfile.txt type SDF
If you'd use junkpos approach then you could get first defining more than one field. ie:
lnMaxRowWidth = 345
lnFields = ceiling(lnMaxRowWidth/254)
dimension arrFields[lnFields,4]
arrFields = 0
for ix=1 to lnFields
  arrFields[ix,1] = 'f'+ltrim(str(ix))
  arrFields[ix,2] = 'C'
  arrFields[ix,3] = iif(ix=lnFields,lnMaxRowWidth-(254*(ix-1)),254)
endfor
create cursor junkpos from array arrFields
append from myFiletxt type SDF && Delimited is dangerous - there might be commas
*...
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform