Previous Topic Next topic Print topic


%IF

Purpose

Conditionally executes code based on a test expression.

Syntax

%[label:]... IF expr %THEN clause-1 [%ELSE clause-2]

Parameters

expr is any expression that results in a scalar bit string value of length ≥ 1. The test-expression is considered true if any bit in the string is one; the expression is considered false only when all bits are zero. clause-n is any single preprocessor statement (other than %DECLARE, %PROCEDURE, %END or %DO), or a preprocessor DO group. Otherwise, the description is the same as that of Open PL/I IF statements.

Description

The %IF statement can control the flow of the scan according to the value of a preprocessor expression.

The preprocessor expression is evaluated. If the result of the evaluation is 1 or greater than 1, clause-1 is executed and clause-2 is ignored, if present. If the result of the evaluation is 0, clause-1 is ignored and clause-2, if present, is executed. In either case, the scan resumes immediately following the IF statement, unless, of course, a %GOTO in any of the clauses causes the scan to resume elsewhere. %IF statements can be nested according to the rules for nesting Open PL/I IF statements.

Example

%DECLARE (A,B) CHARACTER;
%A ='CONTROL_1';
%B = 'NAME';
%IF A = 'CONTROL_1' 
%THEN %DO;
   RES = B + F(X); 
%END;
%ELSE %DO;
   RES = B - F(X) + SQRT(X);
   LST = F(X) + 1; 
%END;

The text generated by this example would be as follows:

RES = NAME + F(X);
Previous Topic Next topic Print topic