MainframeSupports
tip week 24/2008:

Some of my colleagues has made me aware that I do not have any tip about PARSE SOURCE in REXX. The PARSE command in REXX is a statement with a lot of functionality and one of the neglected possibilities certainly is PARSE SOURCE.

PARSE SOURCE returns a string of words about the execution of the REXX executing the PARSE SOURCE command. The following example shows what the command returns. I assume the REXX is called MYREXX, it was started using TSO MYREXX in ISPF and the member MYREXX is found using the SYSEXEC DD concatenation:

/* REXX */
PARSE SOURCE A B C D E F G H I
SAY 'TSO = 'A
SAY 'INVOCATION TYPE = 'B
SAY 'NAME OF REXX = 'C
SAY 'NAME OF DD-NAME, REXX IS LOADED FROM = 'D
SAY 'NAME OF DATASET, REXX IS LOADED FROM = 'E
SAY 'NAME OF REXX AGAIN = 'F
SAY 'INITIAL HOST ENVIRONMENT FOR ADDRESS COMMAND = 'G
SAY 'ENVIRONMENT TYPE = 'H
SAY 'USER TOKEN = 'I

The typical output from the execution of the above REXX on the mainframe will look like this:

TSO = TSO
INVOCATION TYPE = COMMAND
NAME OF REXX = MYREXX
NAME OF DD-NAME, REXX IS LOADED FROM = SYSEXEC
NAME OF DATASET, REXX IS LOADED FROM = ?
NAME OF REXX AGAIN = ?
INITIAL HOST ENVIRONMENT FOR ADDRESS COMMAND = TSO
ENVIRONMENT TYPE = ISPF
USER TOKEN = ?

Invocation type will be either COMMAND, SUBROUTINE or FUNCTION. The environment type is either MVS, TSO or ISPF. The full description of PARSE is avaiable by clicking here. The real handy thing about PARSE SOURCE is of course its ability to tell you what the name of the actual executing REXX is. You may use this for many different purposes, but first and foremost to avoid hardcoding the REXX name in some REXX variable which you forget to change when you copy the same code to another REXX. Invocation type is also quite handy as it may be used to reject calls to a function made from the command line.

Previous tip in english        Sidste danske tip        Tip list