---
title: "IF THEN in JCL Sort Card to Format Records"
description: "IF THEN in JCL to format records using DFSORT utility"
url: https://srinimf.com/2015/04/01/jcl-sort-example-for-ifthen/
date: 2015-04-01
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/04/pexels-photo-1046639.jpeg?fit=1880%2C1253&ssl=1
categories: ["DFSORT"]
tags: ["DFSORT tips and Tricks", "IF Then in JCL"]
type: post
lang: en
---

# IF THEN in JCL Sort Card to Format Records

**The below example says [how to](https://srinimf.com/2012/03/12/cobol-release-and-return-in-sort/) use IFTHEN in [JCL sort card](https://srinimf.com/2012/02/03/jcl-sort-card-bi-to-zd/). IFTHEN will be used to reformat either INREC or OUTREC.**

Using IFTHEN clauses, you reformat different records in different ways by specifying how BUILD or OVERLAY items are applied to records that meet given criteria.

## How to Use IF THEN

IFTHEN clauses let you use sophisticated conditional logic to choose how different record types are reformatted. You can use any INCLUDE logical expression to specify the criteria. You can use any BUILD or OVERLAY items to reformat the records that
meet those criteria.

Related[Include COND: Matching TimeStamp Example](https://srinimf.com/2016/06/21/include-cond-matching-records-with-timestamp/)

[![Dfsort examples](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/10/dfsort-examples.png?resize=385%2C47&ssl=1)](https://srinimf.com/e-books/#dfsort-best-examples)

You can also apply BUILD or OVERLAY items to all records, or only to records that do

not meet any of the criteria.

### Here’s an example of reformatting with INREC and IFTHEN clauses:

```
INREC IFTHEN=(WHEN=INIT,OVERLAY=(73:SEQNUM,8,ZD)),IFTHEN=(WHEN=(4,5,CH,EQ,C&apos;TYPE1&apos;),BUILD=(1,4,61:C&apos;1&apos;,73:73,8)),IFTHEN=(WHEN=(4,5,CH,EQ,C&apos;TYPE2&apos;),BUILD=(1,3,61:C&apos;2&apos;,73:73,8)),IFTHEN=(WHEN=NONE,BUILD=(1,5,61:C&apos;&apos;,73:73,8))
```

One of the interview question is, IFTHEN is used  for conditional logic.

Related[Cobol-Date Function (2of 2)](https://srinimf.com/2011/12/04/cobol-date-2/)

### 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%2F2015%2F04%2F01%2Fjcl-sort-example-for-ifthen%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F04%2Fpexels-photo-1046639.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=IF%20THEN%20in%20JCL%20Sort%20Card%20to%20Format%20Records)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/04/01/jcl-sort-example-for-ifthen/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/04/01/jcl-sort-example-for-ifthen/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/04/01/jcl-sort-example-for-ifthen/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/04/01/jcl-sort-example-for-ifthen/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20IF%20THEN%20in%20JCL%20Sort%20Card%20to%20Format%20Records&body=https%3A%2F%2Fsrinimf.com%2F2015%2F04%2F01%2Fjcl-sort-example-for-ifthen%2F&share=email)
-

### Like this:

Like Loading…
