Search and search all in cobol program
The subscript is a traditional field under the control of the programmer. The index is limited in use. Essentially a programmer has far more control over the manipulation of a subscript than an index. Because the index is used with the SEARCH verb, the restrictions are defined to maximize its effective use in that context. A linear search checks the field we need to match against each element in the table to see if they match.
Binary Search is on a sorted array. Compare the item to be searched with the item at the center. If it matches, it stops the search else repeat the process with the left half or the right half depending on where the item lies. Based on this decision, we have eliminated half the table from the search.
Whether it selected first half or second half, it again select the middle element in that part and continue this process until either element is found or there are no elements to search.
Step 2: Find middle element. In this group we have 7 elements. So, in our array, middle element is 8. Search found the element. Search all stops the search here. When the Table entries are arranged in sequence by some field, such as EMP-ID, the most efficient type of lookup is a binary search. If array is small then go for search. The condition following the word WHEN can only test for equality.
0コメント