% IF/ELSE-IF/ELSE

Evaluate a condition.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

Syntax:

 % IF condition1
    statementblock
 % ELSE-IF condition2
    statementblock
 % ELSE-IF conditionN
    statementblock
 % ELSE
    statementblock
[% END]

Parameters:

condition Can be a
  • Number
  • Literal enclosed in apostrophes or quotation marks
  • Variable
  • Relational operator, which can be =, NOT =, <, >, NOT <, NOT >, <=, >=
  • Value, which can be a number, a literal enclosed in apostrophes or quotation marks, or a variable

Numbers, literals, and variables must be followed by a space and a relational operator; followed by a space and a value. To specify multiple conditions, use the Boolean operators AND or OR with no parentheses.

Comments:

  • Indent each level of subordinate source code a consistent number of columns; we recommend four columns.
  • During processing, the Customizer moves statement blocks to the starting columns of their controlling % IF, % ELSE-IF, and % ELSE statements.
  • The limit of % ELSE-IFs for a single % IF is 199.
  • This structure executes identically to the S-COBOL IF/ELSE-IF/ELSE structure.
  • If an ELSE statement is followed by an IF statement (that is, ELSE ... IF instead of ELSE-IF), code the IF on the next line, and indent it. See the "Examples" below.

Examples:

Test a variable for a numeric condition.

% IF &LEN = 80
% IF &APS-INDENT < 8

Test a variable for a true condition, represented by the value 1.

% &EMPLOYEE-TYPE-A = 0
% &EMPLOYEE-TYPE-B = 1
% IF &EMPLOYEE-TYPE-B
    statementblock

Test a variable for multiple conditions.

% IF &APS-INDENT < 8 OR &APS-INDENT > 11

Code an ELSE ... IF rather than ELSE-IF.

% ELSE
    % IF &A = "ABC" OR &B = "DEF"

Nest conditional statements.

% IF condition1
   statementblock1
    % IF condition2
        % IF condition3
           statementblock2
        % ELSE-IF condition4
        % ELSE-IF condition5
           statementblock3
        % ELSE
           statementblock4
    % ELSE
       statementblock5
        % IF condition6
            % IF condition7
           statementblock6
   statementblock7