Question

I have a Rexx script which functions standalone, and I wish to use another Rexx script to call particular functions within it. I am aware I can call both an entire external Rexx file and internal Rexx functions with call, but am I able to call a single function inside an external script? The following example illustrates what I want to do:

/* REXXA */
say 'hello'

run_test:
say 'test'

...

/* REXXB */
call 'REXXA' /* will say both 'hello' and 'test' */

How can I modify REXXB to say only 'test'?

EDIT: Further research indicates I might be looking for RxFuncAdd - can anyone confirm if that works with mainframe Rexx scripts? Most of the references involving it have been with regards to DLL libraries...

EDIT 2: Apparently not... anybody got any better ideas? RxFuncAdd routine not found

EDIT 3: I mustn't have explained my requirements properly, sorry about that - as per the comment under NealB's response, I essentially want something akin to calling a 'sin' function inside a 'math' class. The code I am writing is REXXB in the example above, and I want to change REXXA as little as possible.

Was it helpful?

Solution

Directly there's no way to address internal labels in another program.

My first gut reaction is that you would have to slightly modify REXXA to add a wrapper function with a function code, something like

/* REXX A */

arg a1 a2 a3 a4 a5 (etc.)
select
when a1 = 'SIN'
  call sin a2 a3 ....
when a1 = 'COS'
  call cos a2 a3 ....
end
exit rc

sin:
  return some equation involving a2 that I last saw about 33 years ago

cos:
  return some equation involving a2 that I last saw about 33 years ago

/* REXX B */
call 'REXXA' 'sin 85' 

However, REXX under TSO does support external functions and subroutines which can be written in many languages, including REXX. The TSO/E REXX Reference External functions and subroutines, and function packages, z/OS V11 flavor describes how to do this.

There is a note in the doc about optionally compiling the REXX. If you don't have it, you may be able to find someone who is licensed for it who could compile it for use with ALTLIB (no license necessary).

OTHER TIPS

cschneid has the right idea... The following works under both TSO (z/os) and Windows ooRexx:

REXXA:

/* REXXA */
parse source . as_a .
if as_a = 'COMMAND' then
   say 'hello'

run_test:
say 'test'
return

REXXB:

/* REXXB */
call 'REXXA' /* will say 'test' */
return

From the TSO or Windows Comand Line prompt: Typing REXXA will print both hello and test. Typing REXXB will print only test.

I must admit that I find this requirement a bit strange...

You might be able to use PARSE SOURCE to determine if you're being called standalone or by another Rexx exec. I haven't done this, but the documentation seems to indicate it would work.

Regarding your later edit: Ah, you want to write the moral equivalent of a DLL in Rexx, multiple entry points with none of them primary. I don't believe there's a way to do that just using Rexx on System z.

The only technique that comes to mind is to have a primary entry point to which you pass the name of the actual function you want to execute, along with its arguments. The main entry point would then call the specified function and return. Kludgy, sorry.

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