IF, ELSE, and ENDIF - FastExport

Teradata FastExport Reference

Release Number
English (United States)
Last Update
Product Category
Teradata Tools and Utilities

The IF, ELSE, and ENDIF commands provide conditional control of execution processes.

Table 36 describes the things to consider when using the IF, ELSE, and ENDIF commands.


Table 36: IF, ELSE and END IF Command Usage Notes 


Usage Notes

ELSE Clause

Use the optional ELSE clause to execute commands when the condition is evaluated as false.

Nesting IF Commands

FastExport supports the nesting of IF commands to a level of 100.

Numeric Results of the Conditional Expression

The conditional expression is an expression that can be evaluated as either true or false.

When evaluation of the expression returns a numeric result:

  • Zero is interpreted as false
  • Nonzero results are interpreted as true
  • Variables in the IF Expression

    The conditional expression can be either user‑defined variables or predefined system variables.

    Variable Substitutions

    Any ELSE or ENDIF commands must be present in their entirety and cannot be composed simply of variables in need of substitution.

    Commands and statements following an IF, ELSE, or ENDIF structure that are not executed are not parsed and do not have their variables substituted.

    FastExport is case sensitive when comparing &SYS system variables. In this example, the RUN FILE command does not execute because the substituted values returned are all capitals:

    0003 .IF ’&SYSDAY’ = ’Fri’ THEN;
    14:10:28  FRI MAY 09, 1993
    UTY2402 Previous statement modified to:
    0004 .IF ’FRI’ = ’Fri’ THEN;
    0005.RUN FILE UTNTS38;
    0006 .ENDIF;  

    Always consider this factor when creating a script to force the execution of a predetermined sequence of events. If ‘FRI’ is substituted in line 0003, the compare would work and the RUN FILE command would execute.

    In the following example, the user has created the table named &TABLE and a variable named CREATERC, into which is set the system return code resulting from the execution of the CREATE TABLE statement: .SET CREATERC TO &SYSRC;

    .IF &CREATERC = 3803 /* Table &TABLE exists */ THEN;
    .RUN FILE RUN01;
    .IF &CREATERC <> 0 THEN;

    If the table name has not already been used, and the return code is not zero, the return code evaluates to an error condition and the job logs off with the error code displayed.