COBOL - SEARCH Statement Introduction
The SEARCH statement searches a table for an element that satisfies the specified condition and adjusts the associated index to indicate that element.
There are two SEARCH format,
- SEARCH statement for serial search.
- SEARCH ALL statement for binary search.
When to use SEARCH and SEARCH ALL
- Use format 1 (serial search) when the table that you want to search has not been sorted. Use format 1 to search a sorted table when you want to search serially through the table or you want to control subscripts or indexes. Also, For a table with less than 50 entries, go for SEARCH.
- Use format 2 (binary search) when you want to efficiently search across all occurrences in a table. The table must previously have been sorted. Also, For a table with more than 50 entries go for SEARCH ALL.
To use SEARCH/SEARCH ALL, table should have an index. To use SEARCH ALL the table should be in a sorted order.
We will see each format in next chapter..
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!