2
votes

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

2

2 Answers

4
votes

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 
3
votes

There is some good information in the JCL Manual to understand the purpose of the IF/THEN/ELSE purpose.

Here are a few bullets from the manual:

  • The IF/THEN/ELSE/ENDIF statement construct does not conditionally control the processing of JCL; rather, it conditionally controls the
    execution of job steps.
  • The result of processing an IF/THEN/ELSE/ENDIF statement construct, once determined, remains unchanged regardless of the outcome from running any remaining steps in a job. The system does not reexamine the original condition at any later job step termination, either normal or abnormal. See Example 9.
  • The system allocates all DD statements defined to a step if the execution time evaluation of the relational-expression determines
    that a step is to be executed. All data sets defined on DD statements in the job must be available at the time the job is selected for execution.
  • You can nest IF/THEN/ELSE/ENDIF statement constructs up to a maximum of 15 levels. You can specify symbolic parameters on IF/THEN/ELSE/ENDIF statements provided that they resolve to one of the supported relational-expression keywords. Any other symbolic parameters, even if accepted by the system, are not intended or supported.

What your doing seems logical, but, its not the intended purpose of JCL SET and conditional logic.

In your case, the last SET executed is what is used and why your seeing the DEV + CLIENTID