COBOL Manual for TNS and TNS/R Programs

Program Compilation
HP COBOL Manual for TNS and TNS/R Programs522555-006
11-85
IF and IFNOT
COPY and REPLACE statements are not affected by this directive; they are still
processed and expanded. In contrast, a SOURCE directive is ignored when it is part of
the ignored text.
If a given toggle is not set, any directives between an IF for that toggle and its
subsequent ENDIF are parsed but are not acted upon; if a given toggle is set, any
directives between an IFNOT for that toggle and its subsequent ENDIF are parsed but
are not acted upon.
In Example 11-11, if toggle 1 is turned on, the ADD statement is compiled; if toggle 1 is
turned off, the COMPUTE statement is compiled.
Example 11-11. IF Directive
?IF 1
ADD A B C GIVING D
?ENDIF 1
?IFNOT 1
COMPUTE D = A + B + C
?ENDIF 1
Note. The IFNOT directive does not behave like an ELSE clause of the IF directive. Each IF
and each IFNOT must have its own ENDIF directive.
Example 11-12. Nested IF and IFNOT Directive Scopes
IF and IFNOT scopes can be nested. Given this program fragment:
01 MASTER-RECORD.
03 HEADER PICTURE X(30).
?IF 1
03 ACCOUNT-ID PICTURE X(50).
?IF 2
03 ACCOUNT-ID-REDEF REDEFINES ACCOUNT-ID.
05 ACCOUNT-GROUP PICTURE X(20).
05 ACCOUNT-CLASS PICTURE X(10).
05 ACCOUNT-NUMBER PICTURE X(20).
?ENDIF 2
03 TRAILER PICTURE X(100).
?ENDIF 1