Friday, April 26, 2019

NAV CAL - Read File using BigText Instream. Separate single line into multiple lines on delimiter

FileMgt.GetServerDirectoryFilesList(Filelist,EDITemp."Input File Location");
//Importfile
IF Filelist.FIND('-') THEN BEGIN
  REPEAT
    LC := 0;
    Path := Filelist.Name;
    InputFile.WRITEMODE(FALSE);
    InputFile.TEXTMODE(TRUE);
    InputFile.OPEN(Path);
    intLen := InputFile.LEN;
    WHILE InputFile.POS < intLen DO BEGIN
    InputFile.CREATEINSTREAM(FileInStream); 
      WHILE NOT FileInStream.EOS DO BEGIN 
        Buffer.READ(FileInStream); 
      END;
      Lineend := 1;
      Buffer2 := Buffer;
      WHILE Buffer2.TEXTPOS(EDITemp."Segment Terminator") > 0 DO BEGIN
        Buffer.GETSUBTEXT(Buffer2,Lineend,Buffer.LENGTH);
        Lineend := Buffer2.TEXTPOS(EDITemp."Segment Terminator") + 1;
        LC := LC + 1000;
        VEL.INIT;
        VEL.Line := LC;
        VEL.Filename := Filelist.Name;
        VEL.DateRead := CURRENTDATETIME;
        Buffer2.GETSUBTEXT(VEL.Detail,1,Lineend);
        VEL.INSERT;
        Buffer := Buffer2;
      END; 
    END;
    InputFile.CLOSE;
    COMMIT;
  UNTIL Filelist.NEXT <= 0
END;

Name DataType Subtype Length
FileMgt Codeunit File Management
EDIFile Record Vendor EDI Files
EDITemp Record Vendor EDI Template
Filelist Record Name/Value Buffer

Name DataType Subtype Length
ServerFile Integer
Path Text 250
InputFile File
VEL Record Vendor EDI Lines
intLen Integer
LC Integer
FileInStream InStream
Buffer BigText
Lineend Integer
Buffer2 BigText

No comments:

Post a Comment