Search and Search All in COBOL Table
Search
- Search is a linear search method. It finds the elements inside the table.
- It performs on both sorted and unsorted table.
- Search is applicable only for the tables stated by an index phrase.
- Searching starts with the initial value of the index.
- An index is automatically incremented by 1, if the searched element is not found then search is carried out till the end of the table.
Syntax:
SEARCH tableName [VARYING {identifier#indexName}]
[AT END StatementBlock]
{ WHEN Condition {Statementblock NEXT SENTENCES}}...
END-SEARCH
Search All
- Search All is a binary search method.
- It finds the element inside the table. A table should be in sorted order, otherwise SEARCH ALL will not work properly.
- The index does not need starting value.
- The table is divided into two parts in binary search and it determines that in which half the searched element is present. This process is repeated until the element is found.