Working with sequential files on Pipes

Question ID : 219
Created on 2013-11-21 at 9:00 AM
Author : Veryant Support [support@veryant.com]

Online URL : http://support.veryant.com/support/phpkb/question.php?ID=219



Piping can be used for files declared as:
a) a printer file (ASSIGN TO PRINTER)
b) a line sequential file (assuming to compile with -flsu)
In all other cases (relative file, binary sequential file etc) piping it is not allowed.

Here a simple program:


       program-id. pipe.
       environment division.
       input-output section.
       file-control.
           select my-file assign to printer '-p sh -c cat>pipe.txt'.
       data division.
       file section.
       fd my-file.
       01 my-rec pic x(60).
       procedure division.
       main.
           open output my-file.
           write my-rec from "abcdefghijk".
           write my-rec from "01234567890" 
           close my-file.

Some hints:


a) How to remove EOL characters and trailing spaces
In some cases it might be necessary to remove the line feed characters and trailing spaces from your piped file. To do that use "NO CONTROL" in your WRITE statements:

           open output my-file.
           write my-rec from "abcdefghijk" NO CONTROL.
           write my-rec from "01234567890" NO CONTROL.
           close my-file.

b) How to remove EOL characters but keep any trailing spaces
In some cases it might be necessary to remove the line feed characters but keep the trailing spaces in your piped file. To do that use "NO CONVERSION" in your WRITE statements:

           open output my-file.
           write my-rec from "abcdefghijk" NO CONVERSION.
           write my-rec from "01234567890" NO CONVERSION.
           close my-file.

c) If some characters are missing in your files
When using the -P for piping, the runtime framework will convert your characters internally to UNICODE. If you find some of your characters are missing, this may be because they were binary data and couldn't be converted. You can avoid this by using +P to prevent the UNICODE conversion.

  select my-file assign to printer '+p sh -c cat>pipe.txt'.


Back to Original Question