IF-THEN-ELSE – Conditional execution

Use the IF and THEN construct to conditionally execute a Workload Automation Programming Language statement, or block of statements if true. Use the ELSE statement to allow an alternative statement or block to run, if the condition is not true. These commands use underlying REXX processing to evaluate the expression.

The basic syntax is:
IF <expression> THEN
     <command1>
ELSE
     <command2>

The expression can be any valid REXX expression that results in 1 or 0. For more details about REXX expressions and available functions, see TSO/E REXX Reference.

Although Workload Automation Programming Language uses the REXX interpreter to evaluate the expression, there are some considerations to be made for Workload Automation Programming Language use:

  • Workload Automation Programming Language variables are resolved before the statement is run, rather than evaluated by the REXX interpreter. This means that any Workload Automation Programming Language variable that includes special characters, such as blanks, must be enclosed within double quotation marks:
    IF "!TAG" = "-JOBNAME" THEN DO
  • If the THEN keyword is surrounded by blanks, it must not appear within the IF or THEN expression, even if within double quotation marks. Therefore, the following example is valid because THEN does not have blanks around it:
    IF “!MYVAR” = “THEN” THEN DO
    When THEN needs blanks around it, you must specify it in a variable, as follows:
    VARSET THEN VALUE(THEN)
    IF “!MYVAR” = “THIS !THEN THAT” THEN DO
  • Workload Automation Programming Language functions can be used within IF, THEN, and ELSE constructs, but cannot contain any REXX functions within the bounds of the Workload Automation Programming Language function. Only literal text or variables can be contained within the arguments of Workload Automation Programming Language functions. Workload Automation Programming Language functions are prefixed by the at sign (@).
    The following example is not valid:
    IF (@JCL(RIGHT(!LINE,8)..EQ.0)) & (LEFT(“!JOB”,1) = “P”) THEN
    but must be handled by resolving the REXX function in a previous statement:
    VARSET STEP = RIGHT(!LINE,8)
    IF (@JCL(!STEP..EQ.0)) & (LEFT(“!JOB”,1) = “P”) THEN
The conditional commands <command1> and <command2> can be included in the same line as THEN and ELSE, respectively. For example:
IF “!TAG” = “-JOBNAME” THEN VARSET COLLECT = “YES”
ELSE VARSET COLLECT = “NO”
To run multiple commands conditionally, use a DO, END block:
IF “!TAG” = “-JOBNAME” THEN DO
   VARSET COLLECT = “Y”
   ITERATE
END
You can use AND or OR within parentheses and the ampersand (&) and vertical bar (|):
IF (“!DAY” = “WED”) & (“!MONTH” = “JAN”) THEN
IF (“!DAY” = “MON”) | (“!DAY” = “TUE”) THEN