Page 1 of 1

Duplicates in Binary Search in COBOL.

Posted: Mon Dec 18, 2017 6:03 pm
by Kailash
Hi,

While working with Binary Search I have understood that Duplicates in Binary Search in COBOL are not allowed. Could someone tell me the reason behind this? Why duplicates are not allowed?

Re: Duplicates in Binary Search in COBOL.

Posted: Mon Dec 18, 2017 6:16 pm
by Robert Sample
I think you misunderstand -- it is not that they are not allowed. It is very possible to generate a table with duplicate key values and use that table in a SEARCH ALL statement. What IBM tells you is that, if the keys are not ascending (or descending, depending upon the coding) -- and duplicate keys are definitely not ascending (nor descending) -- then you CANNOT be assured that the SEARCH ALL worked. It may return a wrong record, or it may fail to return a record even though the key is in the table.