Search code examples
searchcobol

Search and Search All in COBOL


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 ?


Solution

  • 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.