Progress Import Statement

Posted by rrajan on 22-Jul-2013 08:29

I have a csv file with the following data. There is no end of line charater in 2 line. When I use the import statement within a Repeat, progress reads the first line twice. But if I remove the second line and run the same it creates only one record in my temp-table. Any idea on why this is happening or how to fix this will be appreciated.

ABC,,,test,testorder,42483906,line instructions,m@m.com

XYZ,notvalid,notvalid,testc,test,OS04,line instruction,a@a.com

All Replies

Posted by Dileep Dasa on 22-Jul-2013 08:55

I have tried this and the results are as expected.

Can you please attach the csv file? Also, please specify the OpenEdge version you are using.

Posted by rrajan on 22-Jul-2013 08:57

Please find attached the upload file. I am using OpenEdge Release 11.2

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/26/Upload2.csv.zip:550:0]

Posted by egarcia on 22-Jul-2013 08:58

Hello,

I have a csv file with the following data. There is no end of line charater in 2 line.

The IMPORT statement requires a newline at the of the file to recognize it.

You would need to ensure that that the last line of the file has a newline as well.

If you are using a UNIX/Linux system, you can use the following command to add a newline:

     echo '' >> b.txt

I hope this helps.

Posted by rrajan on 22-Jul-2013 09:05

Thanks for replying but my main concerns is around progress reading the first line twice. Please let me know why the first line is read twice. It doesn't happen if I remove the contents of second line

Posted by rohit.ramak on 23-Jul-2013 08:08

Can you post the code you are using to import the csv file?

I'm on Windows / 10.1C. I'm able to correctly ready the two lines of data from your csv file.

DEFINE VARIABLE cLine AS CHARACTER   NO-UNDO.


INPUT FROM C:\temp\psdn.csv.


REPEAT :   

IMPORT   cLine.   

MESSAGE cLine        VIEW-AS ALERT-BOX INFO BUTTONS OK.


END.

Message was edited by: Rohit Ramakrishna - Unable to add code tags...  :(

Posted by rrajan on 23-Jul-2013 08:43

I am using a stream and an unformatted import in my code.

DEFINE VARIABLE cLine AS CHARACTER   NO-UNDO.

DEFINE STREAM stResultList.

INPUT STREAM stResultList FROM C:\temp\psdn.csv.

REPEAT :   

    IMPORT STREAM stResultList UNFORMATTED  cLine.   

    MESSAGE cLine VIEW-AS ALERT-BOX INFO BUTTONS OK.

END.

Posted by rohit.ramak on 24-Jul-2013 00:05

Even with your code, I am able to read the two lines correctly and the first line does not repeat twice.

Posted by Dileep Dasa on 24-Jul-2013 05:13

I am able to reproduce (first line being read twice)  this with the code provided by Ramalingam.

However, removing UNFORMATTED from IMPORT statement resolved the problem

Posted by Håvard Danielsen on 24-Jul-2013 11:39

I don't think it is reading the first line twice. The variable probably has the  result from the previous read because the read of the last line is not  done.

Try to set cLine blank before the import.

Posted by rrajan on 24-Jul-2013 12:26

Perfect. This makes sense.

Posted by rrajan on 24-Jul-2013 12:28

Yes I also noticed this . But the reason it seems is the variable is not reset but interesting thing is removing the unformatted it is reading both lines.

Posted by egarcia on 24-Jul-2013 12:52

Hello,

Notice that in order to read the last line of the file, you would still need the line to end on a newline.

A note in the documentation for the IMPORT statement says the following:

The UNFORMATTED option forces IMPORT to read one physical line at a time. A physical line ends with a newline or linefeed character.

If you set cLine to blank before the import, the value would be blank but the last line would not be read.

I hope this helps.

This thread is closed