# READ statement problem

**URL:** <https://techcommunity.softwareag.com/t/read-statement-problem/61041>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [May 28, 2006, 10:01pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041 "2006-05-28T22:01:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikko](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mikko](https://techcommunity.softwareag.com/u/Mikko)\
**Post date:** [May 28, 2006, 10:01pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041/1 "2006-05-28T22:01:15Z")

</div>

I need to use a READ statement but need to use “OR” and WHERE clauses but doesnt work. Im using FIND now but our DBA suggests to use READ…example

FIND FILE-1 with DESCRIPTOR-DATE1 = #start-date thru #end-date OR  
DESCRIPTOR-DATE2 = #start-date thru #end-date  
WHERE Indicator = “C”  
…  
END-FIND

But when i use READ instead of FIND…i encounter an error. Can someone help?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [May 28, 2006, 11:37pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041/2 "2006-05-28T23:37:12Z")

</div>

If your DBA is suggesting a READ, then he should suggest how to code it, too. 😉

FIND returns a set of records based on some logical criteria. READ returns a sequence of records - in your example, by a key, but physical and internal sequences are also possible. FIND syntax allows a combination of descriptors; READ does not.

If your logical condition was an AND, then you could code

```auto
READ FILE-1 BY DESCRIPTOR-DATE1 FROM #start-date THRU #end-date 
         WHERE DESCRIPTOR-DATE2 = #start-date THRU #end-date 
           AND Indicator = "C" 
```

“WHERE DESCRIPTOR-DATE2” limits the records to a subset of DESCRIPTOR-DATE1. Can you  
guarantee that all records with the specified DESCRIPTOR-DATE2 values also contain the  
specified DESCRIPTOR-DATE1 values? With an OR condition, you need a descriptor which  
will return all values specified for both DESCRIPTOR-DATE1 and DESCRIPTOR-DATE2.

Here’s a simpler example.

```auto
FIND file with SURNAME = 'ZBROG' 
            OR FIRSTNM = 'RALPH' 
```

This returns all ZBROGs and all RALPHs.

If you were certain that all RALPHs were ZBROGs, then you could code

```auto
READ file BY SURNAME FROM 'ZBROG' THRU 'ZBROG' 
       WHERE FIRSTNM = 'RALPH' 
```

But if RALPH SMITH exists on the file, the FIND will return this record, but the READ  
will not. You need a descriptor which returns all ZBROGs and all RALPHs, and then you  
can ignore those records which do not satisfy both criteria.

---

<div class="post-metadata">

**Author:** ![Vasanth](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@Vasanth](https://techcommunity.softwareag.com/u/Vasanth)\
**Post date:** [June 6, 2006, 6:41pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041/3 "2006-06-06T18:41:29Z")

</div>

Mikko,

You cannot do what you needed in a single READ  
You may have to use two read statements and store the values in workfile and merge the two files and then use the work file for processing.

READ FILE-1 BY DESCRIPTOR-DATE1 FROM #start-date THRU #end-date  
WRITE WORK 1 #REC  
END-READ

READ FILE-1 BY DESCRIPTOR-DATE2 FROM #start-date THRU #end-date  
WRITE WORK 1 #REC  
END-READ

Regards  
Vasanth

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [June 6, 2006, 8:28pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041/4 "2006-06-06T20:28:04Z")

</div>

Seems like a lot of extra work to write a work file. Why not…

```auto
READ file BY DESCRIPTOR-DATE1 FROM date1 THRU date2
   PERFORM PROCESS-FILE-RECORD
END-READ

READ file BY DISCRIPTOR-DATE2 FROM date3 THRU date4
   PERFORM PROCESS-FILE-RECORD
END-READ
```

–Jerome

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [June 8, 2006, 12:37pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041/5 "2006-06-08T12:37:37Z")

</div>

> [@Jerome LeBlanc](#):
>
> ```auto
> READ file BY DESCRIPTOR-DATE1 FROM date1 THRU date2
> PERFORM PROCESS-FILE-RECORD
> END-READ
> 
> READ file BY DISCRIPTOR-DATE2 FROM date3 THRU date4
> PERFORM PROCESS-FILE-RECORD
> END-READ
> ```

The disadvantage of two READs: If the periods of time are overlapping each other, you will process some records twice…  
The advantage is perhaps: It could be faster and you don’t need space on the Adabas WORK-area.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:40pm UTC](https://techcommunity.softwareag.com/t/read-statement-problem/61041/6 "2021-04-02T14:40:40Z")

</div>


