VARIABLE stage v1.1

Pipelines v2.1

 

Need examples

 

Purpose, Operands, Streams, Usage, Examples, Related

Home

 

Syntax

 
Tracking needs a tool tip!
 
 
>>──VARiable──┬─name────────┬──┬──────────┬──────────────────────────────────────────><
              ├─name[index]─┤  └─TRACKing─┘
              └─name.index──┘
 

Purpose

 

Use the VARIABLE stage to retrieve or set an ooRexx variable, array or stem entry.

 

By default, when VARIABLE is the first stage of a pipeline; VARIABLE retrieves the value of an ooRexx variable and writes the value to its primary output stream. When VARIABLE is not the first stage of a pipeline, VARIABLE sets the specified variable to the contents of the first record in its primary input stream and then the VARIABLE stage terminates. If at termination; the VARIABLE stage determines that no input records have been read and that the specified ooRexx variable is a simple variable (not an array or stem entry); then the variable is dropped, otherwise the specified array or stem entry remains unchanged. VARIABLE also copies its primary input stream records to its primary output stream.

 

Operands

 

name

specifies the name of the ooRexx variable, array or stem entry on which to operate.

 

 

index

an unsigned integer which specifies the array or stem index.

 

TRACKing

specifies that VARIABLE, when it is the first stage of a pipeline; continuously obtains the value of the variable and writes it to the primary output stream. When VARIABLE is not the first stage of a pipeline, TRACKING specifies that VARIABLE sets the variable to the contents of each input record that is read. The final value of the variable is the last record read from VARIABLE's primary input stream. The variable remains unchanged if no records are read from the primary input stream.

 

Note: that VARIABLE with the TRACKING operand, when it is the first stage of a pipeline; writes an infinite number of records unless you limit the number of records.

 

Streams

 

The following streams are used by the VARIABLE stage:

 

Stream

Action

 

 

Primary input stream

VARIABLE reads records from its primary input stream, if it is connected and writes them the specified ooRexx array.

Primary output stream

VARIABLE writes records to its primary output stream, if it is connected.

 

Usage

 

1.

VARIABLE does not delay the records.

 

2.

If the VARIABLE stage discovers that both its primary input and primary output streams are not connected, the VARIABLE stage ends.

 

3.

With the TRACKING operand, when it is the first stage of a pipeline; writes an infinite number of records unless you limit the number of records.

 

4.

VARIABLE verifies that it has either/and a primary input stream and primary output stream connected and then begins execution.

 

5.

You should be mindful of the way in which ooRexx handles variable definitions when you use the VARIABLE stage. In order to assign a new value to an existing variable; you must provide the name of the variable as an explicit literal argument on the VARIABLE stage. Consider the following example:

 

   **** Top of file ****
 1 Address Rxpipe
 2
 3 /* A simple stem with four elements. */
 4
 5 mystem.1 = "The"
 6 mystem.2 = "quick"
 7 mystem.3 = "brown"
 8 mystem.4 = "fox"
 9 mystem.0 = 4
10
11 'pipe variable mystem.3',       /* Retrieve the value in element number 3 */
12    '| change /brown/ /red/',    /* Change "brown" to "red" */
13    '| var' mystem.3             /* Set the new value of element number 3, you think! */
14
15 Do i = 1 to mystem.0
16    Say "mystem."i" = " || mystem.i
17 End
18
19 Say "brown = " || brown
20
21 Exit 0
   **** End of file ****

 

output:

mystem.1 = "The"

mystem.2 = "quick"

mystem.3 = "brown"

mystem.4 = "fox"

brown = red

 

Note. The value in mystem.3 remains unchanged, because the name of the variable provided by ooRexx to the VARAIBLE stage on line: 13 was interpreted as brown (the value of mystem.3), hence the variable named brown is assigned the value red. To ensure that variable names are treated as literal definitions; always provide the variable as an explicit literal argument:

 

10 ...
11 'pipe variable mystem.3',       /* Retrieve the value in element number 3 */
12    '| change /brown/ /red/',    /* Change "brown" to "red" */
13    '| var mystem.3'             /* Set the new value of element number 3, correctly! */
14 ...
 

Examples

 

1.

/* FINDMAX EXEC */

parse arg x y                     /* get arguments in x and y */

maxnum = max(x, y)                /* find largest of the two */

'pipe var maxnum | > MAX FILE A'  /* write largest to MAX FILE A */

 

2.

/* READLAST EXEC */

 

'pipe literal a b c | split | var letter tracking'

say 'The letter you want is ' letter

 

3.

4.

 

/* CHECKNAM EXEC */

'pipe',

  '<' userid() 'NAMES',         /* read user's CMS NAMES file */

  '| split before string /:/',  /* split lines before colons */

  '| find :nick.'||,            /* find beginning of a nickname */

  '| count lines',              /* count the number of nicknames */

  '| var namewrds'              /* set variable with the count */

                                /* issue messages based on count */

if namewrds > 100 then say "You know lots of people, don't you!"

   else say "You should try to get out more often!"

exit

 

Related

 

ARRAY, STEM

 

History

 

Version

 

Date

Action

Description

Pipelines

1.1

28.12.2021

changed

Application-wide rewrite.

2.1

1.0

04.02.2012

created

First version.

2.0