ASCII files are written with the last line of the file blank, there is an empty line after the last record.
There is a company that receives these files and does not accept this last blank line, the file must have the last line with data.
I am unable to save the file without this blank line.
Are you manually appending a CR/LF to every line or are you letting the driver do it?
You could try writing the file like normal (except the last line), use /ENDOFRECORD driver string to change the terminator, then write the last line by itself.
I am not manually appending a CR/LF to each line, I am letting the driver do that.
I cannot use the driver string /ENDOFRECORD to change the terminator (/ENDOFRECORD only changes the record length, not the end of the file), all lines need to be of a fixed length in order to read the file, this company’s file reader is very limited.
Use the DOS driver.
You’ll have to code ADD(File, Length) as the DOS driver does not Clip. Then ADD(File,2) with the 13,10 as the value for all but the last line.
So you are creating an ascii file with fixed length records, terminated by a CRLF.
And, for this one company the last record shouldn’t have the CRLF terminator on the last record?
Do you have the String Theory add on template? If you do then I think you could edit the file in a few steps to remove the final record terminator?
If not, maybe the simplest approach is to set the record terminator to blank in your dct. The default terminator is CRLF ‘<13,10>’ - the help will explain how to do that, but ask here if you’re not sure how to do that.
Then, in your code for writing to the file, use …
...
Fil:Value12 = 'Some Value'
IF Company = BadCompany AND ThisIsTheLastRecord
Fil:Value13 = 'Some other value' ! Don't add a CRLF to last record
ELSE
Fil:Value13 = 'Some other value' & '<13,10>'
END
ADD(ExportFile)
the help for ENDOFRECORD says
DRIVER('ASCII', '/ENDOFRECORD = n [,m ]' )
[ EOR" = ] SEND(file, 'ENDOFRECORD [ = n [,m ]]' )
Specifies the end of record delimiter.
n represents the number of characters that make up the end-of-record delimiter.
m represents the ASCII code(s) for the end-of-record delimiter, separated by commas. The default is 2,13,10, indicating 2 characters mark the end-of-record, namely, carriage return (13) and line feed (10). SEND returns the end of record delimiter.
so do as Paul says and SEND(file, ‘ENDOFRECORD = 0’) before writing the last line.
or do as Carl says and use the DOS driver
or do as I do and forget using any driver and use StringTheory.
so you have several options!
cheers
Geoff R
OK yes that’s yet another way to do it.
if not st.loadFile('myfile.txt') then <error>.
if st.endsWith('<13,10>') then st.adjustLength(-2).
st.saveFile('myFixedFile.txt')
an alternative to
if st.endsWith('<13,10>') then st.adjustLength(-2).
would be
st.clip('<13,10>')
which would simply take CR and LF chars off the end (regardless of order or quantity).
Thank you very much CarlBarnes.
This is exactly what I needed, it worked perfectly.
And it was very simple to implement in my system.
I appreciate all the answers, which are very useful and always add knowledge to all of us.
I don’t have the String Theory add-on template.
I tested it with DRIVER(‘ASCII’, ‘/ENDOFRECORD = n [,m ]’ ), but I didn’t test it with parameter 0.
Thank you very much again.