---
title: "COBOL SEARCH: How to Use IF Logic Explained"
description: "Simple COBOL search example useful to use in your projects."
url: https://srinimf.com/2018/05/25/cobol-real-time-example-to-write-if-logic-in-search-statement/
date: 2018-05-25
modified: 2020-10-08
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2018/05/pexels-photo-4087569.jpeg?fit=1880%2C1253&ssl=1
categories: ["COBOL"]
tags: ["COBOL Search Example", "COBOL Tips and Tricks", "IF condition in COBOL Search"]
type: post
lang: en
---

# COBOL SEARCH: How to Use IF Logic Explained

In COBOL, we call an internal table as Array. This post explains how to use an IF condition in the Search statement. Here are the [differences between SEARCH and SEARCH ALL](https://srinimf.com/2015/10/02/cobol-search-and-search-all-differences/).

In WHEN condition, you can give =, > and <.

---

![COBOL Search Logic](https://i0.wp.com/srinimf.com/wp-content/uploads/2018/05/cobol.jpg?resize=587%2C391&ssl=1)*COBOL SEARCH IF Condition*

> TIP: SEARCH in COBOL is serial search. So sorting of internal table is not required

## You can use IF condition to filter input fields along with SEARCH. The below sample code shows how to give IF condition:

```
SET IX TO 1.
SEARCH TABLE-ENTRY
AT END
   MOVE 1 TO ORG-SUB
   WHEN ORD-RECIPIENT = TABLE-CODE (IX)
        SET ORG-SUB        TO IX.
        MOVE ORD_CITY (IX) TO WS_CITY
        IF WS_CITY = '840'
           MOVE 'USA'      TO INP_REC (1:3)
        END-IF
END-SEARCH
```

Type your email…

Subscribe

**Also read**

- [Best Example for COBOL SEARCH and WHEN Condition](https://srinimf.com/2016/01/06/best-example-for-cobol-search-and-when-condition/)DateJanuary 6, 2016
- [5 COBOL Frequently Asked Interview Questions](https://srinimf.com/2014/08/07/5-best-cobol-questions-and-solutions/)DateAugust 7, 2014
- [5 Top Limitations of COBOL SEARCH ALL](https://srinimf.com/2016/01/07/5-top-limitations-of-cobol-search-all/)DateJanuary 7, 2016

### 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%2F2018%2F05%2F25%2Fcobol-real-time-example-to-write-if-logic-in-search-statement%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2018%2F05%2Fpexels-photo-4087569.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=COBOL%20SEARCH%3A%20How%20to%20Use%20IF%20Logic%20Explained)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2018/05/25/cobol-real-time-example-to-write-if-logic-in-search-statement/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2018/05/25/cobol-real-time-example-to-write-if-logic-in-search-statement/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2018/05/25/cobol-real-time-example-to-write-if-logic-in-search-statement/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2018/05/25/cobol-real-time-example-to-write-if-logic-in-search-statement/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20COBOL%20SEARCH%3A%20How%20to%20Use%20IF%20Logic%20Explained&body=https%3A%2F%2Fsrinimf.com%2F2018%2F05%2F25%2Fcobol-real-time-example-to-write-if-logic-in-search-statement%2F&share=email)
-

### Like this:

Like Loading…
