Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loading data from text files.....???
Message
From
23/06/1999 07:08:07
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00232388
Message ID:
00232869
Views:
17
>Hi all,
>
>In one of my applications, we need to import a fixed width flat text file with lines that are longer than the 254 characters. The import wizard will allow me to import the data into each field, but I can't seem to duplicate this using the append command for data in the file that occurs after position 254.
>
>

Here is my approach:

lcFileName=x1+ALLTRIM(fname)
WAIT WINDOW lcFileName NOWAIT
* get file content
lcFileContent=FILETOSTR(lcFileName)
*remove garbage at start and end
x4=AT( lcFirstRecord ,lcFileContent )+2

lcFileContent=SUBSTR(lcFileContent,x4)

x4=AT( lcLastRecord ,lcFileContent )+2
x5=AT( lcLineFeed ,SUBSTR(lcFileContent,x4) )+2
lcFileContent=SUBSTR(lcFileContent,1,x4+x5)

*reconnect cut lines and save to file
REPLACE txt WITH STRTRAN(m.lcFileContent,lcContinuationCharacter ," "),OK WITH .T.

IF AT(lcLastRecord ,txt)=0
MESSAGEBOX("file "+lcFileName+" is corrupted")
REPLACE OK WITH .F.
ENDIF
IF OK && both header and trailer records are here, go on
DO translateBAI WITH lcFileName,txt
ENDIF


*****************************************
FUNCTION translateBAI(lcFileName,txt)
*****************************************
LOCAL I, I1, NumBaiRecords, NumFieldsInRecord


IF NOT SEEK(lcFileName,'dbai01','filename')
* this file was not yet imported

* convert text {txt} into array {la1}
NumBaiRecords=ALINES(la1,txt) && number of records in BAI file
FOR I=1 TO NumBaiRecords
LOCAL ARRAY ThisRecordArray[1]
ThisRecord=STRTRAN( la1[ I ], "/" , "" ) && eliminate / character
ThisRecord=STRTRAN( ThisRecord, "," , lcLineFeed ) && change field delimiter to carriage return
NumFieldsInRecord=ALINES( ThisRecordArray,ThisRecord) && convert to array
DO CASE
CASE ThisRecordArray[1]="01"
if alen(ThisRecordArray)<9
dimension ThisRecordArray[9]
for I1=9 to 1 step -1
if type( 'ThisRecordArray[I1]' )='L'
ThisRecordArray[I1]=" "
endif
endfor
endif
ltDate=CovertDateTime(ThisRecordArray[4],ThisRecordArray[5])
INSERT INTO dBAI01 (;
filename,;
senderid,;
receiverid,;
DATE,;
fin,;
versionno) ;
VALUES (;
lcFileName,;
ThisRecordArray[2],;
ThisRecordArray[3],;
ltDate,;
ThisRecordArray[6],;
iif(NumFieldsInRecord=>9,ThisRecordArray[9],'') )

CASE ThisRecordArray[1]="02"

if alen(ThisRecordArray)<8
dimension ThisRecordArray[8]
for I1=8 to 1 step -1
if type('ThisRecordArray[I1]')='L'
ThisRecordArray[I1]=" "
endif
endfor
endif
ltDate=CovertDateTime(ThisRecordArray[5],ThisRecordArray[6])
INSERT INTO dBAI02 (;
bai01_id,;
URI,;
originator,;
status,;
asofdate,;
currency) ;
VALUES (;
dbai01.bai01_id,;
ThisRecordArray[2],;
ThisRecordArray[3],;
val( ThisRecordArray[4] ),;
ltDate,;
ThisRecordArray[7] )

CASE ThisRecordArray[1]="03"
*ltDate=CovertDateTime(ThisRecordArray[5],ThisRecordArray[6])
INSERT INTO dBAI03 (;
bai02_id,;
account,;
currency,;
Fundtail ) ;
VALUES (;
dbai02.bai02_id,;
ThisRecordArray[2],;
ThisRecordArray[3],;
la1[i] )

CASE ThisRecordArray[1]="16"
if alen(ThisRecordArray)<8
dimension ThisRecordArray[8]
for I1=8 to 1 step -1
if type('ThisRecordArray[I1]')='L'
ThisRecordArray[I1]=" "
endif
endfor

endif
INSERT INTO dBAI16 (;
bai03_id,;
code,;
FundType,;
BankRef,;
Custref,;
Note,;
amount,;
tail ) ;
VALUES (;
dBAI03.bai03_id,;
ThisRecordArray[2],;
ThisRecordArray[4],;
ThisRecordArray[5],;
ThisRecordArray[6],;
ThisRecordArray[7],;
val(ThisRecordArray[3] )/100 ,;
la1[i] )

ENDCASE


ENDFOR

ENDIF


RETURN
Peter Cortiel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform