---
title: "JCL IF/ELSE/THEN/ENDIF logic to Use in Job Steps"
description: "JCL how to use IF ELSE and END-IF logic to control execution of job steps"
url: https://srinimf.com/2014/05/07/tips-if-then-else-endif/
date: 2014-05-07
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2014/05/pexels-photo-4353586.jpeg?fit=1880%2C1253&ssl=1
categories: ["Categories"]
tags: ["IF Then in JCL", "JCL tips and Tricks"]
type: post
lang: en
---

# JCL IF/ELSE/THEN/ENDIF logic to Use in Job Steps

Everyone is so familiar with controlling execution of JCL job steps. Two ways we can do it. One is by COND and the other one is by IF/THEN/ELSE/ENDIF.

Related[IF-ELSE-ENDIF JCL top example you need](https://srinimf.com/2013/01/15/jcl-how-to-use-cond-with-if-else-endif/)

## [How to](https://srinimf.com/2017/02/01/the-best-tricky-tip-stored-procedure-if-and-cobol-if/) Control Steps Using IF/ELSE/THEN/ENDIF

We need [to learn](https://srinimf.com/2018/09/13/rpg-programming-language-unique-concepts-to-learn-quickly/) many points here. The following are typical questions you may face in interviews.

Related[JCL Evergreen Interview Question on COND Parameter](https://srinimf.com/2016/02/05/jcl-evergreen-interview-question-on-cond-parameter/)

**Point-1:**

```
//RCTEST IF (STEP1.RC = 10) THEN
//STEP3   EXEC
//IFNOT   ELSE
//        ENDIF
//NEXTSTEP EXEC
```

Here,STEP1 is not executed/abnormally terminated, then, control will not go to** THEN/ELSE**. All the remaining steps will be flushed – in the same construct.

**Point-2:**

```
//RCTEST IF (STEP1.PROCSTEP2.RC = 10)  THEN
//STEP3   EXEC
//IFNOT   ELSE
//        ENDIF
//NEXTSTEP EXEC
```

Here also,STEP1.PROCSTEP2 is not executed/abnormally terminated, then, control will not go to** THEN/ELSE**. All the remaining steps will be flushed – in the same construct.

**Job level evaluation**

If you do not code a stepname, the IF/THEN/ELSE/ENDIF statement construct evaluates the return code, abend condition, or run condition of every previous step in the job. If the condition (return code, abend condition, or run condition) is satisfied based on the steps in the job that have executed thus far, the system executes the THEN clause.

Advertisements

**Step level evaluation**

To test a single step, code the **stepname** of the step you want to test. To test a procedure step, code the **stepname.procstepname** of the procedure step you want to test. If the step or procedure step that you are evaluating did not execute, was cancelled or ended abnormally, the result of the evaluation is false.

**USAGE**

Related[PLI Boolean Operators – Real Purpose](https://srinimf.com/2016/03/09/how-to-interprete-zos-pli-boolean-values/)

Usually, if any step abends, the following steps automatically will be flushed. But with IF/THEN/ELSE/ENDIF – we can continue execution.

- //RCTEST IF (ABEND)  THEN
- //RCTEST IF (ABEND=TRUE)  THEN

[Additional Errors during re-start.](http://pic.dhe.ibm.com/infocenter/zos/v1r11/index.jsp?topic=/com.ibm.zos.r11.ieab600/iea2b690635.htm)

Related[Mainframe Rexx for Beginners (1 of 3)](https://srinimf.com/2012/05/13/rexx-beginers-for-mainframe-1of-3/)

******What we should/should not in THEN/ELSE:**

Do** not place :**

- JOB statement
- JCLLIB statement
- JOBLIB statement
- SYSCHK (job level) statement
- XMIT JCL statement

The system processes the following statements regardless of the logic of the IF/THEN/ELSE/ENDIF statement construct. They can be placed in a THEN or ELSE clause, but they are not executed conditionally.

- PROC and PEND statements
- JES2 and JES3 statements and commands
- JCL command statements
- Comment (//*) statements
- INCLUDE statements
- Delimiter (/*) statements
- Null statements
- SET statements

Related Posts

- [IF-ELSE-ENDIF JCL top example you need](https://srinimf.com/2013/01/15/jcl-how-to-use-cond-with-if-else-endif/)DateJanuary 15, 2013
- [JCL Evergreen Interview Question on COND Parameter](https://srinimf.com/2016/02/05/jcl-evergreen-interview-question-on-cond-parameter/)DateFebruary 5, 2016
- [JCL COND – How to Control Execution of Job Steps Best Example](https://srinimf.com/2015/12/02/3-quick-tips-mastering-cond-parameter-usage-in-job-and-step/)DateDecember 2, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2014%2F05%2F07%2Ftips-if-then-else-endif%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2014%2F05%2Fpexels-photo-4353586.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=JCL%20IF%2FELSE%2FTHEN%2FENDIF%20logic%20to%20Use%20in%20Job%20Steps)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2014/05/07/tips-if-then-else-endif/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2014/05/07/tips-if-then-else-endif/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2014/05/07/tips-if-then-else-endif/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2014/05/07/tips-if-then-else-endif/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20JCL%20IF%2FELSE%2FTHEN%2FENDIF%20logic%20to%20Use%20in%20Job%20Steps&body=https%3A%2F%2Fsrinimf.com%2F2014%2F05%2F07%2Ftips-if-then-else-endif%2F&share=email)
-

### Like this:

Like Loading…
