IF THEN ELSE
Part of the Batch Jobs with JCL section of Coddy's COBOL Programming journey. Lesson 11 of 19.
IF statements choose steps the way a program does, and they read forwards: the steps after THEN run when the test is true.
// IF (CHECK.RC <= 4) THEN
//POST EXEC PGM=POSTTXN
// ELSE
//ALERT EXEC PGM=ALERT
// ENDIFCHECK.RC is the return code of step CHECK. RC alone is the highest code of the steps that ran so far. The tests are =, <, >, <=, >= and ¬=, or EQ, LT, GT, LE, GE, NE.
AND, OR and NOT join tests:
// IF (CHECKA.RC = 0 AND CHECKB.RC = 0) THENThe IF, ELSE and ENDIF lines need no name: leave the name field blank. ELSE is optional.
A step in the branch that does not run is reported as not executed:
IEF272I IFJOB POST - STEP WAS NOT EXECUTED.Challenge
EasyPut POST and ALERT under an IF: POST runs when CHECK ended with 4 or less, and ALERT runs otherwise. Replace each comment with the IF, ELSE or ENDIF line.
Try it yourself
//IFJOB JOB (ACCT),'CODDY',CLASS=A,MSGCLASS=X
//CHECK EXEC PGM=CHKBAL
//CUSTIN DD DSN=CODDY.CUST.FEB,DISP=SHR
//SYSOUT DD SYSOUT=*
//* IF line here
//POST EXEC PGM=POSTTXN
//SYSOUT DD SYSOUT=*
//* ELSE line here
//ALERT EXEC PGM=ALERT
//SYSOUT DD SYSOUT=*
//* ENDIF line here
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Batch Jobs with JCL
Practice on your own: Online COBOL compiler