Feedback
 
Did this article resolve your question/issue?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025

 


Article

The IMPORT UNFORMATTED statement does not read the last line within a text file if there is no carriage-return at the end of the file

« Go Back

Information

 
Article Number000056072
EnvironmentProduct: OpenEdge
Version: 10.x , 11.x
OS: All supported platforms
Question/Problem Description
The IMPORT UNFORMATTED statement does not read the last line within a text file if there is no carriage-return at the end of the file.
The IMPORT UNFORMATTED statement does not read the last line within a text file if there is no line-feed at the end of the file.
Steps to Reproduce
Clarifying Information
ABL code similar to the following is showing the problem:

DEFINE VARIABLE text-string AS CHARACTER FORMAT "x(76)".

INPUT FROM "TextFileWithOneLineAndNoCarriageReturn.txt".

DO WHILE TRUE ON ENDKEY UNDO, LEAVE:
  IMPORT UNFORMATTED text-string.
  DISPLAY text-string WITH DOWN FRAME x.
  DOWN WITH FRAME x NO-LABELS.
END.

INPUT CLOSE. 
Error Message
Defect/Enhancement Number
Cause
As per the ABL Reference handbook, the UNFORMATTED option forces IMPORT to read one physical line at a time. A physical line ends with a new line carriage-return or line-feed character. If the text file doesn't end with a line-feed character the IMPORT UNFORMATTED statement will not be able to read the last line of the text file.
Resolution
Use the COPY-LOB statement to copy the full content of the text file to a LONGCHAR variable, for example:

DEFINE VARIABLE lc AS LONGCHAR   NO-UNDO.
DEFINE VARIABLE c AS CHARACTER   NO-UNDO.

COPY-LOB FILE "TextFileWithOneLineAndNoCarriageReturn.txt" TO lc.
c = lc. /* assuming lc is less than 32k */

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



If a pseudo-file / OS device is specified, other approaches may be required. As specific examples:

1. On Windows, INPUT FROM "CLIPBOARD" will also show this behavior, but the clipboard is not a valid source for COPY-LOB.
Instead, assign the clipboard value to the longchar using the CLIPBOARD system handle: lc = CLIPBOARD:VALUE.

2. If reading from a dedicated input device such as a Barcode Reader, the devices themselves can usually be configured to send a carriage return / linebreak after the last data.
Workaround
Notes
Attachment 
Last Modified Date8/4/2016 10:06 AM