How to import a ASC supported file using Proc only Report

pedwardpedward Member Posts: 11
Hi Experts,

Need your help???

Have to create Processing only report, that will import ASC supported files. After the import stuff is done i have to parse the whole data and put it in a BLOB field.


So how do i get started; Any tips, Any trick any code sample?

Thanks
P.Edward

Comments

  • pedwardpedward Member Posts: 11
    Special request to all MVP's and experts tht plz help me get through with it.

    Thanis
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Is ASC file a 3D studio max file? Or an ascii file?

    If you're importing an ascii file, why do you need to put it into a BLOB field? And what's the purpose of storing data in the BLOB field? Do you need to spit it out afterwards?

    Anywho, I would recommend doing the following:
    1. Create a new table to store the ascii data you imported.
    2. Do your processing based on the imported data on this new table
  • pedwardpedward Member Posts: 11
    Thanks Alex for your reply atleast someone replied :)

    What i have to do is to import either a MS word file/wordpad file/notepad file through the report.

    Then i have to parse that file and store the data as text in blob field.
    I already have that blob field in one of my tables. I know how to retrieve the data from BLOB field.

    But i want to know that how do i import those files through report and thn the parsing mechanism?

    Waiting for your feedback
    Thanks

    P.Edward
  • todrotodro Member Posts: 117
    pedward wrote:
    Thanks Alex for your reply atleast someone replied :)

    What i have to do is to import either a MS word file/wordpad file/notepad file through the report.

    Then i have to parse that file and store the data as text in blob field.
    I already have that blob field in one of my tables. I know how to retrieve the data from BLOB field.

    But i want to know that how do i import those files through report and thn the parsing mechanism?

    Waiting for your feedback
    Thanks

    P.Edward
    are the word files stored in a.) RTF b.) XML or c.) binary (RIFF) format ?

    Depending on that, you will have to use different import strategies:

    a.) RTF files can be large, especially if binary embedded objects like images are included. Dealing with this type of document seems to be more complex

    b.) XML can be imported by using the MSXML automation server

    c.) binary files will require to iterate byte-by-byte through the import stream

    In case of "normal" text files as saved by notepad or wordpad, you have to either know that they are plain ASCII, or in case they are somehow encoded, e.g. UTF-8, then during the import you also have to consider the encoding


    The simple import can be handled like this:
    ImpFile.TEXTMODE := TRUE;
    IF NOT ImpFile.OPEN('c:\test.txt') THEN
      ERROR('File not found...!');
    ImpFile.CREATEINSTREAM(IStream);
    WHILE NOT (IStream.EOS()) DO BEGIN
        IStream.READ(InpBuffer,1);
        ImportText := ImportText + format(inpbuffer);
    END;
    
    MESSAGE(ImportText);
    

    Or you could use READTEXT in case you have CRLF separated text lines.

    What you have to consider:

    a.) for the parsing, you might need to use a buffer (the length depends on what you have parse) unless you can do it on the fly

    b.) max. length for the text variable is 1024, maybe you need several variables for the parse buffer

    c.) if the parts of the document mostly exceed a length of 1024, then you could also use a temporary stream and after filling it, you could use COPYSTREAM

    In general, without knowing the content of the files or without providing examples, it's hard to propose an appropriate solution
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • pedwardpedward Member Posts: 11
    Thanks Todro for your detailed and comprehensive reply. I really appreciate that.

    The files that i will import would be simple text (plain ASCII).

    This is how my file would be

    Date Subject Description
    082807 Testing1 This text can go upto 10000+ characters
    082807 Testing2 This text can go upto 10000+ characters

    Now i have to parse that file, each new entry would be a new record. I have tried to use DataPort but i cant since the Description might go over 1024 characters.

    Now in my table the Description is a BLOB field. What i have to do is to read the entire description of each record parse it and put it back in the BLOB field. I know how to put the data in BLOB field.

    But i have never done the file import stuff before. So i am having trouble in importing the file and parsing it.

    Another thing, i would be selecting a file dont have to put in the path.

    Could you please do my a favour provide some code snippet so that i may start my hit and try.

    Sorry for asking those basic things but honestly speaking i m doing that stuff for the first time; i really need your support.

    Thanks a lot, waiting for your feedback.

    Regards,
    P.Edwards
  • todrotodro Member Posts: 117
    pedward wrote:
    Thanks Todro for your detailed and comprehensive reply. I really appreciate that.

    The files that i will import would be simple text (plain ASCII).

    This is how my file would be

    Date Subject Description
    082807 Testing1 This text can go upto 10000+ characters
    082807 Testing2 This text can go upto 10000+ characters

    Now i have to parse that file, each new entry would be a new record. I have tried to use DataPort but i cant since the Description might go over 1024 characters.

    Now in my table the Description is a BLOB field. What i have to do is to read the entire description of each record parse it and put it back in the BLOB field. I know how to put the data in BLOB field.

    But i have never done the file import stuff before. So i am having trouble in importing the file and parsing it.

    Another thing, i would be selecting a file dont have to put in the path.

    Could you please do my a favour provide some code snippet so that i may start my hit and try.

    Sorry for asking those basic things but honestly speaking i m doing that stuff for the first time; i really need your support.

    Thanks a lot, waiting for your feedback.

    Regards,
    P.Edwards

    Here a q&d version:
    ImpFile.TEXTMODE := FALSE;
    IF NOT ImpFile.OPEN('c:\test.txt') THEN
      ERROR('File not found...!');
    ImpFile.CREATEINSTREAM(IStream);
    Filelen := ImpFile.LEN;
    Filepos := ImpFile.POS;
    
    WHILE  Filepos < Filelen DO BEGIN
    //Read Header
      IStream.READTEXT(Txt,6);
      OK := EVALUATE(Day,COPYSTR(Txt,3,2));
      OK := EVALUATE(Month,COPYSTR(Txt,1,2));
      OK := EVALUATE(Year,COPYSTR(Txt,5,2));
      IF Year IN [0..30] THEN
        Year := Year + 2000
      ELSE
        Year := Year + 1900;
      RecDate := DMY2DATE(Day,Month,Year);
    
    //Read subject
      Subject := '';
      DescFinished := FALSE;
      Filepos := ImpFile.POS;
      WHILE (Filepos < Filelen) AND (DescFinished = FALSE) DO BEGIN
        IStream.READ(InpB);
        Filepos := ImpFile.POS;
        Ch := InpB[1];                      // <== necessary because of type conversion
        Txt := FORMAT(Ch);                  // <==
        IF Txt[1] = 13 THEN BEGIN
          IStream.READ(InpB);
          Ch := InpB[1];
          Txt := FORMAT(Ch);
          IF Txt[1] = 10 THEN BEGIN
            DescFinished := TRUE;
            // Error, CRLF within subject   // Syntax error
          END ELSE BEGIN
            Subject := Subject + FORMAT(Txt[1]);
          END;
        END ELSE BEGIN
          Subject := Subject + FORMAT(Txt[1]);
        END;
      END;
    
    //Read description
      DescFinished := FALSE;
      Filepos := ImpFile.POS;
      WHILE (Filepos < Filelen) AND (DescFinished = FALSE) DO BEGIN
        IStream.READ(InpB);
        Filepos := ImpFile.POS;
        Ch := InpB[1];
        Txt := FORMAT(Ch);
        IF Txt[1] = 13 THEN BEGIN
          IStream.READ(InpB);
          Ch := InpB[1];
          Txt := FORMAT(Ch);
          IF Txt[1] = 10 THEN BEGIN
            DescFinished := TRUE;
          END ELSE BEGIN
            // Save byte to blob here
            // e.g. OStream.write(Txt[1]);
          END;
        END ELSE BEGIN
           // Save byte to blob here
           // e.g. OStream.write(Txt[1]);
        END;
      END;
    
      IF (Filelen - Filepos) < 6 THEN
        EXIT;
    END;
    
    
    Name	DataType	Subtype	Length
    ImpFile	                 File		
    IStream	                InStream		
    Txt	                   Text		1024
    OK	                   Boolean		
    Day	                  Integer		
    Month	                 Integer		
    Year	                  Integer		
    RecDate	               Date		
    DescFinished	      Boolean		
    InpB	                  Binary		1
    Filelen	                  Integer		
    Filepos	                 Integer		
    Ch	                  Char		
    Subject	                Text		1024
    
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
Sign In or Register to comment.