Examples of conditional compilation

Example 1: use predefined compilation variables to enable a program to be used in both CICS and BATCH:

Suppose that the CICS compiler option is in effect and the compiler works with the integrated CICS® translator:

>>IF IGY-CICS
     EXEC CICS READ FILE-1... *> Read a record in CICS
>>ELSE
     READ FILE-2              *> Read a record in BATCH
>>END-IF

Example 2: import numeric variable value from outside the source and test it

Suppose that DEFINE(VAR1=10) is in effect:

>>DEFINE VAR1 AS PARAMETER
. . .
>>DEFINE VAR2 AS VAR1 + 2
. . .
>>IF VAR2 < 12
     compute x = x + 1 *> this code should NOT be included
>>ELSE
     compute x = x – 1 *> this code should be included
>>END-IF

Example 3: use the format 1 EVALUATE directive with numeric compilation variables

>>DEFINE VAR1 AS 6
>>DEFINE VAR2 AS 1
. . .
>>EVALUATE VAR1
>>WHEN VAR2 + 2
       compute x = x + 1 *> this code should NOT be included
>>WHEN 4 THRU 8
       compute x = x – 1 *> this code should be included
>>WHEN OTHER
       compute x = x * 2 *> this code should NOT be included
>>END-EVALUATE

Example 4: use the format 2 EVALUATE directive with alphanumeric compilation variables

>>DEFINE VAR1 AS 'MOO'
. . .
>>EVALUATE TRUE
>>WHEN VAR2 IS DEFINED
       compute x = x + 1 *> this code should NOT be included
>>WHEN VAR1 IS EQUAL TO 'GOO' OR VAR1 IS EQUAL TO 'MOO'
       compute x = x – 1 *> this code should be included
>>END-EVALUATE

Example 5: use OVERRIDE and OFF in the DEFINE directive

>>DEFINE VAR AS 12
. . .
>>DEFINE VAR OFF
. . .
>>IF VAR IS DEFINED
     compute x = x + 1 *> this code should NOT be included
>>ELSE
     compute x = x - 1 *> this code should be included
>>END-IF
. . .
>>DEFINE VAR AS 16
. . .
>>DEFINE VAR AS VAR - 2 OVERRIDE
. . .
>>IF VAR IS EQUAL TO 16
     compute x = x + 1 *> this code should NOT be included
>>ELSE
     compute x = x - 1 *> this code should be included
>>END-IF

Example 6: general use of boolean literals and compilation variables

>>DEFINE B1 B'1' *> B1 is category boolean
>>DEFINE B2 B'0' *> B2 is category boolean
. . .
>>IF B1 AND B2
     display “Both B1 and B2 are true” *> not included
>>ELSE
  >>IF B1
       display “Only B1 is true” *> included
  >>ELSE
    >>IF B2
         display “Only B2 is true” *> not included
    >>ELSE
         display “Neither B1 nor B2 is true” *> not included
    >>END-IF
  >>END-IF
>>END-IF