Question

I am quite new to Rexx, really basic stuff here, I want to get the last element of an array quickly.

Open Object Rexx 4.2.0 for Windows:

test.0=2
test.1="foo"
test.2="bar"
say test.[test.0]

==> Output as wanted:

bar

My easy guess is that the Open Object Rexx interpreter is at work. Square brackets can't be used with Rexx on z/OS.

1st stuff that came to my mind (didn't RTFM) :

say test.test.0
say test.(test.0)

==> Output not good:

TEST.TEST.0
    5 *-* say test.(test.0)
Error 16 running Test.REX line 5:  Label not found
Error 16.1:  Label "SYNTAX" not found

Is there other usages of square brackets ? Why coming from C/Java/Python I am going for test.test.0 or test.(test.0) like a dummy ?

Can't find more information about square brackets usage in Rexx than this: #Reginald's tail expression

So under z/OS for now I am stuck with:

temp=test.0
say test.temp
Was it helpful?

Solution

You have found the answer to your question already.

The only way under mainframe REXX (z/OS, z/VSE, z/VM) is as you coded above:

temp=test.0
say test.temp

The best documentation for understanding what the REXX interpreter is doing can be found in the z/OS TSO/E REXX Reference under Compound Symbols (V2.1 link). It describes why test.test.0 won't work, because of how the interpreter handles the line; in this case, it is looking for a stem test.test.0.

Note that you could code

test.test.0 = 0

and you would have a valid stem test.test.0 (albeit probably useless in most cases).

The next topic in the link discusses stem variables, which also has lots of useful information.

I highly recommend reading both the z/OS TSO/E REXX Reference and the z/OS TSO/E REXX User's Guide (both V2.1 links).


OTHER TIPS

Other pure (non-Object) Rexx alternatives:

interpret "say test." || test.0

or

say value("test." || test.0)

The default Rexx interpreter on z/OS is Classic Rexx, not OORexx. OORexx has not been ported to z/OS.

Bear in mind that (in z/OS, at least) the '.0' variable is not automatically updated. E.g.:

list.1 = 17
list.2 = 12
say 'List.0 is' list.0

Will give 'LIST.0', which is the default value (the variable's name) for an initialised variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top