READ ASCENDING/ DESCENDING

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?

No, it doesn’t make a difference.

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

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

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?

Is is possible:

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

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

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

If you want KKK, start the READ at KKK :wink:

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.

Ralph and All,

Thanks for responses.

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