Interviewer Asked this question, I defined table with 100 rows, but loaded with 50 columns only? When doing the "search all" the element is not found. But actually element is there ? what is the reason?
Ans : I told that the array may not be in sorted order, he is not satisfied with my answer then I told I didn't come across this situation in my experience.
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne
actually, your interviewer is full of crap. had there been only 49 items populated, I can see the problem. But you had 50. so the out-of-sort condition is an adequate answer. Had there been less than 50, then the population of the unused area of the table makes a difference in the outcome of the search all.
search all starts in the middle of your cobol internal table (array) - item 50. then depending on the outcome of the compare, the next place the search all looks is either 1/4 table back or 1/4 table forward.
the last 50 items (learn the correct terminology) if not initialized to high-values (or something greater than any potential item's field value) can/will produce the erroneous result.
your out-of-sort condition is part of the answer, but the key is the unused portion of the table must contain 'higher values' as the used portion. or simply use an ODO with sorted input.