Differences between READ and FIND

I need read file in adabas/database.

When should I use READ or FIND?

The two seem similar.

I realized that the only difference is that the FIND only searches for descriptor.

This is a BIG topic. First, there is no simple answer.

As a general rule, FIND is used to process a small number of records, whereas READ is used for larger groups of records.

For example, I want to process all of the records in a file with DEPT = SALES and LOCATION = NEW YORK. Assume DEPT and LOCATION are both descriptors. Also assume this is a a reasonable sized file (10 million records) and there are 120,000 SALES records and 82,000 NEW YORK records and there are 6,800 records which satisfy both criteria.

Using FIND file WITH DEPT = SALES and LOCATION = NEW YORK

Natural issues what is called a search command to Adabas. This produces a list of 6,800 ISNs, which you would then read and process in your program.

Now, for the READ. assuming there is not a super descriptor which combines DEPT and LOCATION, you would have to either:

READ file IN LOGICAL SEQUENCE BY DEPT STARTING FROM SALES ENDING AT SALES
WHERE LOCATION = NEW YORK

or READ file IN LOGICAL SEQUENCE BY LOCATION STARTING FROM NEW YORK ENDING AT NEW YORK
WHERE DEPT = SALES

The first one reads 120,000 records, the second only 82,000 records.

The FIND would be the choice here. There are lots of other ways to winnow the number of records for searches. This would require learning a lot about how Adabas works, and how Natural interacts with Adabas. I will see what I can find online for you

steve

In help
FIND run with Adabas and SQL/Db.

But in Find “With” options only accept DESCRIPTOR. In SQL/Db “descriptor” is an INDEX ?

True :wink:

Great.

With READ and FIND I can read and provide data

histogram do not have access to data

which then serves to the histogram?

Example:

define data local
01 sag-company view sag-tours-e-company
  02 c-country
end-define
histogram sag-company for c-country
display sag-company *NUMBER
end-histogram
end

output:

SAG-COMPANY    NMBR

C-COUNTRY
---------   -----------

D                     2
DK                    1
E                     2
F                     1
GB                    2
TR                    1
USA                   2

Adabas is very much like a library. A library has books and card catalogues. Adabas’s equivalent of the books is the data files. The equivalent of the card catalogues is called the inverted files (which are part of what is called the associator).

Most libraries (pre computers) would have two card catalogues, one for author and one for subject. If we were to assign Adabas terminology to a library, subject and author would be descriptor fields.

In a library, if I want to find some books by a particular author, I perform two “steps”. First, I go to the card catalogue and look up the author. The result of this step is a list of what are called dewey decimal numbers (DDN) which logically identify books. Then, one at a time I take a DDN and go to a map of the library (or, ask the librarian) to find out where that DDN is physically. Then I go to the book and thumb through it to see if I want to check it out of the library.

Adabas FIND logic is the same two step process. FIND file WITH CITY = ‘NEW YORK’ starts by issuing a call to Adabas to do a search command for CITY = ‘NEW YORK’ . Adabas goes to the inverted tables and looks up CITY = ‘NEW YORK’. The result of this search is a list of Internal Sequence Numbers (ISN). This is then processed, one at a time, by the program, which issues a read to adabas with the next ISN. Adabas has a table called the associator, which functionally is the same as the map on the library wall. It contains the physical address (RABN) of each ISN in the file. In your program, you get to process each record, one at a time.

Note how closely the Natural FIND mimics the library.

Suppose I want to know how many books a library has by all the authors which start with the letter B. There is no reason to look at the books. The card catalogue has all the information I need. I go to the card catalogue and find the first B author, say BARNES. I count the cards in the catalogue and discover there are 7 books by BARNES. I repeat this for all the authors whose name starts with B. I NEVER go to the books, the card catalogue has all the information I need.

Similarly, if I want to find counts for all the cities in my file, I would do a HISTOGRAM file CITY. Natural would call Adabas, which would go to the inverted tables to find the first city, say AKRON, and a count of the number of records for AKRON. This information would be passed back to my program. NO records would be read. This process wopuld be repeated for all the cities that exist on the file.

I have some things I have to do. Will continue the analogy later for READ.

steve

Similarly, the Natural HISTOGRAM statement issues

1 Like

Thanks por all.

Could someone explain to me how the natural adabas retrieves the records on the following ?? situation:
I am reading a file for a super-descriptor that has multiple entries for this super.
When I read the adabas trough of a read command by sp eq ‘xxxxx’
how will I receive the records that have the entire information super duplicate?
My question is: Are you as sure in successive readings of the same file by this super, the records always come back in the same isn order?? in the case of records with the same super?

How the natural - adabas retrieve records form his inverter lists in repeated values of the same entry ?

Thanks!

When multiple records have the same key value (descriptor, subdescriptor, superdescriptor), they are returned in ISN sequence. You may rely on this. It is true for READ and FIND.

Thanks Ralph. This was exactly what I was needing.

Hi,

can some one explain exactly how Read by Logical and Find works inside Adabas. I know Read logical reads values of descriptor and gets ISN from inverted list and using ISN gets RABN from Address converter and reads Data storage to get data. But in case of FIND how this operation differs, I believe find also does the same. Can you please help to understand internal processing logic in FIND process.

Thanks,
S.Saravanan.

Simplified / short version:

  • FIND creates an intermediate result set (a list of ISNs) which is then traversed
  • READ just walks the inverted list and picks ISNs one by one.