DATAPORT : how to return to the first line or read again the file ?

I would need to read the whole CSV file (to check each line) then go back to the first line to process the data.
Is it possible ? How can I do so ?

Answers

  • ftorneroftornero Member Posts: 524
    Hello @navision2009R2,

    You can create a report that call your dataport twice, passing a parameter with the value of 1 the first time and 2 the second, so you can do whatever you need depending on this value.

    Be sure to set the UseReqForm property to No in the dataport.

    sqpaycg9h377.png

    The report could be as simple as this one

    gw99hcel0wn4.png

    Where the function CallID is the function in your dataport to get the call value.

    Like this:

    r340pgi917rz.png

    Where globalID is a global integer variable.

    Regards
  • Big_DBig_D Member Posts: 207
    Hi @navision2009R2,

    Great name by the way :) !

    Sure want to read twice?

    A trick I use to read the header lines on a dataport but you could use to read all the dataport lines...

    OnPreDataItem=VAR
    DosInFile@100000006 : File;
    StreamIn@100000005 : InStream;
    OffSetLength@100000004 : Integer;
    NextStep@100000003 : Integer;
    ReadStep@100000002 : Integer;
    LineFeed@100000001 : Integer;
    ReadLine@100000000 : Text[1024];
    BEGIN
    IF CurrDataport.IMPORT THEN BEGIN
    DosInFile.OPEN (FileName);
    DosInFile.CREATEINSTREAM (StreamIn);
    LineFeed := 0;
    REPEAT
    OffSetLength := StreamIn.READTEXT (ReadLine, 1024);
    LineFeed += 1;
    UNTIL OffSetLength <> 0;
    IF LineFeed > 1 THEN
    OffSetLength := OffSetLength + 2;
    REPEAT
    NextStep := StreamIn.READTEXT (ReadLine, 1024);
    OffSetLength := OffSetLength + NextStep + 4;
    UNTIL NextStep <> 0;
    DosInFile.CLOSE;
    CurrFile.SEEK (OffSetLength);
    END;

    But I would say a better solution is to read all the records and place in a temporary record and on

    Dataport - OnPostDataport()

    Read back the temporary records and process the data from there.

    Hope this helps!
    Big D signing off!
Sign In or Register to comment.