View previous topic :: View next topic |
Author |
Message |
Saty Beginner
Joined: 22 Jul 2004 Posts: 1 Topics: 1
|
Posted: Thu Jul 22, 2004 2:52 am Post subject: SEARCH & SEARCH ALL statement in COBOL |
|
|
SEARCH ALL performs binary search whereas SEARCH performs a linear search in tables. SEARCH ALL is therefore more efficient than SEARCH esp for long tables.
However, the linear search performed by SEARCH can also be accomplished by browsing through an array by varying the subscript. Is the use of SEARCH more efficient than browsing through an array? Is so, why ecaxtly is it more efficient? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Jul 22, 2004 4:19 am Post subject: |
|
|
saty,
Performance wise there is no difference between COBOL linear search and PERFORM UNTIL. When excueted both of them perform alike.
On the other hand there is a difference between a linear search(SEARCH) and binary search (SEARCH ALL).
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
dhruv Beginner
Joined: 01 Jun 2004 Posts: 10 Topics: 1
|
Posted: Thu Jul 22, 2004 4:30 am Post subject: |
|
|
The following need to considered when deciding between a linear SEARCH vs PERFORM
SEARCH uses index Specified in the INDEXED BY CLAUSE.
Also, linear SEARCH on a table using a OCCURS DEPENDING ON clause, can come out of the search faster. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Jul 22, 2004 4:32 am Post subject: |
|
|
Quote: |
Also, linear SEARCH on a table using a OCCURS DEPENDING ON clause, can come out of the search faster.
|
Dhruv,
Can you elaborate more on the above statement?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
dhruv Beginner
Joined: 01 Jun 2004 Posts: 10 Topics: 1
|
Posted: Thu Jul 22, 2004 4:37 am Post subject: |
|
|
Lets say you a table with 100 elements.
But only the first 30 elements have been populated. IF the ODOvariable is 30, then the SEARCH will come out after scanning through the first 30 elements, rather than searcing all 100 elements.
Hope its clear
Thanks |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Jul 22, 2004 4:40 am Post subject: |
|
|
Quote: |
But only the first 30 elements have been populated. IF the ODOvariable is 30, then the SEARCH will come out after scanning through the first 30 elements, rather than searcing all 100 elements.
|
Dhruv,
Doesn't this hold good for PERFORM VARYING also?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
dhruv Beginner
Joined: 01 Jun 2004 Posts: 10 Topics: 1
|
Posted: Thu Jul 22, 2004 4:48 am Post subject: |
|
|
If you use a limiting factor (equivalent of the ODO) in the PERFORM VARYING statement, in conjunction with an indexed variable(not a working storage variable), then i suppose the PERFORM VARYING might come close to the SEARCH performance wise, although, even for big tables, there is very little difference to chose from the 2.
Thanks |
|
Back to top |
|
|
|
|