FILEOUT (>) stage v1.1

Pipelines v2.1

 

Purpose, Operands, Streams, Usage, Examples, Related

Home

 

Syntax

 

>>───FILEOUT───────────────────────────────────────────────────────────────────><
    └─>───────┘  └─RECno─┘  └─filename─┘
                              (1)
 
Notes:
(1) The filename operand is only allowed if the stage does not have a
    Secondary input stream connected.
(2) 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.

 

Operands

 

RECno

specifies that a record number should be inserted in to both the output file record and the primary output stream record.

 

filename

is the name of the output file.

 

Streams

 

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

 

1.

Input Streams

 

 

When the secondary input stream is connected.

 

FILEOUT will not allow the filename argument to be specified. FILEOUT first reads a record from its secondary input stream, which it treats as the name of the file to which it should write. If the content of the record (the filename) is different from the previous secondary input stream record, FILEOUT closes the current output file and opens the new one specified in the record. FILEOUT next reads a record from its primary input stream; writes this record to the target output file and then writes the record to its primary output stream, if it is connected. This process continues until the end-of-file is reached on the primary input stream.

 

Secondary input stream:

 

|...+....1....+....2....+....3....+....4....

c:\myfile.dat

c:\myfile.dat

d:\yourfiles\yourfile.dat

..

..

d:\yourfiles\yourfile.dat

 

Primary input stream:

 

|...+....1....+....2....+....3....+....4....

record

record

record

..

..

record

 

When the secondary input stream is not connected, the filename argument is allowed.

 

1.

When the filename argument is specified.

FILEOUT reads records from its primary input stream and writes them unchanged to the specified file, and to its primary output stream, if it is connected.

 

Primary input stream:

 

|...+....1....+....2....+....3....+....4....

record

record

record

..

..

record

 

2.

When the filename argument is not specified.

FILEOUT expects its primary input stream records to follow a specific format; the record must comprise an output filename, followed by the delimiter 0xff and the record (data) to write to the output file. FILEOUT extracts the output filename and if it differs from the filename specified in the previous primary input stream record (the current output file), then FILEOUT closes the current output file and opens the new one. FILEOUT writes the record (data) part of the primary input stream record to the specified file, and to the primary output stream, if it is connected.

 

Primary input stream:

 

|...+....1....+....2....+....3....+....4....

c:\myfile.datXrecord

c:\myfile.datXrecord

d:\yourfiles\yourfile.datXrecord

..

..

d:\yourfiles\yourfile.datXrecord

 

2.

Output file

 

 

Without RECno operand:

 

 

FILEOUT writes the data part of the primary input stream record to the specified file.

 

...|...+....1....+....2....+....3....+....4....

   **** Top of file ****

 1 record

 2 record

 3 record

 . ..

 . ..

99 record

   **** End of file ****

 

With the RECno operand:

 

 

FILEOUT writes the current output record number; a ten-digit field, right-aligned with leading spaces, the delimiter 0x20 (blank) and the contents of the primary input stream record to the specified file.

 

...|...+....1....+....2....+....3....+....4....

   **** Top of file ****

 1          1Xrecord

 2          2Xrecord

 3          3Xrecord

 .         ..

 .         ..

99         99Xrecord

   **** End of file ****

 

3.

Output streams

 

 

Primary output stream:

(without RECno operand)

 

 

FILEOUT writes the data part of the primary input stream record to the specified file.

 

|...+....1....+....2....+....3....+....4....

record

record

record

..

..

record

 

Primary output stream:

(with RECNO operand)

 

 

FILEOUT writes the current output record number; a ten-digit field, right-aligned with leading spaces, the delimiter 0x20 (blank) and the contents of the primary input stream record to the specified file.

 

|...+....1....+....2....+....3....+....4....

         1Xrecord

         2Xrecord

         3Xrecord

        ..

        ..

        99Xrecord

 

Usage

 

1.

The FILEOUT stage does not delay the records.

 

2.

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

 

3.

When the FILEOUT stage opens an output file, the file remains locked against read and write access until the file is closed.

 

4.

If the pipeline is forcibly terminated (CTRL-C or the console window is closed) whilst FILEOUT is still active, an existing file remains unchanged. An existing file is only replaced at the successful completion of the FILEOUT stage.

 

5.

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

 

6.

The FILEOUT stage 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.

 

'pipe console | > myfile.txt'

 

2.

Copy

 

3.

?

 

4.

?

 

5.

?

 

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