View previous topic :: View next topic
|
Author |
Message |
peyush
New User
Joined: 29 Sep 2008 Posts: 6 Location: United Kingdom
|
|
|
|
Hi,
I have a query related to sequential search in COBOL.
What would be the position on index when a sequential search is not successful.
Is it the last position ?
n+1 where n is the last position where data in stored in a table
or n.
Ex - A table with OCCURS 10 INDEXED BY I.
Suppose there is data in 5 positions.
If search is not successful the position of index is 10,6,5. I read somewhere that it is unpredictable.
Please help. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The COBOL Language Reference (manuals link at the top of the page), section 6.2.32.1 on sequential SEARCH, is quite clear:
Quote: |
If the end of the table is reached (that is, the value of the incremented index is greater than the highest possible occurrence number) without the WHEN condition being satisfied, the search is terminated. |
In other words, the value will be 11 for your example.
Please note that the actual number of elements you've loaded into the table has no bearing upon the SEARCH verb. Only the defined number of elements (10 in your example) matters -- the fact that you've loaded only 5 elements means that you're comparing unknown values for the last 5 search tests (possibly LOW-VALUES, possibly something else).
If a BINARY search fails, the index value will be unpredictable. However, if a SEQUENTIAL search fails the index value is known. |
|
Back to top |
|
|
peyush
New User
Joined: 29 Sep 2008 Posts: 6 Location: United Kingdom
|
|
|
|
Thanks for the response. |
|
Back to top |
|
|
|