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
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.
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]
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.
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
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... :(
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.
Even with your code, I am able to read the two lines correctly and the first line does not repeat twice.
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
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.
Perfect. This makes sense.
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.
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.