Page 1 of 1

Using SEARCH without setting INDEX in COBOL.

Posted: Mon May 19, 2014 4:51 pm
by Ramnath
Hi,

What happens if we donot set the index before search, will this work?

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Mon May 19, 2014 5:26 pm
by William Collins
It depends on what you are trying to do. Have you looked at the documentation, it should be clear what will happen.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Mon May 19, 2014 7:43 pm
by zprogrammer
Also suggest to try it yourself if you have access to Mainframes.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Mon Jun 09, 2014 12:00 pm
by Ramnath
I came to know that for SEARCH to work in COBOL defining INDEX is mendatory but I could not test it, as I don't have the mainframe access yet.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Mon Jun 09, 2014 12:22 pm
by William Collins
You could try to install GNU COBOL (formerly OpenCOBOL) to try things out.

It is unclear what you mean exactly by "definiing INDEX is mandatory". SEARCH does no definitions at all.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Thu Jun 04, 2015 2:29 pm
by Ramnath
I wrote a post but i am not able to see it now...

If want the table to be in specific order then the INDEX needs be defined..right?

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Thu Jun 04, 2015 3:27 pm
by Anuj Dhawan
Ramnath wrote:I wrote a post but i am not able to see it now...
Did you click on the Submit button or just complied a reply? I doubt it was the later case! :)

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Thu Jun 04, 2015 3:50 pm
by William Collins
There is no necessary relationship between the order of data and whether an INDEX is defined.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Thu Jun 04, 2015 6:10 pm
by Robert Sample
If want the table to be in specific order then the INDEX needs be defined..right?
A COBOL table, unlike a VSAM KSDS, does not order the data in the table by the index. Data in a COBOL table is in the order your program loads it. Whether or not an INDEX is defined in the DATA DIVISION has nothing to do with the order of the data.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Thu Jun 04, 2015 6:15 pm
by Anuj Dhawan
Hello Ramnath

The thread seems to go nowhere - are you, by chance, talking about SEARCH ALL and the table declaration with INDEX and KEY ASCENDING/DESCENDING?

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Fri Jun 19, 2015 6:10 pm
by Ramnath
Yes, I have askedthe same??

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Fri Jun 19, 2015 10:44 pm
by Robert Sample
Yes, I have askedthe same??
No, you have not. COBOL has the SEARCH verb, which does a sequential search of a table, as well as SEARCH ALL, which does a binary search of a table. The binary SEARCH will fail if the data in the table is not sorted by the index whereas a sequential SEARCH can succeed no matter whether the data is sorted or not. You asked about SEARCH without specifying whether or not you are doing a binary search -- and the SEARCH works very differently compared to SEARCH ALL. If you read the Enterprise COBOL Language Reference manual, you will find that a sequential SEARCH uses an index but that index does not have to be defined on the table you are searching.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Wed Jun 24, 2015 12:41 pm
by Ramnath
I re-read my posts and understand that how less I was making sense in getting the answer. Thanks for your all help, it really heped me to understand about SEARCH and SEARCH ALL.

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Wed Jun 24, 2015 7:02 pm
by Anuj Dhawan
That's great and thanks for the feedback. Nothing to worry, as you progress in your career you'll learn to explain better yourself. :)

Re: Using SEARCH without setting INDEX in COBOL.

Posted: Mon Jul 06, 2015 1:58 pm
by Ramnath
Thanks Anuj!