Piping it is allowed for file declared as:
a) printer file (ASSIGN TO PRINTER)
b) 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 termination characters removing trailing spaces
In same cases could be request to remove EOL from piping file. In order to do that it is useful to add "NO CONTROL" in WRITE statements:
open output my-file.
write my-rec from "abcdefghijk" NO CONTROL.
write my-rec from "01234567890" NO CONTROL.
close my-file.
b) some characters are missing in pipe files.
In case that UNICODE internal conversion (default behavior with -P) is unable to convert some characters, that could happen if binary data are used, +P should be used instead because it prevent UNICODE conversion.
select my-file assign to printer '+p sh -c cat>prova.txt'.
c) how to remove EOL and maintains trailing spaces
In same cases could be request to remove EOL from piping file and maintains the trailing spaces. In order to do that it is useful to add "NO CONVERSION" in WRITE statements:
open output my-file.
write my-rec from "abcdefghijk" NO CONVERSION.
write my-rec from "01234567890" NO CONVERSION.
close my-file.
|