I am creating a Line Sequential File, for the State of Illinois, and they are saying my file contains "an extra line". My program opens the file as output, writes the records, and then closes the file.
When I look at the file, it looks to me as if the program is adding an extra carriage return at the end of the file. How do I get rid of that, OR not write it at all?
Anyone have any suggestions?
If you are running on Windows, the old DOS convention for line sequential files is used by RM/COBOL to conform to Windows conventions. Lines are terminated with a carriage return and line feed pair. On UNIX, lines are terminated with just a line feed and RM/COBOL for UNIX uses this convention. I don't know of any way to change this behavior in RM/COBOL other than to change your OS. It's possible you are sending a Windows format text file to the State of Illinois and that they require a UNIX format file. Frequently the conversion can be handled by FTP (file transfer program, a common way to send a file between Windows and UNIX systems), which on a Windows to UNIX transfer will translate CR/LF into LF. FTP has two modes for the transfer: (1) ASCII, which does translation of line termination and (2) BINARY which does not change line termination characters because in a binary file, CR/LF or LF might not represent line termination. There are also freely available programs, such as d2u (DOS to UNIX), which will convert CR/LF line terminations to LF line terminations on Windows and u2d (UNIX to DOS), which will convert LF line terminations to CR/LF line terminations on UNIX.
Of course, this assumes that the State of Illinois wants a line termination on the last record. They might expect that the last record to be terminated by the end of file and thus they consider line termination on the last line to be "an extra line". In that case, you might need a program to truncate the last two characters off the file. There's no help in RM/COBOL for this odd desired behavior.
I am creating a Line Sequential File, for the State of Illinois, and they are saying my file contains "an extra line". My program opens the file as output, writes the records, and then closes the file.
When I look at the file, it looks to me as if the program is adding an extra carriage return at the end of the file. How do I get rid of that, OR not write it at all?
Anyone have any suggestions?
That is what I thought. Thanks!
I am creating a Line Sequential File, for the State of Illinois, and they are saying my file contains "an extra line". My program opens the file as output, writes the records, and then closes the file.
When I look at the file, it looks to me as if the program is adding an extra carriage return at the end of the file. How do I get rid of that, OR not write it at all?
Anyone have any suggestions?
Amy,
You could write a rather simple VBScript that can use regular expression(s) to change some or all of the control characters in your file.
Without knowing what the exact complaint they have (other than the apparent intolerance of the control characters at the very end of the file it is hard to tell you what specific solution to use.
If it is just the last control characters, then use a VBScript to read in the entire file (ReadAll method of the FileSystem Object) and then use the Write method to write all but the last two characters to another file.
It would be instructive if the State of Illinois would provide you specifications for the file, so that we can see what the final outcome needs to be.
I am creating a Line Sequential File, for the State of Illinois, and they are saying my file contains "an extra line". My program opens the file as output, writes the records, and then closes the file.
When I look at the file, it looks to me as if the program is adding an extra carriage return at the end of the file. How do I get rid of that, OR not write it at all?
Anyone have any suggestions?
That is a good idea, but I do not know how to write VBScripts.
I am creating a Line Sequential File, for the State of Illinois, and they are saying my file contains "an extra line". My program opens the file as output, writes the records, and then closes the file.
When I look at the file, it looks to me as if the program is adding an extra carriage return at the end of the file. How do I get rid of that, OR not write it at all?
Anyone have any suggestions?
Hi Amy,
I have attached a VBScript (using file extension TXT since this board does not allow attachments will extension VBS). I chopped this out of an existing script I had available.
To use, rename the script to striplastcr.vbs. Then invoke using CALL SYSTEM along the lines of:
CALL SYSTEM 'cscript striplastcr.vbs "filename" '
where:
filename is the absolute and unambiguous pathname to the file you want 'stripped' (See C$GetLastFileName in the RM/COBOL User Guide for instructions on obtaining the complete pathname for a file.) It is enclosed in quotes to allow for embedded spaces.
You may test this script quite simply by using a Windows command line window.
Tom Morrison
Hill Country Software
I am creating a Line Sequential File, for the State of Illinois, and they are saying my file contains "an extra line". My program opens the file as output, writes the records, and then closes the file.
When I look at the file, it looks to me as if the program is adding an extra carriage return at the end of the file. How do I get rid of that, OR not write it at all?
Anyone have any suggestions?
If you'd rather do this entirely in COBOL, why not just define the file as Binary Sequential, and add your own CR, LF, or CRLF characters at the end of the records (lines) that require them, and omit them for the last record.
I often define these characters in Working-Storage:
77 CR PIC X(01) Value X'0D'.
77 LF PIC X(01) Value X'0A'.
77 CRLF PIC X(02) Value X'0D0A'.
Then add them as needed to each record (after it's populated with the rest of the contents) using reference modification:
(assuming an 80-byte record size)
Move CR to My-Record(80:1)
or
Move LF to My-Record(80:1)
or
Move CRLF to My-Record(79:2)