Previous Topic: In-Stream DataNext Topic: The RC Expression


Controlling Processor Flow Using the IF-THEN-ELSE Statement

The CA Endevor SCM IF-THEN-ELSE JCL statement provides control of the order SCL statements are processed. The IF-THEN-ELSE statement is derived from the IBM OS JCL statement and provides the following functionality:

At run time, the IF-THEN-ELSE statement is evaluated and then the appropriate statements are selected for inclusion. Consequently, the processor JCL can be customized at each run without causing intervening modifications to the processor.

The CA Endevor SCM IF-THEN-ELSE statement is similar to the COND and EXECIF keywords function. However, the IF-THEN-ELSE statement provides the following advantages over the COND and EXECIF keywords:

COND and EXECIF keywords must be coded on each applicable EXEC statement.

CA Endevor SCM allows selection of steps and DD statements using not only condition codes from prior steps but also values of CA Endevor SCM symbols and processor symbols. This allows the customer more control of the processor execution.

The basic syntax of IF-THEN-ELSE follows the syntax of most JCL statements, but also has some idiosyncrasies. Columns 1 and 2 must contain slashes "//". An optional name may be placed in Column 3, can be up to eight characters long, and must be followed by a blank.

Note: It is highly recommended you specify a name. This helps in the debugging process if unexpected results occur.

The IF statement must be present followed by a conditional statement and is concluded with the THEN statement. The conditional statement may be enclosed in parentheses to indicate nesting. An ELSE statement is coded similarly to the IF statement excluding the conditional statement. The IF block is completed by the ENDIF.

Syntax example

//TEST1      IF keyword operator value THEN
//
.
.
.
statements 
//ELSE1    ELSE
//
.
.
.
statements
//ENDIF1 ENDIF

keyword

Valid keywords are:

operator

Valid operators are:

Note: For more information about these operators, see The EXECIF Keyword.

value

Values are:

statements

Represents any valid JCL statements inserted between the IF-THEN-ELSE statements.

These statements can be EXEC or DD statements.

The entire statement must be coded within the IF-THEN-ELSE structure. If a JCL statement is continued on multiple lines, it must be completed before an intervening IF-THEN-ELSE is encountered.

Example: IF-THEN-ELSE Statement (example 1)

This example is valid.

//* Valid example
//IF    IF   (&STAGE=PRD) THEN
//DD1   DD   DISP=(,CATLG),UNIT=SYSDA,
//      VOL=SER=VOLUME,DSN=ABC.DEF
//      ENDIF

The following example is not valid.

//* Invalid example
//IF   IF  (&STAGE=PRD) THEN
//DD1  DD  DISP=(,CATLG),UNIT=SYSDA,
//     ENDIF
//     VOL=SER=VOLUME,DSN=ABC.DEF

Example: IF-THEN-ELSE Statement (example 2)

This example is valid.

//* Valid example
//SYSABEND   DD DUMMY                                                      
//           IF (&CDEBUGD='D') THEN                                        
//SYSLIB     DD DSN=ABC.DEF1,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=BCD.DEF2,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=CDE.DEF3,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=IJK.DEFADD,DISP=SHR,MONITOR=COMPONENTS                 
//           ELSE                                                          
//SYSLIB     DD DSN=EFG.DEF4,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=FGH.DEF5,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=HGI.DEF6,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=IJK.DEFADD,DISP=SHR,MONITOR=COMPONENTS                 
//           ENDIF                                                         

The following example is not valid.

//*Invalid example                                                         
//SYSABEND   DD DUMMY                                                      
//           IF (&CDEBUGD='D') THEN                                        
//SYSLIB     DD DSN=ABC.DEF1,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=BCD.DEF2,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=CDE.DEF3,DISP=SHR,MONITOR=COMPONENTS                   
//           ELSE                                                          
//SYSLIB     DD DSN=EFG.DEF4,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=FGH.DEF5,DISP=SHR,MONITOR=COMPONENTS                   
//           DD DSN=HGI.DEF6,DISP=SHR,MONITOR=COMPONENTS                   
//           ENDIF                                                         
//           DD DSN=IJK.DEFADD,DISP=SHR,MONITOR=COMPONENTS  

An IF clause may be coded at three points in the processor JCL:

  1. Prior to EXEC statements and all of their associated DD statements.

    The IF clause is coded here when a test is to be made to determine if one or more complete steps within an IF-THEN-ELSE block are to be either included or excluded from the processor execution.

    //STEP1 EXEC PGM=COBOL1
    //  IF (STEP1.RC=0)
    //    THEN
    //STEP2 EXEC PGM=LINK
    //DD1   DD DISP=SHR,DSN=INPUT
    //DD2   DD DISP=SHR,DSN=OUTPUT
    //STEP3 EXEC PGM=PRINT
    //DD1   DD DISP=SHR,DSN=INPUT
    //DD2   DD DISP=SHR,DSN=OUTPUT
    //    ELSE
    //STEP4 EXEC PGM=PRINT
    //DD1   DD DISP=SHR,DSN=INPUT
    //DD2   DD DISP=SHR,DSN=OUTPUT
    //    ENDIF
    //STEP5 EXEC PGM=COPY
    

    If the return code of STEP1 is equal to 0, STEP2 and STEP3 are executed. STEP4 is not executed.

  2. Prior to DD statements and any DD statements that are concatenated to them.

    The IF clause is coded here when a test is to be made to determine if one or more complete DD statements within an IF-THEN-ELSE block are to be either included or excluded from the processor step definition.

    //STEP1 EXEC PGM=COBOL1
    //STEP2 EXEC PGM=LINK
    //DD1   DD   DISP=SHR,DSN=INPUT1
    //  IF (&STAGE=PRD).
    //    THEN
    //DD2   DD   DISP=SHR,DSN=INPUT2
    //DD3   DD   DISP=SHR,DSN=INPUT3
    //    ELSE
    //DD4   DD   DISP=SHR,DSN=INPUT4
    //    ENDIF
    //STEP3 EXEC PGM=PRINT
    

    If &STAGE is equal to PRD when STEP2 is executed, then DD1, DD2, and DD3 are included in the step definition. DD4 is not included in the step definition.

  3. Prior to a DD statement that is part of a DD concatenation.

    The IF clause is coded here when a test is to be made to determine if one or more statements that are part of a DD concatenation and within an ITE (IF-THEN-ELSE) block are to be either included or excluded from the processor step definition.

    //STEP1 EXEC PGM=COBOL1
    //STEP2 EXEC PGM=LINK
    //DD1   DD  DISP=SHR,DSN=INPUT1
    // IF (&STAGE=PRD).
    //   THEN
    //      DD  DISP=SHR,DSN=INPUT2
    //      DD  DISP=SHR,DSN=INPUT3
    //   ELSE
    //      DD  DISP=SHR,DSN=INPUT4
    //   ENDIF
    //DD2   DD  DISP=SHR,DSN=INPUT5
    //DD3   DD  DISP=SHR,DSN=INPUT6
    //STEP3 EXEC PGM=PRINT
    

    If &STAGE is equal to PRD when STEP2 is executed, datasets INPUT1, INPUT2, INPUT3 are included in the dataset concatenation defined by DD1. The INPUT4 dataset is not included.

    An IF-THEN-ELSE IF specification may extend over multiple statements. The specification must be within columns 1 - 71 of each statement. Column 72 may contain an X to indicate a continuation of the line, but it is not mandatory.

Example (An IF statement extending over multiple statements, without an 'X' in column 72)

CC                                                    CC
1                                                     72
//TESTIF    IF  ((&STG. EQ PRD1) OR (&STG. EQ PRD2)
//          OR   (&STG. EQ PRD3) OR (&STG. EQ PRD4)
//          OR   (&STG. EQ PRD5)) THEN

Example (An IF statement extending over multiple statements, with an 'X' in column 72)

CC                                                    CC
1                                                     72
//TESTIF   IF   ((&STG. EQ PRD1)                      X
//         OR   (&STG. EQ PRD2)                       X
//         OR   (&STG. EQ PRD3)                       X
//         OR   (&STG. EQ PRD4)                       X
//         OR (&STG. EQ PRD5)) THEN

The THEN clause may be on the same statement as the preceding IF definition or it can be specified on a subsequent statement. All text to the right of the THEN clause is treated as comments.

Example (THEN clause on the same line as the IF statement)

//TESTIF  IF (&STG. EQ PRD) THEN   COMMENTS
//STEP1   EXEC PGM=COBOL1
//TESTIF           ELSE
//STEP2   EXEC PGM=COBOL2
//TESTIF  ENDIF

Example (THEN clause on a separate line from the IF statement)

//TESTIF  IF (&STG. EQ PRD)
//             THEN  COMMENTS
//STEP1   EXEC PGM=COBOL1
//TESTIF       ELSE
//STEP2   EXEC PGM=COBOL2
//TESTIF  ENDIF

Stacking IF-THEN-ELSE specifications on the same statement is not acceptable.

//T1    IF(&SYS. EQ ACC)THEN IF(&SUB. EQ REC)THEN
//STEP  EXEC PGM=COBOL1
//      ELSE
//STEP  EXEC PGM=COBOL2
//      ENDIF
//      ELSE
//STEP  EXEC PGM=COBOL3
//      ENDIF

The syntax in this IF-THEN-ELSE definition is rejected at translation time because anything on the first statement following the THEN clause is treated as a comment.

IF-THEN-ELSE specifications can be nested, however. The above could have been coded in the following manner.

//T1    IF(&SYS. EQ ACC)
//      THEN
//T2    IF(&SUB. EQ REC)
//      THEN
//STEP  EXEC PGM=COBOL1
//T2    ELSE
//STEP  EXEC PGM=COBOL2
//T2    ENDIF
//T1    ELSE
//STEP  EXEC PGM=COBOL3
//T1    ENDIF

Example (nested IF-THEN-ELSE statement)

DD statements related to an EXEC must be included within the IF-THEN-ELSE block for that step. CA Endevor SCM has no way of knowing that DD statements following an EXEC statement belong to a prior statement. In short, the step must be complete as if IF-THEN-ELSE were not coded. As an example, this processor is invalid:

//IF     IF     (&COBOL='1'). THEN
//STEP1  EXEC  PGM=COBOL1
//       ELSE
//STEP1  EXEC  PGM=COBOL2
//       ENDIF
//SYSIN  DD   DISP=SHR,DSN=INPUT.SOURCE
//SYSLIN DD  DISP=SHR,DSN=OBJECT.OUTPUT
//...

It is desirable to associate the DD statements with program COBOL1 or program COBOL2. However, in this case the DD statements are only associated with program COBOL2. If the IF-THEN-ELSE statements are removed, the DDs are allocated to the COBOL2 program. Internally, DD statements are associated with the prior exec statement. To associate the DD statements with the first exec statement, they must be duplicated in that step. This example is valid:

//       IF  (&COBOL='1')  THEN
//STEP1  EXEC PGM=COBOL1
//SYSIN  DD  DISP=SHR,DSN=INPUT.SOURCE
//SYSLIN DD  DISP=SHR,DSN=OBJECT.OUTPUT
//...
//       ELSE
//STEP1  EXEC PGM=COBOL2
//SYSIN  DD  DISP=SHR,DSN=INPUT.SOURCE
//SYSLIN DD  DISP=SHR,DSN=OBJECT.OUTPUT
//...
//       ENDIF 

The relational expression of the IF statement tests six IBM-defined possible expressions and the CA Endevor SCM symbolic variables and literals. The six IBM expressions are: