# READ ASCENDING/ DESCENDING

**URL:** <https://techcommunity.softwareag.com/t/read-ascending-descending/57984>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-on-Mainframes, Adabas-Basics-on-Mainframes\
**Created:** [May 2, 2006, 3:01am UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984 "2006-05-02T03:01:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vallish](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vallish](https://techcommunity.softwareag.com/u/Vallish)\
**Post date:** [May 2, 2006, 3:01am UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/1 "2006-05-02T03:01:10Z")

</div>

I have tried the query of READ a file by ASCENDING and DESCENDING order.

For ex: File CLASS-NAME contains the columns as shown with NAME being a descriptor,  
Roll No. Name  
1 AAA  
2 CCC  
3 BBB  
4 KKK

READ CLASS-NAME BY NAME = ‘CCC’ ASCENDING returns:

CCC  
KKK

READ CLASS-NAME BY NAME = ‘CCC’ DESCENDING returns

CCC  
BBB  
AAA

1. What is the performance implication of having a DESCENDING parameter for a read? Does it make any difference at all?
2. Can ADABAS return the result set of a query in DESCENDING order?

---

<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:** [May 2, 2006, 8:10pm UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/2 "2006-05-02T20:10:22Z")

</div>

> [@Vallish](#):
>
> 1. What is the performance implication of having a DESCENDING parameter for a read? Does it make any difference at all?

No, it doesn’t make a difference.

> [@Vallish](#):
>
> 1. Can ADABAS return the result set of a query in DESCENDING order?

What “result set” ? Are you still talking about a READ, which doesn’t create a result set, or a FIND ?  
If the latter, you will have to use

```auto
FIND <viewname> SORTED BY <descriptor(s)> DESCENDING
```

---

<div class="post-metadata">

**Author:** ![Vallish](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vallish](https://techcommunity.softwareag.com/u/Vallish)\
**Post date:** [May 3, 2006, 10:16am UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/3 "2006-05-03T10:16:12Z")

</div>

> [@](#):
>
> What “result set” ? Are you still talking about a READ, which doesn’t create a result set, or a FIND ?

By result set, I meant, why cannot Adabas return the result from a read statement in the order of descending or ascending

For ex:  
READ CLASS-NAME BY NAME = ‘CCC’ DESCENDING returns

CCC  
BBB  
AAA

Instead, why can it not return,  
KKK  
CCC

May be its a stupid question, knowing well that adabas is not relational db. But still, why is it not possible?

Secondly, your answer to my question as quoted above, hints that Find creates a result set - what do you mean by this result set? How does it get created?

---

<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:** [May 3, 2006, 12:58pm UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/4 "2006-05-03T12:58:25Z")

</div>

> [@Vallish](#):
>
> May be its a stupid question, knowing well that adabas is not relational db. But still, why is it not possible?

Is is possible:

```auto
READ CLASS-NAME BY NAME = 'ZZZ' DESCENDING 
ENDING AT 'CCC'
```

> [@Vallish](#):
>
> Secondly, your answer to my question as quoted above, hints that Find creates a result set - what do you mean by this result set? How does it get created?

A short answer: Find creates a list of ISNs and stores it automatically in the WORK-area of ADABAS. The programmer is able to sort that ISN-List or make set operations with it.  
Read is not that flexible, because it doesn’t create an ISN list. But therefore it’s better for mass data operations. For example: If you have to access all records of a file without a special sorting, it would be stupid to create a ISN-list of all records.

For more information please see the “Natural Programming Guide \> Accessing Data in a Database \> Accessing Data in an Adabas Database \> Statements for Database Access”  
There you can read more things about READ, FIND and HISTOGRAM

A rule of thumb is:  
READ is for mass data operations  
FIND is good for finding and sorting less records

---

<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:** [May 3, 2006, 1:19pm UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/5 "2006-05-03T13:19:40Z")

</div>

> [@Vallish](#):
>
> For ex:  
> READ CLASS-NAME BY NAME = ‘CCC’ DESCENDING returns
> 
> CCC  
> BBB  
> AAA
> 
> Instead, why can it not return,  
> KKK  
> CCC

Why should it return KKK when you explicitely ask for records with CCC and lower ???

If you want KKK, start the READ at KKK 😉

---

<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 3, 2006, 9:14pm UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/6 "2006-05-03T21:14:33Z")

</div>

Vallish,

READ does not process a set.

The “=” is a synonym for the keyword FROM, and specifies a starting position within the index.

The ASCENDING and DESCENDING keywords are applied after positioning within the index, not after a set is created.

The meaning of

READ CLASS-NAME BY NAME = ‘CCC’ DESCENDING

is to position to the value CCC within the NAME index and read in descending sequence (i.e. from CCC to AAA). It does not mean “read from CCC to ZZZ and display in descending sequence.”

FIND does process a set. Operations, such as sorting and adding selection criteria, may be applied to an existing set.

---

<div class="post-metadata">

**Author:** ![Vallish](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vallish](https://techcommunity.softwareag.com/u/Vallish)\
**Post date:** [May 3, 2006, 10:37pm UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/7 "2006-05-03T22:37:41Z")

</div>

Ralph and All,

Thanks for responses.

> [@](#):
>
> It does not mean “read from CCC to ZZZ and display in descending sequence.”

I have written code to make use of ASC, DESC in the read statement. Ralph clearly wrote my thoughts. All I was trying to understand is why it is supposed to work this way. I know Adabas does things differently. I was trying to question it and understand.

Cheers  
Vallish

---

<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:38pm UTC](https://techcommunity.softwareag.com/t/read-ascending-descending/57984/8 "2021-04-02T14:38:59Z")

</div>

Closed on April 2, 2021, 2:38pm UTC


