TAKE stage v1.0

Pipelines v2.0

 

Purpose, Operands, Streams used, Usage notes, Examples, See also

Home

 

Syntax

 

             _FIRST_    _1_______
>>__TAKE__ _|_______|__|_________|_ ___________________________________________________><
          | |_LAST__|  |_numrecs_| |
          |_ _ALL_ ________________|
            |_*___|

 

Purpose

 

Use the TAKE stage to select one or more records from the beginning or end of its primary input stream. TAKE copies the selected records to its primary output stream. If its secondary output stream is connected, TAKE copies all other records to its secondary output stream, otherwise it discards the unselected records.

 

Operands

 

    

FIRST

select records from the beginning of the input stream. This is the default.

 

    

LAST

select records from the end of the input stream.

 

    

ALL

*

specifies that all input records are selected and written to the primary output stream.

 

    

numrecs

is an unsigned integer which specifies the number of records to be selected from the input stream. The default is 1. If you specify 0 for numrecs, TAKE copies all of its input records to its secondary output stream, if it is connected, otherwise TAKE discards the records and the stage ends.

 

Streams used

 

The following streams are used by the TAKE stage:

 

Stream

Action

 

 

Primary input stream

TAKE reads records from its primary input stream.

Primary output stream

TAKE copies the selected records to its primary output stream.

Secondary output stream

TAKE copies the unselected records to its secondary output stream, if it is connected.

 

Usage notes

 

     1)

TAKE FIRST does not delay the records. TAKE LAST delays the specified number of records.

 

     2)

TAKE LAST stores the specified number of records in a buffer. For each subsequent input record (if any), TAKE LAST writes the record residing longest in the buffer to the secondary output stream, if it is connected. Otherwise, it discards the record. The input record is then stored in the buffer, queued on a first-in, first-out basis. When end-of-file is reached on the primary input stream, TAKE LAST writes the specified number of records from the buffer to the primary output stream, if it is connected, otherwise it discards the records.

 

     3)

If the TAKE stage discovers that all of its output streams are not connected, the TAKE stage ends.

 

     4)

TAKE FIRST disconnects its primary output stream before it writes the unselected records to its secondary output stream. TAKE LAST disconnects its secondary output stream before writing the records to its primary output stream.

 

     5)

TAKE verifies that its secondary input stream is not connected and then begins execution.

 

Examples

 

The following pipeline reads the file in.txt and displays on the console only record number 10.

 

**** Top of file ****
01 Address Rxpipe
02
03 ‘pipe < in.txt’,
04    ‘| drop first 9’,
05    ‘| take 1’,
06    ‘| console
07
08 Exit 0
**** End of file ****

 

See also

 

Reference the following links for additional information:

 

DROP, FROMLABEL, HOLE, TOLABEL

 

History of change

 

None.