Codeunit to import data

I would like to know if it is possible to use a codeunit for importing data. I first thought of using a dataport and dependant upon the value of the first field, the data would be transferred into either Table A or Table B. In testing, this worked great, but when writing this for actual use, I found that the value in a particular field may be of diffent type. i.e. CSV FILE: HEAD,abc123,abc124,12345 LINE,1234,12,2.50,large item In Navision this translates to: VAR,Sell-to Cust.,Ship-to Cust.,Your Ref. VAR,Item No.,QTY.,Unit Price,Description So what I end up with is this : (HEAD) Field 1 := VAR Field 2 := Code 20 Field 3 := Code 20 Field 4 := Text 30 (LINE) Field 1 := VAR - This is okay Field 2 := Code 20- This is okay Field 3 := Decimal Field 4 := Decimal Field 5 := Text 50 As you can see in the above example, the problems I encounter are with fields in position no.s 3 and 4. As this is apparantley quite standard, does anyone already have a solution for this ? Am I looking at this from the wrong angle ? Any suggestions greatley appreciated. Edited by - Dean Axon on 2001 Jun 21 15:38:17

Dean Use a Dataport on the integer table. Have you input fields as global variables, which are all set to type text. You can then write code to process this data convert it to what ever type you want and put it into what ever tables you feel like. Beaware because of a bug in 2.60a you can not use the integer table in dataport, this was fixed in 2.60b. Paul Baxter

I have found that there is very simple solution to my problem: EVALUATE !! This works great. Moving swiftly on… …Can anyone explain the principles of the No. series Mgt. and how I can get the next avaliable Sales Order number. Cheers Dean

Noseriesmgt = CU 396 Noseriesmgt.GetNextNo(NoSeriesCode,WORKDATE,FALSE); will return the next number in the series at workdate but will not update the series. Change the FALSE to a TRUE and the series is updated. Paul Baxter

can you share how to import file (txt or csv) using codeunit

i needed urgently


stan, there was the answer for that, 9 years ago:
Use a Dataport on the integer table. Have you input fields as global variables, which are all set to type text.

why dont try to use dataport?

that’s the problem

i must import several lines from txt, and it for 1 record

so cannot be done using dataport

Hi stan,

you can import your File using a Codeunit (or Report) with a routine like this:


BackupFilename := Filename + ‘’ +
FORMAT(TODAY,0,’<Month,2><Day,2>’) + '
FORMAT(TIME,0,’<Hours24,2><Minutes,2><Seconds,2>’) + ‘.bak’;

// Create backup TXT → BAK

FieldSep := ‘;’;
LF := 10;
CR := 13;

EOF := ReadRecord; // Read into array




The Function ReadRecord looks like this:

Fieldno := 1;
CLEAR(Field); // Delete Array

CharsRead := f.READ(Character); // Read 1 char

IF CharsRead = 0 THEN
EXIT(TRUE); // EOF reached

IF Character = FieldSep THEN BEGIN
Fieldno := Fieldno + 1; // Next field
IF NOT (Character IN [CR,LF]) THEN
Field[Fieldno] := Field[Fieldno] + FORMAT(Character);

UNTIL Character = LF; // End of rec

You can handle the different line types in the Function Process Line.

The Variables:

Field: Text Array
CR,LF,FieldSep: Char
EOF Boolean
f File

but i don’t use separator or delimeter like that

i’m using start pos and length

i already done with this, but i cannot take from BIGTEXT type to TEXT type

Pos1 := STRPOS(vstring,‘SHR’); → BIGTEXT cannot use strpos??