Search code examples
mainframejcl

JCL : IF Statement with SET Statement


I have set FLAG as 1 and I am execpting ARG value should be DEV only. But am getting as ARG= DEV + CLIENTID

000023 //         FLAG=1

000026 // IF (&FLAG=1) THEN        
000027 //SET1     SET ARG=DEV         
000028 // ELSE        
000029 //SET2     SET ARG=DEV+&CLIENT 
000030 // ENDIF                       

It mean JCL assign the value in RUNTIME (before checking the IF Condition).

Please help me to understand.

Thanks! Bharathi


Solution

  • What @hogstrom said is correct. The JCL IF statement tests Step Return codes and not Variable values:

    //IFBAD     IF  (ABEND | STEP1.RC > 8) THEN
    

    Following on from what he said you can use a variable in an include statement

    Include With variable

    //  INCLUDE MEMBER=OPT&FLAG
    

    and setup members in the proclib

    MEMBER=OPT1

      // SET ARG=DEV 
    

    MEMBER=OPT2

      // SET ARG=DEV+&CLIENT 
    

    You have to setup an include for every possible value of &FLAG and it is very long winded for one SET. It is more commonly used when you can set lots of variables like:

    // INCLUDE MEMBER=ENV&ENV
    

    where &ENV=PROD \ TEST etc

    Your case

    Do not use flag, just set the variable:

    // SET ARG=DEV
    

    or

    // SET ARG=DEV+&CLIENT