2. Syntax inside action blocks

2a. Iterations

do i = 2 by 2 to 12 /* execute for i = 2, 4, 6, 8 ,10 ,12 */

  some-action

end

 

do forever /* execute until the command 'leave' is reached */

if some-logical-evaluation-is-true then iterate /* start over */

some-action

if some-other-logical-evaluation-is-true then do

leave /* leave this do loop now */

end

end

2b. Evaluations

 

if some-logical-evaluation-is-true then do /* either or: */

some-action

end

else do

some-other-action

end

 

select /* evaluate or case structure: */

when some-logical-evaluation-is-true then do

some-action

end

when some-other-logical-evaluation-is-true then do

some-other-action

end

otherwise do /* Note: 'otherwise' clause must always be stated */

another-action

end

end

RXS normally uses the syntax above: an if-statement is a separate line ending with 'then do'.  What is to be done is ended with an 'end' in a separate line.

A short form may be used: if some-logical-evalution-is-true then some-action

2c. Operators

'some-logical-evaluation' means some expression containing an operator, that is '=', '<', '>' and the like. Example: a < 14. The operator <> (not equal) is valid in RXS.

Two or more logical evaluations may be combined into one using the logical operators '&' (and) '|' (or) and parenthesis. Example:

if (a > 14 & b >= 13) | c <> 12 then do

In Nordic countries, France, Germany, Austria and Italy, the 'or' operator is '!'. This oddity is enherited from REXX or more correctly, from EBCDIC.

 

This inconvenience applies generally to RXS: When in the Nordic countries, France, Germany, Austria or Italy: Whenever the documentation specifies '|' then use  '!'.

2d. Variables

Names for variables in RXS must start with a letter; special characters are not allowed. Maximum length of a name is 250 characters. Underscore '_' is allowed, hyphen '-' is not allowed.

Names starting with the characters rx_ are reserved for internal use and cannot be used.

Variables in RXS are allocated automatically. Variables are typeless, the variable a may contain a number or an alphanumeric constant. But asking if a > 14 will only evaluate to true or false if a is currently holding a numeric value. Otherwise execution is terminated in error.

 Alphanumeric constants in RXS must be contained in quotes - single or double. Maximum length of a quoted string in an assignment is 256 characters. Internally in RXS, an alphanumeric string can hold up to 16 MB of data (see section 2n below).

Numeric constants in RXS hold up to 15 digits. Exponential notation is possible: 1.4E+02 is 1400.

Hexadecimal constants in RXS are in the form "12AB"X

A 'stem'  in RXS is an array. The form of a stem is variabelname.number. For example      mystem.14, or mystem.mynumbr, provided that mynumbr is the name of a variable containing a number. (It is also accepted that mynumbr is not numeric).

The assignment mystem. = '' will initialize all possible values inside mystem.

2e. Active statements in RXS

'some-action' in the text above indicates one of the following active elements in RXS:

2f. Active statements: Assignments. Functions.

RXS uses assignments in the form: a = 14 or a = random(). Here random() is an example of a function in RXS. RXS has a rich collection of functions, most of them dealing with strings - see section 40.

Assignments may contain arithmetic: multiply a * b, divide a / b, square a ** 2. And a + b and a - b. Parenthesis may alter the normal order of evaluation.

2g. Active statements: External calls

The call of an external function in RXS is in the form:  call myrexx

This assumes that myrexx is a rexx or a clist residing on a library allocated to the tso-session. Section 31 and 33 explain other forms of external calls.

2h. Active statements: Instructions

An instruction in RXS is a command that alters the further proceedings of the program.

For example iterate (see section 2a), leave (section 2a), exit (see section 2m below). All instructions in RXS are listed in section 40.

2i. Active statement: Nested action blocks

An action block may be situated anywhere where an active statement is acceptable. This indicating that action blocks can be nested.  Which doesn't make much sense for now: action blocks are just blocks of REXX coding. The purpose of this construct will be revealed in section 18.

2j. Active statements: Strings

A string may be situated any places where an active statement is acceptable. A string is a line surrounded by single or double quotes (plus some other situations which RXS classifies as strings: evaluations which transforms into strings after evaluation). In the case of a string, RXS will write the string to output. See Section 4 for further discussion.

Example 2.1:

)action

do i = 1 to 2

i"."  

do 3

if i = 1 then do

"What shall we do with the drunken sailor"

end

else do

"Put him in the longboat till he's sober"

end

end

"Early in the morning"

" "

end

)endaction

Example 2.1 is a slightly more advanced programming of our current example: output will be as in example 1.1 Notice that lines in an action block may be intended - to increase readability.

The second line in the action block: i"." transforms into a string after evaluation. The evaluation results in a replacement of the variable i with its current value.  The thereby created string will be written to output by RXS.

 

2k. Statements are separate lines: one statement per line

The above elements in RXS have to be written as separate lines in the action block. It is possible to continue a line: ending a line with ',' will concatenate the next line to this line. It is also possible to write several lines in one line, separating the parts by ';'.

Otherwise no constraints on layout exists: RXS statements in actions blocks can have any amount of leading 'white space', and can be written in any dataset.

2l. Comments

/* starts a comment, */ ends a comment.

2m. RXS compared to REXX

The syntax described above is equivalent to REXX syntax. It is REXX: RXS uses the interpreting engine supplied by REXX to interpret and execute coding inside action blocks. Accordingly, even more advanced elements in the REXX language may be used in RXS - for instance REXX commands for handling input and output, and REXX commands for handling stacks and queues. But such advanced REXX elements are not often used in RXS: the handling of text-blocks and other internal files inside the RXS program and the handling of files externally in the form of input and output is more easily handled using the basic machinery in RXS. 

Two REXX constructs are not allowed in RXS:

This implies that execution in a RXS program is always sequential: top down. An action block is executed when the execution hits the block; it cannot be 'called'.

Notice that call of external routines, for instance the calling of REXX or RXS programs, is supported by RXS (See section 31 and 33).

There are two differences between detailed functionality in RXS and REXX:

Finally: RXS differs from REXX by supplementing REXX with a (small) number of new functions and instructions. All relevant functions and instructions in RXS are listed in Section 40.

2n. "Program memory exhausted"

REXX variables have an implementation maximum: No single request for storage can exceed the fixed limit of 16 MB. This limit applies to the size of a variable plus any control information. It also applies to buffers obtained to hold numeric results. 

The limit is often lower than 16 MB when running in tso (in foreground). It depends on the region size at logon. The maximum may be as low as 3 MB. The relation between region size and maximum length of a data structure in RXS is not obvious. If the limit is reached, execution halts with the error message "Program memory exhausted".

A file read or written from RXS cannot exceed about 1 GB. All external and internal files in RXS are kept in memory during execution of the program. Accordingly, RXS uses a lot of high memory during execution.

Running RXS in the background might be needed if the program is very data intensive. Here using REGION=0K in the JOB-card will maximise the amount of high memory. See section 36.