Search and Search All in COBOL

Viewed 364

I want to know the result when we try to search an item in COBOL using SEARCH or SEARCH ALL and this item appears multiple times in the table. Will any of the two will find all the occurrences ?

2 Answers

Will any of the two will find all the occurrences ?

No. Either SEARCH will identify one, and only one, table element.

The SEARCH statement is used to search a table for a table element that satisfies the specified condition and to adjust the value of the associated index to indicate that table element.

For SEARCH, the final value, of the index or identifier, will be the first table element that matches the conditions.

For SEARCH ALL, the final setting of the search index is equal to one of them, but it is undefined which one.

Neither will, but with the search you can set the initial starting index and do a second search to find subsequent entries.

Search

The Search verb does a linear search through the table. Table entries can be in any sequence.

If there are multiple entries the first after the starting index will be found.

You can use the Set index to verb to set the starting position.

Search All

The Search All does a binary search of the Table. The table must be in Key Sequence. If there are multiple match's, any one could be found. For large tables, the Search All will be faster option.

Related