Importing csv file

JackYJackY Member Posts: 3
edited 2008-07-01 in Navision Financials
I have a csv file I am importing data to update customer records using a codeunit.
I have successfully completed this task in the past but these records contain several boolean fields.

It seems that when I import the first record and attempt to assign the first field of data using SELECTSTR(1, TrainingInfoLine) it gives me the following message 'STRSET' cannot contain 'TRUE' more than once.

I wouldn't think this would normally cause a problem.

Any suggestions would be helpful. :?

I am running Financial 26e on a sql server 2000

Comments

  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    The following code will show how to create your own selectstr function. This is neccessary beacuse selectstr cannot handle situations whre 2 substrings are equal.
    GetFieldContent(parFieldNo : Integer;parTxt : Text[1024]) : Text[1024]
    ReturnString := '';
    FieldsFound := 1;
    boo := -1;
    REPEAT
      CounterPOS += 1;
      IF parTxt[CounterPOS] = '"' THEN
        boo *= -1
      ELSE BEGIN
        IF (parTxt[CounterPOS] = ',') AND (boo = -1) THEN
          FieldsFound += 1
        ELSE
          IF FieldsFound = parFieldNo THEN
            ReturnString := ReturnString + COPYSTR(parTxt,CounterPOS,1);
      END;
    UNTIL (CounterPOS = STRLEN(parTxt)) OR (FieldsFound > parFieldNo);
    
    EXIT(ReturnString);
    

    This works for me
  • afarrafarr Member Posts: 287
    Thanks a lot. I only realised this limitation of SELECTSTR now, and your code saves me an hour or two of messing around.

    Alastair
    Alastair Farrugia
  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    I'm just so glad to be of any assistance.

    And by the way: Your post shows that it is a good idea to search the forum before posting new questions...
  • magnifiquemagnifique Member Posts: 43
    i have trying to apply the code that was given by PrebenRasmussen.

    am trying to instream a csv file that has 7 comma separated subtrings eg.
    ABL,1480,1480,1480,2501,07/11/05,5456.79

    this is how the code in the codeunit looks like:
    OnRun()

    Data.OPEN('C:\Rates.txt');
    Data.CREATEINSTREAM(InS);
    code := 1;
    WHILE NOT (InS.EOS()) DO
    BEGIN
    InS.READTEXT(Txt);
    Table.INIT;
    Table."Equity Code" := GetFieldContent(1, Txt);
    Table."Closing Price" := GetFieldContent(2, Txt);
    Table."Opening Price" := GetFieldContent(3, Txt);
    Table."Current Price" := GetFieldContent(4, Txt);
    Table."Session No." := GetFieldContent(5, Txt);
    Table."Date of Price Change" := GetFieldContent(6, Txt);
    Table."GSE Index" := GetFieldContent(7, Txt);

    Table.INSERT;
    code := code + 1;
    END;
    Data.CLOSE();
    MESSAGE('Records have been written');
    and the
    GetFieldContent(parFieldNo : Integer;parTxt : Text[1024]) : Text[1024]

    ReturnString := '';
    FieldsFound := 1;
    int := -1;
    REPEAT
    CounterPOS += 1;
    IF parTxt[CounterPOS] = '"' THEN
    int *= -1
    ELSE BEGIN
    IF (parTxt[CounterPOS] = ',') AND (int = -1) THEN
    FieldsFound += 1
    ELSE
    IF FieldsFound = parFieldNo THEN
    ReturnString := ReturnString + COPYSTR(parTxt,CounterPOS,1);
    END;
    UNTIL (CounterPOS = STRLEN(parTxt)) OR (FieldsFound > parFieldNo);

    EXIT(ReturnString);


    please help out i need cos i need it badly.thank u ](*,)
  • AlbertvhAlbertvh Member Posts: 516
    Hi magnifique

    You could try this

    Table."Equity Code" := COPYSTR(Txt,1,strpos(Txt,',') - 1);
    Txt := COPYSTR(Txt,strpos(Txt,',') + 1);
    Table."Closing Price" := COPYSTR(Txt,1,strpos(Txt,',') - 1);
    Txt := COPYSTR(Txt,strpos(Txt,',') + 1);

    etc for all the fields that are used.
    Hope this helps
    Albert
  • magnifiquemagnifique Member Posts: 43
    thanx am about to try it and would give you a feedback the very moment am done.
  • FrankieFrankie Member Posts: 8
    I use this code
       lastpos := STRPOS(text,',');
       temp := COPYSTR(text,1,lastpos-1);
       EVALUATE(Testart.eins,temp); 
       text := DELSTR(text,1,lastpos);
    

    you can use this for every element in the CSV-file
  • magnifiquemagnifique Member Posts: 43
    :D
    guys Albertvh code worked for me thanks so much .Frankie i will try yours later to see how it goes.Thanks everyone u saved the day.i guess navision with tyme will become as easy as ABC . this an appluase for all the help =D>
  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    You are MOST welcome...
Sign In or Register to comment.