-
Notifications
You must be signed in to change notification settings - Fork 28
Ensuring Fixed Length Records for Cobol Source Files (Unix and Linux)
Home -> User Guide -> Unix and Linux User Guide ->
Developer Guide -> Unix and Linux Platform Guide ->
Cobol source on the mainframe resides in sequential datasets with fixed-length, 80-byte records. In contrast, Cobol source files on *nix systems reside in text files, which are treated as char streams. Newline characters embedded in the file's contents are treated as logical end-of-line markers when text files are processed line-by-line, as with a Java BufferedReader object.
The *nix equivalent of a fixed-length sequential dataset is a fixed-width text file. This is not a supported *nix file type. Files that are meant to be treated as fixed-width have to be handled specially by programmers and users.
When you create/edit files on a *nix system or download files from a mainframe system, the data are stored in the *nix way, with a newline following the last non-blank character in each logical record. A mainframer would think of this as similar to a variable-length dataset, although it is not implemented in the same way.
On the mainframe itself, the fixed-length logical records contained in sequential datasets do not have newline characters. They contain just the 80 bytes of data. Any Cobol source file intended to be uploaded to a mainframe system must contain 80-character "lines" with a newline appended, giving a logical record length of 81.
One way to pad the records in a file to 80 characters plus a newline is to use awk as follows:
awk -F, '{printf("%80-s\n", $1)}' sourcefilename > targetfilename
The format string means "left-justify and pad the first argument to a length of 80." awk processes the whole file as a stream using the embedded newline characters as end-of-line indicators.
We have a convenience script named pad that wraps the awk command. You can also do something similar using any shell language or programming language, if you prefer.