REXXTRY: Execute a line of REXX code and set &result

                 

Overview

The REXXTRY command is invoked in two different TSO/E environments to execute REXX execs:

  1. from a CLIST, to execute a "one-line" REXX exec
  2. in a batch job, to execute an in-line REXX exec

REXXTRY is written in assembler and runs in the MVS/ESA, OS/390 and z/OS environments. It is a free program, available in source-code and load-module format in the freeware section of this Web site.

           

Description

REXXTRY can be invoked as a command anywhere in the TSO/E environment: READY prompt, PDF opt 6, ISPF TSO command, CLIST, ISPF panel, ISPF command table, etc. In particular, in a CLIST or in batch TSO/E:

  1. in a CLIST, to execute a one-line REXX exec as a sub-routine. The REXX exec, which can be a single REXX instruction or multiple instructions separated by semi-colons, must be specified as an argument in the REXXTRY command, for example:
    REXXTRY a='A'; b='B'; RETURN a || b 

    If the REXX exec ends with a RETURN instruction (as shown in the example above), the returned value is stored into the &RESULT variable. The length of the data returned by the exec is limited to 256 bytes.

  2. in a batch TSO/E job step, in which case the REXX code is not specified as an argument to the command, but consists in all the input lines present after the REXXTRY command in SYSTSIN. Note that in batch mode, REXXTRY invokes the REXX code as a command and does not set &RESULT.to execute an in-line REXX exec, for example:
    //REXX    EXEC PGM=IKJEFT01
    //STEPLIB  DD DSN=CBTTAPE.FILE183.LOAD,DISP=SHR
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD *
    REXXTRY
    SAY 'Hello!' 

When REXXTRY runs in an on-line TSO session and no REXX code is specified as an argument, it displays its eye-catcher using TPUT and terminates with RC=20.

In the ISPF environment, if the REXX exec needs to access ISPF variables using VGET and VPUT, REXXTRY must be invoked with LANG(CREX). However, specifying LANG(CREX) prevents REXXTRY from storing the data returned by the REXX exec into &RESULT. Consequently, the REXX exec must be designed to use RETURN or VGET/VPUT, but not both. This restriction is imposed by the method ISPF uses to handle variables in the compiled REXX environment.

Examples

Invocation in a CLIST

    SET string = ABC DEF GHI JKL
    REXXTRY xxx="&string"; +
            n=WORDS(xxx); +
            RETURN WORD(xxx,n)
    WRITE LASTCC=&LASTCC RESULT=&RESULT 

Invocation in a CLIST - CLIST starts with PROC, ISPF BROWSE via STEMEDIT

    PROC 1 DSN ALL
    SET cmd = LISTC ENT(&STR(&dsn)) &all	/* TSO Command */
    REXXTRY RC=OUTTRAP("LINE."); "&cmd"; CC=RC; RC=OUTTRAP("OFF"); +
	    CALL STEMEDIT "BROWSE","LINE.",,,"&cmd" 

Invocation in an ISPF Panel; the REXX code ends with RETURN:

    %RESULT=&result
    )INIT
      IF (&result=&Z) &result=0
    )PROC
      &ZSEL='CMD(REXXTRY RETURN &result+1) MODE(FSCR)'
    )END 

Invocation in an ISPF Panel; the REXX code uses VGET and VPUT:

    %RESULT=&result
    )INIT
      IF (&result=&Z) &result=0
    )PROC
      &rexx='"VGET result"; result=&result+1; "VPUT result"'
      &ZSEL='CMD(REXXTRY ADDRESS ISPEXEC; &rexx) LANG(CREX)'
    )END 

Invocation in BATCH mode.

Execute two TSO TIME commands

    //TSO EXEC PGM=IKJEFT01,PARM='REXXTRY "TIME"; "TIME" ' 
    //STEPLIB  DD DSN=CBTTAPE.FILE183.LOAD,DISP=SHR    REXXTRY
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD DUMMY 

Execute two REXX SAY commands

    //TMP1    EXEC PGM=IKJEFT01,PARM='REXXTRY SAY DATE(); SAY TIME() '
    //STEPLIB  DD DSN=CBTTAPE.FILE183.LOAD,DISP=SHR    REXXTRY
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD DUMMY 

Execute in-line REXX code

    //TMP2    EXEC PGM=IKJEFT01
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD *
    TSOLIB ACT DS('CBTTAPE.FILE183.LOAD')
    REXXTRY
    SAY "this is my REXX exec (line 1)"
    SAY "this is my REXX exec (line 2)"
    EXIT 3 

BATCH mode - execute an in-line CLIST which uses REXXTRY to execute an in-line REXX exec

    //CLISTRX EXEC PGM=IKJEFT01
    //STEPLIB  DD DSN=CBTTAPE.FILE183.LOAD,DISP=SHR    REXXTRY
    //SYSPROC  DD DSN=CBTTAPE.FILE183.PDS,DISP=SHR     EXECUTE
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD *
    %EXECUTE CLIST
      /* The CLIST starts here */
    CONTROL LIST CONLIST                              /*CLIST*/
    WRITE Start of the CLIST                          /*CLIST*/
    REXXTRY A=1;                                      /*REXX*/ +
            B=2;                                      /*REXX*/ +
            UID=USERID();                             /*REXX*/ +
            RETURN(A+B UID)                           /*REXX*/
    WRITE LASTCC=&LASTCC RESULT='&RESULT'             /*CLIST*/
    EXIT CODE(&LASTCC)                                /*CLIST*/ 

Invocation via a CALL command

    //VIACALL EXEC PGM=IKJEFT01
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD *
    CALL 'CBTTAPE.FILE183.LOAD(REXXTRY)' 'SAY XXX; SAY YYY'
    /* 
    //VIACALL2 EXEC PGM=IKJEFT01
    //SYSTSPRT DD SYSOUT=*
    //SYSTSIN  DD *
    CALL 'CBTTAPE.FILE183.LOAD(REXXTRY)'
    SAY XXX
    SAY YYY
    /* 

Return-Codes

The return-code produced by the REXXTRY program is the return-code received from the REXX interpreter.