Read a text file

Hi all I plan to use the following code to read a text file into a table(the fileds of files are seperated bx tilt character (~). Can anybody suggest a better way than this or some changes in my code. variables fileReadto File txtRecord Text 250 txtfieldsArray Text 100 intColno Integer intPrevious Integer intLenchar Integer intFilelen Integer fileReadto.OPEN(‘Myfile.txt’); fileReadto.TEXTMODE(TRUE); WHILE fileReadto.READ(txtRecord) > 1 DO BEGIN intColno := 1; intPrevious := 1; intLenchar := -1 ; FOR i := 1 TO (STRLEN(txtRecord)) DO BEGIN intLenchar +=1; IF COPYSTR(txtRecord,i,1) = ‘~’ THEN BEGIN txtfieldsArray[intColno] := COPYSTR (txtRecord,intPrevious,intLenchar); intPrevious := i+1; intColno += 1; intLenchar := -1; END; //code for writting array values into //the text file //code for clearing array values END; Regards Joseph Mathew

Why not using a dataport?? that’s what they are supposed to do: reading data from text files and putting it into tables … :slight_smile: – Alfonso Pertierra apertierra@teleline.es Spain

Hi The resons for not using the dataport are follows. 1. Since the files are from the different customers, I want to check the validity of file (All the informations in the files are ok for import) 2. It has to be decodes some values. 3. Import the values into more than one table including some calculated values. 4. Create a log files about this imports As of my opinion it is better to use a code unit for this than using a dataport. Regards Joseph Mathew

quote:


Originally posted by Joseph_Mathew: 1. Since the files are from the different customers, I want to check the validity of file (All the informations in the files are ok for import) 2. It has to be decodes some values. 3. Import the values into more than one table including some calculated values. 4. Create a log files about this imports As of my opinion it is better to use a code unit for this than using a dataport.


You can do almost the same with a dataport than with a codeunit. The difference basically is that when using a dataport you’ve a faster parsing tool than when using a Codeunit,where you’ve to define all the searching routine for the values (importing from different files it’s not a real problem, also decoding values when importing or importing into more than one table, as you can always use autosave = false and use your code for entering the values you obtain from variables that you define for catching the info from the file). – Alfonso Pertierra apertierra@teleline.es Spain

quote:


Originally posted by apertierra: You can do almost the same with a dataport than with a codeunit. The difference basically is that when using a dataport you’ve a faster parsing tool than when using a Codeunit,where you’ve to define all the searching routine for the values (importing from different files it’s not a real problem, also decoding values when importing or importing into more than one table, as you can always use autosave = false and use your code for entering the values you obtain from variables that you define for catching the info from the file). – Alfonso Pertierra apertierra@teleline.es Spain


Actually, you (probably) should use a nonprinting report NOT a dataport and NOT a codeunit. Dataports should only be used to import beginning values during the initial installation and to transfer data from one Navision installation to another (for example, when you import payroll tax rates into the US payroll system.) ------- Tim Horrigan horrigan@aol.com

WHAT! Why would you not use Dataports for daily importing? I might have missed something, but they seem to be a pretty good fit for the task. Soren Nielsen, moderator Integration/Developer NOLUG

Hi all I will do the same functionality in dataport and let all know the results. Thanks and regards. Joseph Mathew

I dont see how you can think such a ridiculous thought Tim??? Dataports are useful for so many things once the system is running. Check out the standard dataport 5000 - definitely not a single run dataport. As for using a dataport for this issue - its the only thing I would use and as I have said before in other postings using code behind dataports gives you all the functionality that Joseph wanted. Craig Bradney Technical Manager Navision Solutions & Services, Deloitte Touche Tohmatsu Email:cbradney@deloitte.com.au