> (FILEOUT)
v1.1
v2.1

Purpose, Argument, Streams, Usage, Examples, Related

Syntax

                                      (2)┌─WRITE──┐ 
                 ┌─NOCLOse─┐             ├─R/W────┤
>>──┬─>───────┬──┼─────────┼──┬───────┬──┼────────┼──┬──────────┬────────────────────>< 
    └─FILEOUT─┘  └─CLOse───┘  └─RECno─┘  ├─RDONLY─┤  └─filename─┘
                                         └─R/O────┘    (1)
Notes: (1) The filename operand is only allowed if the stage does not have a secondary input stream connected. (2) Unless the WRITE keyword is specified; a file that is write-protected (RDONLY) remains write-protected after it has been processed. (3) FILEOUT cannot be specified as the first stage in a pipeline.
Purpose

Use the FILEOUT stage to create a disk file or replace the contents of a disk file.

FILEOUT reads records from its primary input stream and writes them to the specified file and to its primary output stream, if it is connected. FILEOUT appends a Line-Feed character to each output record that it writes to the specified file, primary output stream records are written unchanged. If the specified file does not already exist; FILEOUT creates a new file containing the records read from its primary input stream. If the specified file already exists, FILEOUT replaces the contents of the file with the records read from its primary input stream.

If you do not specify a fully qualified path and filename; the FILEOUT stage will create a new file in the current working directory.

Argument
Streams

The following streams and files are used by the FILEOUT stage:

  1. Input streams

  2. Output file

  3. Output streams:

Usage
  1. FILEOUT does not delay the records.

  2. If FILEOUT discovers that its primary input stream is not connected, the FILEOUT stage ends.

  3. FILEOUT determines if an output exists at the moment the file is opened for writing. FILEOUT opens an output file for writing when there is an output record to write. FILEOUT does not create empty files.

  4. When FILEOUT opens an existing output file for writing; the contents of the file, if any, are replaced.

  5. FILEOUT appends a Line-Feed character to all but the last record that it writes to the specified output file.

  6. FILEOUT does not write directly to the target output file; to preserve the integrity of the target file (an existing file) in the event of a pipeline runtime error (or a user intervention – CTRL-C, end-task or close-window); FILEOUT writes its output records to an intermediate work file. Only at the end-of-file on the primary input stream will FILEOUT swap this work file for the final target output file.

    When the FILEOUT stage is interrupted or if FILEOUT encounters an unrecoverable error (and the stage may be unable to finalise its final file the file-write) the intermendiate work file(s) will be left as-is and available for inspection.

    A work file has a specific filename format that will allow you to determine what the file was created for, the manager, and pipeline and stage that created it. The following schema defines the format of a work file:

    The format of an intermediate work file is:
    FILEOUT.TYPE=%s.FILE=%s.PID=%.5d.PIPE=%.4d.STAGE=%.4d.UNQ=%10.0d.DAT
    Element Meaning ------- -------
    %s The stage (DLL name) FILEOUT . separator TYPE=%s 'NEW' or 'SWAP' . separator FILE=%s The target output filename (including .ext if it is specified) . separator PID=%.5d The process identification number of the manager . separator PIPE=%.4d The pipeline number . separator STAGE=%.4d The stage number . separator UNQ=%10.0d A ten digit (unique) number derived from the current system time . separator DAT The file extension

  7. FILEOUT verifies that its secondary output stream is not connected and then begins execution.
Examples
  1. The following pipeline reads records from the console and writes them to the file: myfile.txt. The pipeline ends when a null record is entered.

    'pipe console | > myfile.txt 
    

  2. The following example show how the CONSOLE stage reads interactively from the keyboard; writing each of the input records to the output file: keyboard.txt. For each input record; the FILEOUT stage produces an output record that comprises a ten-digit field, right-aligned with leading spaces, the delimiter 0x20 (a blank) followed by the contents of the input record.

    **** Top of file ****
    Address Rxpipe
    'pipe cons eof /stop/', '| xlate', '| recno >', '| console'
    Exit 0 **** End of file ****

    console:
    CONSOLE(0): 'stop' to end. CONSOLE(0): ? one 1 ONE CONSOLE(0): ? flew over 2 FLEW OVER CONSOLE(0): ? the cuckoos 3 THE CUCKOO'S CONSOLE(0): ? nest 4 NEST CONSOLE(0): ? stop

    keyboard.txt
    
    ...|...+....1....+....2....+....3....+....4....
       **** Top of file ****
     1          1 ONE
     2          2 FLEW OVER
     3          3 THE CUCKOO'S
     4          4 NEST
       **** End of file ****
    
Related

CONSOLE, >> (FILEAPPEND), > (FILEIN), IN, OUT

History

Version
Date
Action
Description
Pipelines
1.1
??.??.2025
changed
Application-wide rewrite
2.1
1.0
06.09.2007
created
First version.
1.0