Monday, August 22, 2016

REXX: How to Execute a REXX inside a REXX

It is possible to execute a REXX inside another REXX using the EXEC command.

For example, we shall use this approach to Read the pdsname and member name and pass this information to an another REXX procedure which will work upon this file and produce an output file. We shall open that output file and show it to the user using the outer REXX.

Lets us name the REXX reading the PDSNAME and Member Name as REXX 1.

Lets us name the REXX processing the member as REXX 2.

Rexx 1 should call the REXX 2 using the following code

"EXEC 'Dataset where REXX 2 is residing' '"Input-file"'"  

Rexx 2 will process the Input file and produce an output file.

This output file could be opened from REXX 1 and displayed to the user using the following code.

ADDRESS ISPEXEC "EDIT DATASET("OUTPUT-FILE") "

In case of queries, please post in the comments.

4 comments:

  1. It can even be done in a single routine. The only reasons to use an external routine is if it already exists -- and you don't have to write it -- or if it would have some utility as an independent routine.

    For instance, a routine which handles several PDSs might call an external routine to return a concise list of members, eliminating the need to have that code local to the new routine.

    ReplyDelete
    Replies
    1. that's correct... This is just an example here explaining how it could be done... its up to the application programmer to decide and select best possible way to develop a macro...

      Delete
    2. Do you have any concrete example on how to call endevor directly from a REXX? If yes, can you post your code and explain it? P.S. Accessing endevor via jcl isn't required.

      Delete
  2. Virtually anything you can run via JCL you can run via REXX. It's a simple matter of having all the required allocations:
    "ALLOC FI(C1MSGS1) UNIT(VIO) SPACE(5 5) TRACKS NEW DELETE REU"
    "ALLOC FI(ENPSCLIN) UNIT(VIO) SPACE(1) TRACKS NEW DELETE REU"
    "ALLOC FI(SYSPRINT) DUMMY REU"

    "EXECIO" queued() "DISKW ENPSCLIN (FINIS"

    "XEQ ENBP1000" /* invoke endevor */

    "EXECIO * DISKR C1MSGS1 (STEM NDV. FINIS" /* Read c1msgs1 (output) */

    as a single example.

    ReplyDelete

Featured Post

REXX Skeleton: Submitting jobs through Rexx

Submitting jobs through REXX and reading the spool through REXX gives us immense potential to automate many manual activities in mainframes....