Dataport import and output error in a txt file

peterropeterro Member Posts: 9
Dear all,

I am using dataport to import data into Navsion table Location from a text file .
My text file contain some errors ( text lenght exceed or illegal caracter etc ).
Does anyone know is there any way to validate the data during import? How can import data and skip the errors and write error to a text file.
Your comment is highly appriciated.

Regards,

Comments

  • krikikriki Member, Moderator Posts: 9,118
    Instead of using the field in the dataport, use a global variable.
    This you can test in the "OnAfterImportRecord()"-trigger.
    If it is not ok, you can skip the record (=CurrDataport.SKIP;).
    For writing to a file, you have to open it in the "OnPreDataItem()"-trigger and close it in the "OnPostDataItem()"-trigger.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • peterropeterro Member Posts: 9
    kriki wrote:
    Instead of using the field in the dataport, use a global variable.
    This you can test in the "OnAfterImportRecord()"-trigger.
    If it is not ok, you can skip the record (=CurrDataport.SKIP;).
    For writing to a file, you have to open it in the "OnPreDataItem()"-trigger and close it in the "OnPostDataItem()"-trigger.

    I'm beginner .... if you post some example code ?
    I'm disperate .... pls help me
    thanks
  • krikikriki Member, Moderator Posts: 9,118
    OnPreDataItem()
    intRecord := 1;
    filFile.WRITEMODE(TRUE);
    filFile.TEXTMODE(TRUE);
    filFile.QUERYREPLACE(TRUE);
    filFile.CREATE("The File Name");
    

    OnAfterImportRecord()
    intRecord += 1;
    IF STRLEN(txtImportedText) > MAXSTRLEN("Some Field In The Table" THEN
      filFile.WRITE('The text for "txtImportedText" is too big for record' + FORMAT(intRecord));
    // this IF STRLEN ... MAXSTRLEN.... you have to write for each field in the dataport that can be too long
    // txtImportedText is a text or a code with a length that is long enough to contain all chars
    

    OnPostDataItem()
    filFile.CLOSE;
    

    I didn't test the code, but this is less-or-more what you will need.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • peterropeterro Member Posts: 9
    Any solution guys ?
    here is my example of my import :import.txt
    I have one table with 2 fields : code and location
    <|333156|>^<|DEPOZIT BULK|> ./ldjwzz/....
    <|333953|>^<|K-MAG PLOIESTI 1|>
    <|333954|>^<|K-MAG TARGOVISTE 1|>
    <|334033|>^<|K-MAG GIURGIU 1|>}}[e
    <|334148|>^<|MARFA NEEXPEDIATA|>
    <|334149|>^<|MARFA NERECEPTIONATA|>
    <|334204|>^<|K-MAG GALATI 1|>
    <|334205|>^<|K-MAG GALATI 2|>----87362,,mdjd

    how to set up a dataport to skip this records and output error filed to a text file ?
  • peterropeterro Member Posts: 9
    I came up with this code, but I only chech the first line of the imput text file. How can I go to the next line ?
      fisier.TEXTMODE(TRUE);
      fisier.CREATE('C:\Erori.TXT');
    
         
      intrare.TEXTMODE(TRUE);
      intrare.OPEN('c:\mmm.txt');
    
      intrare.READ(rand);
      start := 1;
      pozitia := STRPOS(rand, '^');
    //  fisier.WRITE(pozitia);
    
      WHILE (( (pozitia > 0) AND (pozitia < STRLEN(rand)-4) ) AND (intrare.POS<STRLEN(rand)-4) ) DO
      BEGIN
        sirul := COPYSTR(rand, start, pozitia-1);
    //  fisier.WRITE(sirul);
        IF ( (STRPOS(sirul, '<|') <> 1) OR (STRPOS(sirul, '|>') <> STRLEN(sirul)-2) ) THEN BEGIN
                                                                                           fisier.WRITE(rand);
                                                                                           CurrDataport.SKIP;
                                                                                           END;
        pos := pozitia;
        start := pozitia + 1;
        sirul := COPYSTR(rand, start, STRLEN(rand));
        pozitia := STRPOS(sirul, '^') + pos;
      END;
      sirul := COPYSTR(rand, pozitia + 1, STRLEN(rand));
      IF sirul <> '' THEN BEGIN
                          fisier.WRITE(rand);
                          CurrDataport.SKIP;
                          END;
    
  • krikikriki Member, Moderator Posts: 9,118
    Lets do this step-by-step.
    First make a dataport with 1 field (a text (=txtTheInputText) of 1024) [at least if your textfile doesn't contain lines longer than 1024 characters].
    This will read the file line by line.
    You can check it if you put a MESSAGE('%1',txtTheInputText); in the OnAfterImportRecord()-trigger.
    So you don't need to do a read from a file. This is handled by the dataport. Look at the standard-import dataports. In general there is no code for importing. The DataItem you can use, is the "Integer"-table with properties "AutoSave","AutoUpdate","AutoReplace" = No.

    Once this works fine, you can start putting your code to test the input and to write errors to the textfile:
    In the OnPreDataItem()-trigger you open the textfile for writing.
    In the OnAfterImportRecord()-trigger you text the textline and write errors to the textfile.
    In the OnPostDataItem()-trigger you close your textfile.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.