Kbase P124970: How to add a Line Feed to the end of a text file so that the IMPORT UNFORMATTED statement can read t
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  07/12/2010 |
|
Status: Verified
GOAL:
How to add a Line Feed to the end of a text file so that the IMPORT UNFORMATTED statement can read the last line?
GOAL:
Adding a Line Feed at the end of a text file for reading the last line of a file using IMPORT UNFORMATTED.
FACT(s) (Environment):
Progress/OpenEdge Product Family
All Supported Operating Systems
FIX:
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 linefeed character.
If the text file doesn't end with a Line Feed character the IMPORT UNFORMATTED will not be able to read the last line of the text and will read twice one line from the last line.
This solution describes one possible way to add a Line Feed character at the end of the text file programmatically.
DEFINE VARIABLE cLine AS CHARACTER NO-UNDO.
DEFINE VARIABLE mLine AS MEMPTR NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
ASSIGN cFile = "insert.html" .
INPUT FROM VALUE(cFile) BINARY.
SEEK INPUT TO END .
SEEK INPUT TO (SEEK(INPUT) - 1) .
SET-SIZE(mLine) = 0 .
SET-SIZE(mLine) = 1 .
IMPORT UNFORMATTED mLine .
INPUT CLOSE .
IF get-byte(mLine,1) <> 10 THEN DO:
OUTPUT TO VALUE(cFile) APPEND .
PUT UNFORMATTED "~n" .
OUTPUT CLOSE .
END.
INPUT FROM VALUE(cFile) .
REPEAT:
IMPORT UNFORMATTED cLine .
MESSAGE "Import Line: " + cLine
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
INPUT CLOSE .
SET-SIZE(mLine) = 0 .