Difference Between Search and Search All in COBOL
Last Updated :
09 Sep, 2021
There are two ways in which we can perform the searching operations in COBOL, first using the traditional method i.e. by applying the loop with the help of PERFORM statement, or by using the predefined verbs: SEARCH and SEARCH ALL. SEARCH and SEARCH ALL verbs can be used only in the INDEXED FILES because they use the indexed variable associated with the file.
SEARCH VERB performs a linear search in the record/array whereas SEARCH ALL VERB performs the binary search in the record/array.
Search
The Search verb in COBOL can be used to perform Linear searches, using table names as indexes.
Syntax:
SEARCH {TableName} [VARYING {IndexName}]
[AT END Code1]
{WHEN condition {Code2}
{NEXT SENTENCE }
[END-SEARCH]
Example:
WORKING-STORAGE SECTION.
77 N PIC 99.
77 SEARCHRNO PIC 99.
01 ARRAY.
02 ARR OCCURS 10 TIMES ASCENDING KEY IS RNO INDEXED BY I.
03 RNO PIC 99.
PROCEDURE DIVISION.
//AFTER ENTERING THE ELEMENTS IN ARRAY
//WE SEARCH THE ROLL NUMBER ENTERED
//BY USER IN VARIABLE SEARCHRNO.
SET I TO 1.
SEARCH ARR AT END DISPLAY "NOT FOUND"
WHEN RNO(I) = SEARCHRNO DISPLAY "FOUND ROLL NUMBER".
STOP RUN.
Output 1: To search the element that actually belongs to an array.
Output 2: To search the element that does not belong to an array.

Search All
The Search All verb in COBOL is used to perform a Binary search in COBOL using the indexes(name of the table).ntax
Syntax:
SEARCH ALL {TableName} [VARYING {IndexName}]
[AT END Code1]
{WHEN condition {Code2}
{NEXT SENTENCE }
[END-SEARCH]
Example:
WORKING-STORAGE SECTION.
77 SEARCHRNO PIC 99.
77 N PIC 99.
01 ARRAY.
02 ARR OCCURS 10 TIMES ASCENDING KEY IS RNO INDEXED BY I.
03 RNO PIC 99.
PROCEDURE DIVISION.
//AFTER ENTERING THE ELEMENTS IN ARRAY
//WE SEARCH THE ROLL NUMBER ENTERED
//BY USER IN VARIABLE SEARCHRNO.
SEARCH ALL ARR AT END DISPLAY "NOT FOUND ROLL NUMBER"
WHEN RNO(I) = SEARCHRNO DISPLAY "FOUND ROLL NUMBER".
STOP RUN.
Output: 1: To search the element that actually belongs to an array.
Output 2: To search the element that does not belong to an array.

Difference Between Search and Search All:
The below table has all major differences between Search and Search all:
SEARCH
| SEARCH ALL
|
---|
SEARCH verb is used to perform a linear search in COBOL. | SEARCH ALL verb is used to perform binary search in COBOL. |
For this the array is not required to be in the sorted form. | For this, the array must be in the sorted order form (either ascending or descending). |
It performs searching operations sequentially and is also known as sequential search. | It performs searching operations by comparing the element with the middle element of the array, divides the array into two halves, and continues the process until the element is found. |
It performs slow operations and is less efficient. | It performs a fast operation and is more efficient |
It can be used in single as well as multi-dimensional arrays. | It can only be used in single-dimensional arrays. |
Multiple conditions can be applied for searching using the WHEN. | Only one equality condition can be applied. |
The value of identifier-1 must be initialized prior to the SEARCH verb using the SET verb. | There is no need to use the SET verb prior to SEARCH ALL verb and thus the incrementing is done automatically. |
Similar Reads
Difference between Database and Search Engine A database and a search engine are both tools for finding information, but how they do this and what types of problems they solve differ greatly. Think of a database as an orderly virtual cabinet where you keep all your structured data â think of pieces like names, addresses, or sales records. It is
6 min read
Difference Between COBOL and FORTRAN COBOL stands for Common Business-Oriented Language, while FORTRAN stands for Formula Translation. What is COBOL? The COBOL computer programming language is a compiled English-like language designed for business. Businesses and governments have been using COBOL for years for business, finance, and ad
4 min read
Difference between Elasticsearch and Solr 1. Elasticsearch : It is an full text search and open-source engine. It is platform independent and can be run on any platform because it is built on java programming language. It allows user to access very large amount of data at very high speed. Features- It is scalable.It is open-source.It docume
2 min read
Difference between Search Engine and Subject Directory 1. Search Engine:A search engine, as the name suggests, is defined as an application designed to carry out web searches and enables users to locate information on WWW. Search engines are machine-driven and are used to find resources such as web pages, Usenet forums, videos, etc., assigned to individ
3 min read
Difference between grep and fgrep command This is the powerful grep and fgrep commands used to search text in a Linux-based system. Despite their similarity in use, which is for matching patterns in file strings, they still appear to be different in their own approach and capabilities. Grep supports regular expressions, including flexible a
4 min read
Difference between COMP and COMP3 Computer stores the data in more than one form. The Cobol language facilitates the programmer to specify the internal representation of the data according to the need. There are two internal forms available in the Cobol:DISPLAY: It is the default internal representation of the data. Any type of data
5 min read